well, i started messing around with dictionaries, yet, most of the pages i found about them always talk about getting only one word out of it and turning it vice versa, i've been playing with that code for a few hours:
trying to get an output from the reversed dictionary is just not working, keeps giving me KeyErrors, even i enter only 1 word that is IN the dictionary...
maybe it's because didn't use conventional letters, but still, how do i decrypt?
plz help
#Note: the Encryption works perfectly, the Decryption Doesn't.
I'm using python 2.5 (python 3 is weird O|o)
Code:
#dics
Encryption={',':'hy{;',' ':'h4x0r2','':'zomg','?':'bko','a':'ika','b':'d0v','c':'ino', 'd':'maw', 'e':'aon', 'f':'que', 'g':'kip', 'h':'an[', 'i':'bf}', 'j':'ana&', 'k':'%d#', 'l':'d^f', 'm':'[d:w]', 'n':'ko[p', 'o':'{par:', 'p':'nt|;', 'q':'bz&$', 'r':'le{}', 's':'ak+', 't':'joq%', 'u':'f%(', 'v':'@!', 'w':'hg^*', 'x':'yu#', 'y':'fy%s', 'z':'mos@'}
Decryption=dict(zip(Encryption.values(), Encryption.keys()))
#functions#
# f1 enc #
def encrypt(x):
try:
#open spot for output#
lol=""
##
for letter in x:
lol += Encryption[letter]
print lol
except KeyError:
print 'These keys are not in the dictionary!'
# f2 dec #
def decrypt(y):
try:
lol=""
for mail in y:
lol += Decryption[mail]
print lol
except KeyError:
print 'These keys are not in the dictionary!'
#men#
def menu():
while 1:
t=raw_input('Do you want to Encrypt or to Decrypt?[e,d] ').lower()
#case 1#
#Enc#
while t=='e':
try:
print 'Enter Text below'
x=raw_input('').lower()
if len(x)<10:
print 'Print only long sentences'
else:
encrypt(x)
except KeyError:
print 'These keys are not in the dictionary!'
#case 2#
#Dec#
while t=='d':
try:
print 'Enter Text below'
y=raw_input('').lower()
decrypt(y)
except KeyError:
print 'These keys are not in the dictionary!'
#b2men#
menu()
maybe it's because didn't use conventional letters, but still, how do i decrypt?
plz help
#Note: the Encryption works perfectly, the Decryption Doesn't.
I'm using python 2.5 (python 3 is weird O|o)
Comment