In: Computer Science
Write a python function called HackCaesar with the following requirements:
def hack_caesar(cyphertext): ‘’’ cyphertext is a text encoded using Caesars encryption. The encryption key is unknown. The function returns the correct encryption key. Hint: Use the function we wrote was called caesar(c, key) and could encode a single character.
# YOUR CODE GOES HERE
#source code:
def caesar(c,key):
c=c.upper()
list=[x for x in range(0,26)]
letter=[chr(x) for x in range(65,91)]
cypher=""
for i in range(len(c)):
for j in range(len(letter)):
if(c[i]==letter[j]):
form=(j+key)%26
cypher+=letter[form]
return cypher
def hack_caesar(cyphertext):
for key in range(1,27):
letter=[chr(x) for x in
range(65,91)]
plain=""
for i in
range(len(cyphertext)):
for j in
range(len(letter)):
if(cyphertext[i]==letter[j]):
form=(j-key)%26
plain+=letter[form]
print("plain_String:{} And
Key={}".format(plain,key))
if __name__=="__main__":
#for excryption
text=input("Enter text to Encrypt:")
key=int(input("Enter key to Encrypt:"))
cypher=caesar(text,key)
print(cypher)
#for decryption
hack_caesar(cypher)
#output:
#based on output we simply said key 3 is meaning full data so key is 3
#if you have any doubt comment below.