I got a question from my lecturer which is to implement an encoder/decoder of ROT-13. I don't really understand the question asked. The question sounds like this
In cryptography, a Caesar cipher is a simple encryption technique in which each letter is replaced by a letter some fixed number 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 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:
The question have give the 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' }
I have to encode/decode this message :
pnrfne pvcure? v zhpu cersre pnrfne fnynq!
This is my coding after I have research from several web site. I couldn't run my program since it has an error. Can anyone help me solve my problem?
def decodeThis(n):
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' }
for x in n:
v =x in key.keys()
if v == True:
py += (key[x])
else:
py += x
return py
Yes = decodeThis("pnrfne pvcure? v zhpu cersre pnrfne fnynq!")
print(Yes)