Olivia Dolan 4512 Text Encryption Wildern School AQA COMPUTER SCIENCE 4512/1 Practical Programing Scenario 4 Olivia Dolan 3457 58243 Design of Solution- 2 Solution Development- 4 Programming Techniques- 7 Testing Techniques- 8 Evaluation- 9 1 Olivia Dolan 4512 Text Encryption Wildern School Design of Solution I will create a program that includes a randomly generated key to encrypt the contents of a file. My program will allow the person using it to decrypt the cipher text of the encrypted file if the right key is correct. Encryption is a way to talk secretly without anyone knowing what you’re saying without the key. User Needs- Task 1 Develop a main menu Encrypt message Decrypt message Exit the program Task 2 Develop a program that reads the contents of a text file to be encrypted Ask the user to enter the name of the file containing the message to be encrypted Load the contents of the specified file Task 3 Develop the part of the program that generates an eight character key the program will use to encrypt the message To generate an eight character key the program should: a. Generate a random integer between 33 and 126 b. Convert the random number into its equivalent ASCII character ( for example the number 65 would be converted into the character ‘A’) c. Repeat steps a and b eight times to generate an eight character key d. Display the eight character key to the user Task 4 Convert each of the eight characters into its ASCII code Add numbers together Divide results by 8 Round down to whole number Subtract 32 Offset factor calculated Task 5 Develop the part of the program that converts each character in the message in to 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. ii. 2 Convert the character into its ASCII code (eg B=66) Add the ASCII code to the offset factor calculated in Task 4. If the result is greater than 126 then subtract 94 so that the result is a valid ASCII code Olivia Dolan 4512 Text Encryption Wildern School iii. Convert the result into its equivalent ASCII character. Flowchart for task 2 Flowchart for task 1 This is my flow chart showing the process for the start of my program. Flowchart for task 3 This is my flowchart for the 2nd part of my program that I will write. This is my flowchart for the 3rd part of my program. Flowchart for task 5 Start Convert the character into its ASCII code Flowchart for task 4 This is my flowchart for the 4th part of my program. 3 Add the ASCII code to the offset factor calculated in Task 4. If the result is greater than 126 then subtract 94 so that the result is a valid ASCII code Convert the result into its equivalent ASCII character. This is my flowchart for the 5th part of my program. Olivia Dolan 4512 Text Encryption Wildern School Solution Development This is my main program and my outcomes This is a screen shot of my python program for 1&2. 4 Olivia Dolan 4512 Text Encryption Wildern School Programing Techniques Technique used Explanation Print() The print function in python is a function that outputs to your console window whatever you say you want to print out. If The ‘If’ function is a function that processes the option you have chosen on the main menu. Choice The choice statement is the function that gives the program user several options to pick from. Int/input The Input function saves what the program user inputs and uses it. Else This else option is if you pick anything else like the ‘if’ statement. While While repeats a section of the program and allows 2 things to happen at the same time. Or The ‘or’ function allows there to be more than one of the options. Elif The elif function is a comination of the the ‘If’ and else statement and used in between the 2. Import The import function is where something that can be added onto a program something that is already in the program this means you don’t have to rewrite it. Exit The exit function allows you to leave that section of the code. 5 Justification of technique used Robustness & efficiency Olivia Dolan 4512 Text Encryption Wildern School False False part of the program Import os.path This function will use this to check if file path is present. Import random Will use this to help generate random numbers. def readafile(filename): Reads a file. If If file is a certain filename. os.path.isfile(filename): File=open(filename, Open and then read the chosen “r”) file. Task 4 For Specifying part of program and looping the program Ord() Int() Changing it into a whole number Print() 6 Olivia Dolan 4512 Text Encryption Wildern School Programing Techniques Task 1 and 2 run 7 Olivia Dolan 4512 Text Encryption Wildern School Testing Techniques 8 Test No Description Test data 1 Press option 1 on the main menu If choice ==1: print (“you have chosen option1”) 2 Press option 2 on the main menu If choice ==2: Print(“you have chosen option2”) 3 Press option 3 on the main menu If choice ==3: print (“you have chosen option3”) Expected outcome This should be printed on screen if you select ‘option 1’ (“You have chosen option1”) This should be printed on the screen if you select ‘option 2’ (“ you have chosen option2”) This should be printed on the screen if you select ‘option 3’ (“ you have chosen option3”) Actual outcome (“you have chosen option1”) was printed on screen Further action? No, works correctly (“you have No, works chosen correctly option2”) was printed on the screen (“you have No, works chosen correctly option3”) was printed on the screen Olivia Dolan 4512 Text Encryption Wildern School Evaluation Task number User needs Did I meet this need How was this need met? 1 Develop a main menu Encrypt message Decrypt message Exit the program yes I have an option for each of the user needs on the menu How could this need be better met? Could have been more colourful and more decretive 2 Develop a program that reads the contents of a text file to be encrypted Ask the user to enter the name of the file containing the message to be encrypted Load the contents of the specified file yes I have made a code that allows users to type in their name Could have included background music 3 Generate a random integer between 33 and 126 Convert the random number into its equivalent ASCII character ( for example the number 65 would be converted into the character ‘A’) Repeat steps a and b eight times to generate an eight character key Display the eight character key to the user yes I have included code that generates a random numbers for encryption N/A 4 Convert each of the eight characters into its ASCII code Add numbers together Divide results by 8 Round down to whole number Subtract 32 Offset factor calculated yes I have programed a part that generates a code for encryption N/A 9 5 Olivia Dolan 4512 Text Encryption Wildern School If the character is a space then do not encrypt the character Otherwise: Convert the character into its ASCII code (eg B=66) Add the ASCII code to the offset factor calculated in Task 4. If the result is greater than 126 then subtract 94 so that the result is a valid ASCII code Convert the result into its equivalent ASCII character. 10 yes These user needs make sure if there are any problems then they are solved by the program N/A