Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help in comment in your program texts, explaining each function or block of code . That all I need I already have code

I need help in comment in your program texts, explaining each function or block of code. That all I need I already have code running I need help for those thing

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 youre done, you will be able to read the following secret message:

Pnrfne pvcure? V zhpu cersre Pnrfne fnynq!

Python Code:

def decrypt(str, key): 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 Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions