Just comment in my code text and explaining each function or block of code that all i need help on
- In cryptography, a Caesar cipher is a very simple encryption technique in which each letter in the plain text is replaced by a letter some fixed number of positions down the alphabet. For example, with a shift of 3, A would be replaced by D, B would become E, and so on. The method is named after Julius Caesar, who used it to communicate with his generals. ROT-13 (“rotate by 13 places”) is a widely used example of a Caesar cipher where the shift is 13. In Python, the key for ROT-13 may be represented by means of the following dictionary:
key = {‘a’:’n’, ‘b’:’o’, ‘c’:’p’, ‘d’:’q’, ‘e’:’r’, ‘f’:’s’, ‘g’:’t’, ‘h’:’u’,
‘i’:’v’, ‘j’:’w’, ‘k’:’x’, ‘l’:’y’, ‘m’:’z’, ‘n’:’a’, ‘o’:’b’, ‘p’:’c’,
‘q’:’d’, ‘r’:’e’, ‘s’:’f’, ‘t’:’g’, ‘u’:’h’, ‘v’:’i’, ‘w’:’j’, ‘x’:’k’,
‘y’:’l’, ‘z’:’m’, ‘A’:’N’, ‘B’:’O’, ‘C’:’P’, ‘D’:’Q’, ‘E’:’R’, ‘F’:’S’,
‘G’:’T’, ‘H’:’U’, ‘I’:’V’, ‘J’:’W’, ‘K’:’X’, ‘L’:’Y’, ‘M’:’Z’, ‘N’:’A’,
‘O’:’B’, ‘P’:’C’, ‘Q’:’D’, ‘R’:’E’, ‘S’:’F’, ‘T’:’G’, ‘U’:’H’, ‘V’:’I’,
‘W’:’J’, ‘X’:’K’, ‘Y’:’L’, ‘Z’:’M’}
Your task in this exercise is to implement an encoder/decoder of ROT-13. Write one function/method to encode messages and write another to decode them. Once you’re done, you will be able to read the following secret message:
Pnrfne pvcure? V zhpu cersre Pnrfne fnynq!
Python code
decrpted_str = ""
for i in str:
if i in key:
decrpted_str = decrpted_str + key[i]
else:
decrpted_str = decrpted_str + i
return decrpted_str
def main():
key = {
'a': 'n', 'b': 'o', 'c': 'p', 'd': 'q', 'e': 'r', 'f': 's', 'g': 't', 'h': 'u', 'i': 'v', 'j': 'w', 'k': 'x',
'l': 'y', 'm': 'z', 'n': 'a', 'o': 'b', 'p': 'c', 'q': 'd', 'r': 'e', 's': 'f', 't': 'g', 'u': 'h', 'v': 'i',
'w': 'j', 'x': 'k', 'y': 'l', 'z': 'm', 'A': 'N', 'B': 'O', 'C': 'P', 'D': 'Q', 'E': 'R', 'F': 'S', 'G': 'T',
'H': 'U', 'I': 'V', 'J': 'W', 'K': 'X', 'L': 'Y', 'M': 'Z', 'N': 'A', 'O': 'B', 'P': 'C', 'Q': 'D', 'R': 'E',
'S': 'F', 'T': 'G', 'U': 'H', 'V': 'I', 'W': 'J', 'X': 'K', 'Y': 'L', 'Z': 'M'
}
str = "Pnrfne pvcure? V zhpu cersre Pnrfne fnynq!"
decrypted_str = decrypt(str, key)
print("Encrypted message: " + str)
print("Decrypted message: " + decrypted_str)
if __name__ == "__main__":
main()
Step by stepSolved in 4 steps with 3 images
- Cryptography is the study of protecting information. A cipher is a pair of algorithms ―the first algorithm encrypts a message and the second algorithm decrypts the message. In most cases, a unique key is also required to encode or decode plaintext. The Caesar cipher is one of the simplest and most widely known ciphers. It is named after Julius Caesar who allegedly used it to protect important military directives. Every letter in the plaintext is replaced by a letter N positions down the alphabet. For example, if N = 3, then a => d and b => e. While the idea is remarkably simple, it appeared to work in Ancient Rome. Most people there couldn't read, and those who could simply assumed it was a foreign language. Write a program that implements the Caesar cipher. You program will get from standard input the key N, followed by a line of plaintext. . . The key N should be any integer between 0 and 26 inclusive. If this isn't the case, print an error message and quit. Any numbers or…arrow_forwardHow do I solve the picture below?arrow_forwardPython question Simple python programarrow_forward
- Encode the number using the given public key. Encode the number M = 14 using the public key n = 77 and e = 13. Assume you are encoding the number using the RSA cryptosystem. Note: You can use the Modular Exponentiation calculator to help with the calculation. a 46 (mod 77), encoded number = 46 47 (mod 77), encoded number = 47 48 (mod 77), encoded number = 48 d. 49 (mod 77), encoded number = 49arrow_forwardBoth parts pleasearrow_forwardThe art of breaking ciphers is known as: a. cryptology b. cryptography c. cryptanalysis d. cryptingarrow_forward
- Use symmetric ciphers to encrypt message "“promise" and decrypt message "FOG". The representation of characters in modulo 26 is described as follows: Plaintext - a bcdefg|hijk1 mnopar stuvwx y z Ciphertext A BCD|EFG|HIJKL|M|NO|P|Q|R s T|U|VwxY|Z Value 00 01 02|03 04 05 06|07|08|09|10|11 12|13|14|15 16|17 18|19 20 21 22 23 24 25 The mathematical equations for encryption and decryption can be described as follows: Encryption Ea:i→i+kmod 26 Decryption Da : i→i-k mod 26 i represents the messages (plaintext or cipher), k represents a symmetric key. In this case k=20arrow_forwardTry it yourself to make sure you've got the concept. 1. Use a Caesar cipher with key 6 (AàG) to encrypt the following message: ANCIENT OF DAYSarrow_forward4. Decipher the following ciphertext, which was enciphered with the Caesar cipher: TEBKFKQEBZLROPBLCERJXKBSBKQP, using the statistical cryptoanalysis and the 1-gram model of English (see the table below). Write a program to calculate the correlation (i) for 0 ≤ i ≤ 25 to help identify the key and the plaintext. a b с d e f 61) 0.080 0.015 0.030 0.040 0.130 0.020 0.015 h i k 0.060 j 0.005 1 0.065 0.005 0.035 m 0.030 n 0 9 Р 0.020 r 0.070 S 0.080 0.002 0.065 0.060 t u V X y N 0.090 0.030 0.010 0.015 0.005 0.020 0.002arrow_forward
- Help me fast so that I will give Upvote.arrow_forwardA block cipher with a random key is most like a Choose one: Private random function Public random permutation Private random permutation Public random functionarrow_forwardNote: The notation from this problem is from Understanding Cryptography by Paar and Pelzi. Consider the LFSR represented by the polynomial x¹ + x³ +x+1 What are the tap bits of the LFSR? Please enter your answer as unspaced binary digits (e.g. 010101 to represent p = 0, P4 = 1, P3 = 0, P2 = 1, P₁ = 0, Po = 1).arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education