Instructions
Requirements and Specifications
- Create a Python code file named M4Lab_Encryption_FirstLast.py
- Add a title comment block to the top of the new Python file using the following form
- Create a program that uses a dictionary to assign "codes" to each character in the alphabet. For example
- Using the example above, the letter 'A' would be converted to a parentheses ')' and the letter 'a' would be converted to a zero (0) and so on.
- The program is to ask the user to enter a sentence, then pass the sentence to a function that would create an encrypted version of the sentence.
- The function that evalutes the sentence is to use a loop to iterate over the sentence then use the dictionary and create the encrypted version of the sentence. This function is a value returning function, meaning it is to return the encrypted version of the sentence.
- The program is to then display the encrypted version of the sentence
(replace "FirstLast" with your own name)
# A brief description of the project
# Date
# CSC-121-Encryption
# Your Name
codes = {'A' : ')' , 'a' : '0' , 'B' : '(' , 'b' : '9' ,.......}
Source Code
# A brief description of the project
# Date
# CSC-121-Encryption
# Your Name
codes = {'A': ')', 'B': '(', 'C': '*', 'D': '&', 'E': '^', 'F': '%', 'G': '$', 'H': '#', 'I': '@', 'J': '!',
'K': '}', 'L': '{', 'M': 'P', 'N': 'O', 'O': 'I', 'P': 'U', 'Q': 'Y', 'R': 'T', 'S': 'R', 'T': 'E',
'U': 'W', 'V': 'Q', 'W': '"', 'X': ':', 'Y': 'L', 'Z': 'K',
'a': '0', 'b': '9', 'c': '8', 'd': '7', 'e': '6', 'f': '5', 'g': '4', 'h': '3', 'i': '2', 'j': '1',
'k': ']', 'l': '[', 'm': 'p', 'n': 'o', 'o': 'i', 'p': 'u', 'q': 'y', 'r': 't', 's': 'r', 't': 'e',
'u': 'w', 'v': 'q', 'w': '\'', 'x': ';', 'y': 'l', 'z': 'k'}
def encode(text):
result = ""
for c in text:
if c in codes:
result += codes[c]
else:
result += c
return result
plain_text = input('Please, enter the sentence: ')
encrypted = encode(plain_text)
print('Encrypted sentence:', encrypted)