Answered step by step
Verified Expert Solution
Question
1 Approved Answer
this code has been given already to us import random # Given a dictionary d and value v, # find and return the key associated
this code has been given already to us
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(cypher_seed):
random.seed(cypher_seed) # seed the random number generator with the given seed
cypher = {} # create empty dictionary
# add code here
return cypher # return the completed cypher dictionary
def encrypt(s, cypher_seed):
cypher = create_cypher_dictionary(cypher_seed) # get the cypher dictionary
# add your code here
def decrypt(s, cypher_seed):
cypher = create_cypher_dictionary(cypher_seed) # get the cypher dictionary
# add your code here
def encrypt_multiple_times(s, cypher_seed, 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_seed):
cypher = create_cypher_dictionary(cypher_seed) # get the cypher dictionary
# add your code here
s = input("Enter text to encrypt: ")
# add your code here
print("Encrypted string:", encrypt(s, 1337))
print("Decrypted string:", decrypt(encrypt(s, 1337), 1337))
salted_s = encrypt_multiple_times(s, 1337, 2)
print("Encrypted string:", salted_s)
print("Decrypted string:", decrypt_multiple_times(salted_s, 1337))
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