代做Decryption and encryption is a very useful activity to hide messages or data代写Web开发
- 首页 >> Python编程Decryption and encryption is a very useful activity to hide messages or data. Encryption is utilized to store passwords, store user information and in many other means when the sender does not want the message to be easily readable to anyone other than the intended reader.
Your Assignment
You must write a program that can both decrypt and encrypt a single word that is entered by the user. The initial choice of encryption and decryption is left up to the user. Additionally, the user will enter a value to be utilized when determining how to translate the character.
Alphabetic Positions
Positions start at zero. If the letter is ‘a’ then its position in the alphabet is 0 and if the letter is ‘c’ the position is 2 and so on through ‘z’.
Algorithm
Acquire the method to perform. (encryption or decryption).
Check whether the method specified is valid.
Acquire the translation map
If keyword default is entered, utilize the default map.
default map: “zyxwvutsrqponmlkjihgfedcba”
Validate the size of the map (26 characters)
Acquire the word to encrypt or decrypt, validate depending on method
Validate whether the word can be encrypted
All characters in word must be lowercase letters
Validate whether the word can be decrypted
All characters in word exist in map
Perform. encryption or decryption
Encryption: Convert all characters in word to a character in the map
Given a character in the word, calculate its position in the alphabet
Replace the character in the word with the character in map at that position.
Decryption: Convert all characters in the word by utilizing the discovered map index
Given a character in the word, determine its index in the map string
This is the position of the character in the alphabet!
Add the position to the first character in range of valid characters for a word What is the range of valid characters? Check the validation step. What is the first character in that range?
Hints/Tips
Implement the algorithm in the order that is specified.
If you get to an error point, immediately exit the program (within main just return 0;)
Use only a single map variable, assigning a proper value into it based on user input.
Encryption Example
If your map is "0987654321abcdefghijklmnop" and your word is "abc", then you need to convert the 'a' to '0', 'b' to '9', and 'c' to '8'; because 'a' is the first letter in the alphabet, so it gets converted to the first character in the map.
Output Requirements
A bad operation choice should result in an error line.
Output results should utilize one of the three following key phrases:
Error
Decrypted word
Encrypted word
Potential Errors
invalid method choice.
invalid translation map size.
encryption cannot be performed.
decryption cannot be performed.
Submission
You will submit on CodeCheck. Once you have submitted and passed all the test cases, take a screenshot showing all the test cases passed and submit the screenshot to canvas.
Example Runs (User input has been bolded and underlined for emphasis)
Example 1
What is the method (encryption or decryption)? encryption
What is the translation map (type 'default' to use default): default
What is the single word to translate: hello
Encrypted word: svool
Example 2
What is the method (encryption or decryption)? decryption
What is the translation map (type 'default' to use default): default
What is the single word to translate: zyx
Decrypted word: abc
Example 3
What is the method (encryption or decryption)? google
Error: invalid method choice.
Example 4
What is the method (encryption or decryption)? encrptn
Error: invalid method choice.
Example 5
What is the method (encryption or decryption)? encryption
What is the translation map (type 'default' to use default): default
What is the single word to translate: 123cat
Error: encryption cannot be performed.
Example 6
What is the method (encryption or decryption)? encryption
What is the translation map (type 'default' to use default): default
What is the single word to translate: cat
Encrypted word: xzg
Example 7
What is the method (encryption or decryption)? encryption
What is the translation map (type 'default' to use default): xyzabcdefghi
Error: invalid translation map size.
Example 8
What is the method (encryption or decryption)? encryption
What is the translation map (type 'default' to use default): xyzabcdefghijklmnopqrstuvw
What is the single word to translate: cat
Encrypted word: zxq
Example 9
What is the method (encryption or decryption)? encryption
What is the translation map (type 'default' to use default): 123defghijklmnopqrstuvwxyz
What is the single word to translate: cat
Encrypted word: 31t
Example 10
What is the method (encryption or decryption)? encryption
What is the translation map (type 'default' to use default): 123defghijklmnopqrstuvwxyz
What is the single word to translate: 4cat
Error: encryption cannot be performed.
Example 11
What is the method (encryption or decryption)? decryption
What is the translation map (type 'default' to use default): default
What is the single word to translate: xzg
Decrypted word: cat
Example 12
What is the method (encryption or decryption)? decryption
What is the translation map (type 'default' to use default): default
What is the single word to translate: 31t
Error: decryption cannot be performed.
Example 13
What is the method (encryption or decryption)? decryption
What is the translation map (type 'default' to use default): 123defgh
Error: invalid translation map size.