import sys import os word=[] word1=[] alphabet= {1:'a', 2:'b' , 3:'c' , 4:'d' , 5:'e' , 6:'f' , 7:'g' , 8:'h' , 9:'i' , 10:'j' , 11:'k' , 12:'l' , 13:'m' , 14:'n' , 15:'o' , 16:'p' , 17:'q' , 18:'r' , 19:'s' , 20:'t' , 21:'u' , 22:'v' , 23:'w' , 24:'x' , 25:'y' , 26:'z'} numbers= {'a':1 , 'b':2 , 'c':3 , 'd':4 , 'e':5 , 'f':6 , 'g':7 , 'h':8 , 'i':9 , 'j':10 , 'k':11 , 'l':12 , 'm':13 , 'n':14 , 'o':15 , 'p':16 , 'q':17 , 'r':18 , 's':19 , 't':20 , 'u':21 , 'v':22 , 'w':23 , 'x':24 , 'y':25 , 'z':26} a="" def sclear(): sys.stdout.write(os.popen('clear').read()) def encrypt(alphabet,numbers): string1=raw_input('Enter your string: ') length=len(string1) for num in range(length): newstring=3+numbers[string1[num]] word.append(alphabet[newstring]) encrypted="".join(word) print "The encrypted text is: %s" % encrypted def decrypt(alphabet,numbers): string1=raw_input('Enter your string: ') key=raw_input('Enter the key: ') length=len(string1) for num in range(length): b="%s-%s" % (numbers[string1[num]],key) a=numbers[string1[num]] print a print alphabet[a] print b word1.append(alphabet[newstring]) decrypted="".join(word1) print "The decrypted text is: %s" % decrypted def arg1(): action=raw_input('Do you want to encrypt or decrypt(e,d):') if action == "e": encrypt(alphabet,numbers) elif action == "d": decrypt(alphabet,numbers) elif action != "e"|"d": arg1() sclear() arg1() print "Done";