Follow this blog by Email

Thursday, 5 September 2013

Solution to the python challenge Caesar crypt puzzle

Here is my solution to the Python Challenge Caesar crypt with shift. Very simple but teaches a python beginner a lot of its concepts about python and good hands-on exercise to solve oneself:

 import string  
 from string import maketrans  
 ip = string.lowercase  
 op = ip[2:]+ip[:2]  
 ciphersubtab = maketrans(ip, op)  
 ipstr = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj"  
 opstr = ipstr.translate(ciphersubtab)  
 print opstr 

1 comment:

Anonymous said...

#!/usr/local/bin/python

if __name__ == "__main__":

ct = """g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj"""
bits = ct.split(" ")
chs = list("abcdefghijklmnopqrstuvwxyz")
mes = ""
for bit in bits:
for bt in bit:
if bt in chs:
i = chs.index(bt)
if i == 24:
i = 0
mes = mes + chs[i]
elif i == 25:
i = 1
mes = mes + chs[i]
else:
mes = mes + chs[i+2]
else:
mes = mes + bt
mes = mes + " "
print mes