Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please use the following code and include comments explaing what/why its being done import random # Given a dictionary d and value v, # find
please use the following code and include comments explaing what/why its being done
import random
# Given a dictionary d and value v,
# find and return the key associated with that value.
# (From the slides.)
def reverse_lookup(d, v):
for key in d:
if d[key] == v:
return key
return None
LETTERS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()`~-=_+[]{}|;\':",./? '
def create_cypher_dictionary():
random.seed(1337) # important - please keep this line here.
cypher = {} # create empty dictionary
# add code here
return cypher # return the completed cypher dictionary
def encrypt(s):
cypher = create_cypher_dictionary() # get the cypher dictionary
# add your code here
def decrypt(s):
cypher = create_cypher_dictionary() # get the cypher dictionary
# add your code here
def encrypt_multiple_times(s, n):
pass # delete this line and add your code here
# Source: https://en.wikipedia.org/wiki/Most_common_words_in_English
COMMON_WORDS = [" the ", " be ", " to ", " of ", " and ", " a ", " in ", " that ", " have ", " I ", " it ", " for ", " not ", " on ", " with ", " he ", " as ", " you ", " do ", " at "]
def decrypt_multiple_times(s):
cypher = create_cypher_dictionary() # get the cypher dictionary
# add your code here
s = input("Enter text to encrypt: ")
# add your code here
print("Encrypted string:", encrypt(s))
print("Decrypted string:", decrypt(encrypt(s)))
salted_s = encrypt_multiple_times(s, 2)
print("Encrypted x2 string:", salted_s)
print("Decrypted x2 string:", decrypt_multiple_times(salted_s))
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started