Question

In: Computer Science

Write a python function called HackCaesar with the following requirements: def hack_caesar(cyphertext): ‘’’ cyphertext is a...

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


def is_odd(n):
return n%2 == 1


def caesar(c, key):
""" Encrypts a lower case character c using key
Example: if c = "a" and key=3 then the function should return d
"""
return chr((ord(c)-97+key) % 26 + 97)


n = input("enter a number:")
n = int(n)
if n > 10:
print("hello")
print("your number if more than 10")
else:
print("else block")



for i in range(5):
print(i)
print(i*i)
print(is_odd(i))
print(caesar("a", 3))

Solutions

Expert Solution

#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.


Related Solutions

USING PYTHON 3.7 AND USING def functions. Write a function called GPA that calculates your grade...
USING PYTHON 3.7 AND USING def functions. Write a function called GPA that calculates your grade point average (GPA) on a scale of 0 to 4 where A = 4, B = 3, C = 2, D = 1, and F = 0. Your function should take as input two lists. One list contains the grades received in each course, and the second list contains the corresponding credit hours for each course. The output should be the calculated GPA. To...
Using Python, write a program that meets the following requirements: Make a list called sandwich_orders and...
Using Python, write a program that meets the following requirements: Make a list called sandwich_orders and fill it with the names of various sandwiches. Make an empty list called finished_sandwiches. Loop through the list of sandwich orders and spring a message for each order such as "I am working on your tuna sandwich" As each sandwich is made, move it to the list of finished sandwiches. After all the sandwiches have been made, print a message listing each sandwich that...
2. working with databases and files in python a) Write a function with prototype “def profound():”...
2. working with databases and files in python a) Write a function with prototype “def profound():” that will prompt the user to type something profound. It will then record the date and time using the “datetime” module and then append the date, time and profound line to a file called “profound.txt”. Do only one line per function call. Use a single write and f-string such that the file contents look like: 2020-10-27 11:20:22 -- Has eighteen letters does 2020-10-27 11:20:36...
Write a Python function with prototype “def anagramdictionary(wordlist):” that will return an “anagram dictionary” of the...
Write a Python function with prototype “def anagramdictionary(wordlist):” that will return an “anagram dictionary” of the given wordlist  An anagram dictionary has each word with the letters sorted alphabetically creating a “key”.
#Python 5. Write function called evaluate() that evaluates the following Python expressions or assignments as specified:...
#Python 5. Write function called evaluate() that evaluates the following Python expressions or assignments as specified: Request input from the user for three variables (floating-point or integer) x, y, z, and myAverage. If the average of the first three numbers equals the fourth number, print 'Your average is correct.'. If not print 'Your average is not correct'. and print the correct average. Print the largest value among x, y, and z. Print the minimum value of x, y, y. >>>...
In python please write the following code the problem. Write a function called play_round that simulates...
In python please write the following code the problem. Write a function called play_round that simulates two people drawing cards and comparing their values. High card wins. In the case of a tie, draw more cards. Repeat until someone wins the round. The function has two parameters: the name of player 1 and the name of player 2. It returns a string with format '<winning player name> wins!'. For instance, if the winning player is named Rocket, return 'Rocket wins!'.
Write a python function to fulfill the requirements. The function accepts a string, a current state,...
Write a python function to fulfill the requirements. The function accepts a string, a current state, edges’ information, and an accepting state. The output of the function is a boolean value verifying if the string can pass the finite state machine or not.             ### Finite State Machine Simulator in Python ### Provide s1 and s2 that are both accepted, but s1 != s2. s1 = "bdf" s2 = "bdgbdf" edges = {(1,'a') : 2,                (1,'b') : 3,       ...
Write a python program using the following requirements: Create a class called Sentence which has a...
Write a python program using the following requirements: Create a class called Sentence which has a constructor that takes a sentence string as input. The default value for the constructor should be an empty string The sentence must be a private attribute in the class contains the following class methods: get_all_words — Returns all the words in the sentence as a list get_word — Returns only the word at a particular index in the sentence Arguments: index set_word — Changes...
Using Python, write a program named hw3a.py that meets the following requirements: Create a dictionary called...
Using Python, write a program named hw3a.py that meets the following requirements: Create a dictionary called glossary. Have the glossary include a list of five (5) programing words you have learned in chapters 4-6. Use these words as keys to your dictionary. Find the definition of these words and use them as the values to the keys. Using a loop, print each word and its meaning as neatly formatted output. Create three dictionaries called person. Have each of the person...
This is python: #Write a function called count_positive_evens. This function #should take as input a list...
This is python: #Write a function called count_positive_evens. This function #should take as input a list of integers, and return as #output a single integer. The number the function returns #should be the count of numbers from the list that were both #positive and even. # #For example: # # count_positive_evens([5, 7, 9, 8, -1, -2, -3]) -> 1 # count_positive_evens([2, 4, 6, 8, 10, 12, 15]) -> 6 # count_positive_evens([-2, -4, -6, -8, -10, 1]) -> 0 # #0...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT