Evaluation - Wildern School

advertisement
AQA computer science
4512/1 practical programing
Scenario 4
Brandon Williams
58243
3726
brandon williams
Brandon Williams
Contents page
1
4512 Text Encryption
Wildern School
Brandon Williams
Design of solution
For this exam I have to create a
program using python that will have
a menu that will allow the user to
encrypt, decrypt or exit the program
2
4512 Text Encryption
Wildern School
Brandon Williams
4512 Text Encryption
Wildern School
Solution Development
Task 1: Main Menu
Code:
#this is a main menu for the user
import os.path
print ("___________________________________________________________")
print ("|
Main Menu
|")
print ("|
1 Encrypt Message
|")
print ("|
2 Decrypt Message
|")
print ("|
3 Exit The Program
|")
print ("___________________________________________________________")
print("\n")
#this is a command for the user
print("please enter your choice")
User Needs
Task 2: Read File
Code:
print("\n”)
#this is a command for the user
print("please enter your choice")
choice = int(input())
#these are the choices the user can make
if choice == 1:
print("what is the name of the file you would like to encrypt?")
if os.path.isfile("sample.txt"):
file = input()
file = open ("sample.txt", "r")
plaintext = file.read()
print (plaintext)
#this part will open the "sample.txt" file and will display what is on this file
3
Brandon Williams
4512 Text Encryption
Task 3: Key
Code:
key = ''
for i in range(8):
random_number = randint(33, 126)
key += chr(random_number)
print("you will need this key to decrypt your file")
print("your key is:" + key)
char_key = key
User Needs
Task 4: offset
Code:
offset = 0
for x in char_key:
offset = offset + ord(x)
offset = offset/8
offset = int(offset)
offset = offset - 32
print("your offset is:",offset)
User Needs
4
Wildern School
Brandon Williams
4512 Text Encryption
Task 5: plaintext - ciphertext
Code:
ciphertext = ""
for letter in plaintext:
if ord(letter) ==32:
ciphertext=ciphertext+letter
elif ord(letter)+offset <= 126:
print()
else:
#ciphertext = ciphertext+chr(ord(letter)+offset-94)
#print (ciphertext)
User Needs
Task 6: write ciphertext
Code:
print("enter the name of the new text file")
filename = input()
file = open(filename, "w")
file.write(ciphertext)
file.close()
User Needs:
5
Wildern School
Brandon Williams
4512 Text Encryption
Task 7: read ciphertext
Code:
Print("enter the filename you would like to read ")
cipherfile = input()
file = open("cipherfile","r")
cipherfile = file.read
file.close
User Needs:
6
Wildern School
Brandon Williams
4512 Text Encryption
Wildern School
Programming techniques
Technique
Print
If
Else
Task
1
7
Where used
I used this on line 15
of python program
print("please enter
your choice").
Why used
I used the function
print so that this
would be displayed
to the user when
they started the
program up.
I used this on line 18 I used this function
of my python
so that it would give
program if choice == the user an option on
1:
what they wanted to
do. It also makes the
program do
something if option 1
is chosen.
I used this function
The else function
on line 40 of my
allows my program
python program else: to print something
telling the user to
choose either option
1, 2, 3 if they didn’t
choose one of them
already.
Data structure
name
Choice
Data structure
type
Variable
Data type
purpose
Integer
Use to store the
choice that the
user entered at
the main menu
Brandon Williams
4512 Text Encryption
Wildern School
Testing and evaluation
Test No.
Test data
entered
Valid
/extreme/
invalid/
erroneous
What do you
expect to
happen
What actually
happened
Further
action
required
Task 1
1.1
1
Extreme
2
Extreme
1.3
3
Extreme
1.4
4
invalid
“Encrypt”
displayed on
screen
“Decrypt”
displayed on
screen
“you have
chosen to exit
the program”
displayed on
screen
“you must
choose 1, 2,
3” displays on
the screen
None
1.2
“Encrypt” will
display on
screen
“Decrypt” will
display on
screen
“Exit” will
display on the
screen
Nothing will
display on the
screen
None
None
none
1.5
Task number
User need
Did I meet this
need?
How was this
need met?
1
The user needed
to see a main
menu to encrypt,
decrypt a
message or exit
the program.
The programme
should ask the
user to enter a
file that they
would like to
encrypt.
The program
should generate
and print a key
for the user.
yes
I used the print
function so when
the user ran the
program it would
appear on
screen.
Again I used the
print function to
appear the
message on
screen.
The programm
now had to
yes
2
3
4
8
yes
yes
I used print again
and assigned key
with an equation
to be done when
the user uses the
program.
I used the print
function to
How could this
need be better
met?
The exit option
should
completely exit
the program.
There is no
improvements I
could make on
this task.
There is no
improvements I
could make on
this task.
There is no
improvements I
Brandon Williams
4512 Text Encryption
create on offset
and show that to
the user.
5
6
7
8
9
9
Wildern School
display the offset
on screen.
could have made
to this.
Download