mitchell_morgan58243_cand

advertisement
Morgan mitchell
4512 text encryption
Wildern school
AQA COMPUTER SCIENCE
4512/1 practical programming 58243
SCENARIO 4
MORGAN MITCHELL
Cad.no
Page number
File path
Morgan mitchell
4512 text encryption
Wildern school
Design and solution
I have been asked to write a program about encryption which is a cipher text. It is the conversion of
text into form. Encryption uses a key to hide the meaning of a message from people who are trying
to read it. We will be given a program which will propped the user to give the location of a text file,
the program will then encrypted using an offset. THz program will then give you the option to
decrypted the message
Plan text
Plan text
encrypt
Decrypt
Cipher text
Cipher text
User needs for task 1 /2:
1. Develop a main menu – encrypt & decrypt a message – exit program
2. Develop the part of the program that read the contents of a text file to be encrypted –
ask the user to enter name of the file containing the message to be encrypted – loads
the content of the special file.
3. To generate an eight character key the program should:
- Generate a random integer between 33 and 126
- Convert the random number into its equilivant ASCII character (for example the number
65 wold be converted into the character)
- Repeat steps 1 and 2 eight eight times to generate an eight character key
- Display the eight character key tot eh user
Page number
File path
Morgan mitchell
4512 text encryption
Wildern school
This is the task one flow chart showing how the display menu is tested.
Page number
File path
Morgan mitchell
4512 text encryption
Wildern school
Task 2
Start decrypt
Ask user for
ciphertext file
Read from
the file
Ask user
for
character
key
Work out the offset
Encrypted ciphertext into
plan text
Display the plan
text
Page number
File path
Develop the part of the program
that reads the contents of the files.
After you have press option one it
will read the sample.txt file ready
for encrypting.
Morgan mitchell
4512 text encryption
Wildern school
TASK 3
Start
Generate a random
number between 33 and
126
X8
Convert number into its
ASCII character
Display the 8
character key
to user
Page number
File path
a. Generate a random integer
between 33 and 136
b. Convert the random
number into its equivalent
ASCII character
Morgan mitchell
4512 text encryption
Wildern school
Task 4
START
Add numbers together.
Divide results by 8
Round down to a whole
number
Subtract 32
Offset factor
calculated
Page number
File path
Morgan mitchell
4512 text encryption
Wildern school
Task 5
Develop the part of the program that converts each character in the message into its ASCII code and
encrypts it using the following rules:
a. If the character is a space then do not encrypt the character
b. Otherwise:
i.
Convert the charac6er into its ASCII code (eg B = 66)
ii.
Add the ASCII code to the offset factor calculated in task 4. If the results is
greater than 126 then subtract 94 so that the result is a valid SCII code
iii.
Convert the result into its equivalent ASCII character.
An example is shown in figure 3.
start
i.
Convert the charac6er into its
ASCII code (eg B = 66)
ii.
Add the ASCII code to the offset
factor calculated in task 4. If the results
is greater than 126 then subtract 94 so
that the result is a valid SCII code
iii.
Convert the
result into its
equivalent ASCII
character
Page number
File path
Morgan mitchell
4512 text encryption
Wildern school
TASK 1
This screen shot shows my program working
Page number
File path
Morgan mitchell
4512 text encryption
Wildern school
TASK 2
Solution and development
This means that that while one choices going on something
else is happening as well.
Page number
File path
Morgan mitchell
4512 text encryption
Wildern school
TASK 3
Here is the cod I used for task 3.
Here is the output
Task 4
Page number
File path
Morgan mitchell
4512 text encryption
Wildern school
Output for task 4
Programming techniques
Techniques used:
Task 1 print
Task 1 if
Task 1 elif
Task 1 While
Page number
File path
Explanation :
The print function in python is a function that
outputs to your console window whatever you
say you want to print out
The if function in python is a function that lets
the user decide what they will have to do next.
if choice == 1: this is an example and I have
used this in my menu statement
The elif function in python is just the second if
statement which is used if there is more than
one decision to make
The while function in python is an option you
use when you have two things going on at once
Morgan mitchell
4512 text encryption
Wildern school
Task 1 else
Else function in python gives the user another
option in the program.
The import os.path statement means that they
use this to check if file path is present
This reads a file in python
Is a file is a certain name
Task 2 Import os.path
Task 2 Def readafile(filename):
Task 2 If
Os.path.isfile(filename,”r”)
Task 2 print
Print ‘no file’ if you have not got the text file in
the same folder.
Task 2 open
Task 2 read
Task 2 isfile
Task 2 else
Task 3 Import random
The Radom statement in python means that
they will use this to help generate random
numbers.
Task 3 chr
Task 3 for
Task 3 print
Task4 techniques table
- For
- Ord()
- Int()
- Print()
For means loop
Data Structure
Task 1
1
2
2
2
3
Data structure
Choice
Filename
File
Plaintext
Character key
4
5
Offset
cipher text
Page number
File path
explanation
Saves the user input
Saves the user input
Reads file name
Reads file
Saves the character key
created
Holds number from int
Hold s random encrypted
cipher text
Morgan mitchell
4512 text encryption
Wildern school
Testing and evaluation
Test no
Description
Test data
1
Press option 1
on the main
menu
If choice == 1:
Print (“you
have chosen
to encrypt”)
2
Press option 1
on the main
menu
If choice == 1:
Print (“you
have chosen
to decrypt ”)
3
Press option 1
on the main
menu
If choice == 1:
Print (“you
have chosen
exit”)
This is my testing table which shows all my testing.
Page number
File path
Expected
outcome
This should be
printed on
screen if you
select(“you
have chosen
to encrypt”)
This should be
printed on
screen if you
select(“you
have chosen
to
decrypted”)
This should be
printed on
screen if you
select(“you
have chosen
to exit”)
Actual
outcome
(“You have
chosen to
encrypt”) was
printed on
screen
Further action
?
No works
correctly
(“You have
chosen to
decrypt ”)
was printed
on screen
No works
correctly
(“You have
chosen to
exit”) was
printed on
screen
No works
correctly
Morgan mitchell
4512 text encryption
Wildern school
Task number
User need
Did I meet this
need
How was this
need met
1
1.
Develop
a main menu –
encrypt &
decrypt a
message – exit
program
a.
Generate
a random integer
between 33 and
136
b.
Convert
the random
number into its
equivalent ASCII
character
Develop the part
of the program
that reads the
contents of the
files. After you
have press
option one it will
read the
sample.txt file
ready for
encrypting.
Calculate offset
yes
User enter
choices and it
works.
yes
It calculates 8 bit
character
3
4
Page number
File path
yes
yes
How could this
need be better
met
Add colour and
fonts.
Cannot think of
any way to make
better.
Cannot think of
any way to make
better.
It calculates
offset
Download