python - I need to remove whitespace in this program in order for encryption/decryption to work -
for example, code outputs:
encrypted message: j 6 5 + ~ 5 + ~ = ~ * 9 + *
decrypted message: t ~ h ~ ~ s ~ ~ ~ s ~ ~ ~ ~ t ~ e ~ s ~ t
...due fact whitespace considered '~' decryption method.
from collections import defaultdict e1 = {} e2 = {} e3 = {} d3 = {} d2 = {} d1 = {} print "would encrypt 'e' or decrypt 'd' message?" count = 1 while count >= 1: eod = raw_input("> ") if eod in ("encrypt", "encrypt", "e", "e"): print "enter message here:" emessage_in = raw_input("> ") elength = len(emessage_in) elistm = list(emessage_in) x in range(0, elength): e1[x] = elistm[x] e2[x] = ord(e1[x]) e3[x] = 158 - e2[x] emessage_out = chr(e3[x]) print emessage_out, count = 0 elif eod in ("decrypt", "dencrypt", "d", "d"): print "enter message here:" dmessage_in = raw_input("> ") dlength = len(dmessage_in) dlistm = list(dmessage_in) y in range(0, dlength): d3[y] = dlistm[y] d2[y] = ord(d3[y]) d1[y] = 158 - d2[y] dmessage_out = chr(d1[y]) print dmessage_out, count = 0 else: print "please type 'e' or 'd':" count += 1
would believe took me ten minutes of troubleshooting realize calling print in loop? :) added/modified lines commented.
if eod in ("encrypt", "encrypt", "e", "e"): print "enter message here:" emessage_in = raw_input("> ") elength = len(emessage_in) elistm = list(emessage_in) emessage_out = '' # initialize empty string x in range(0, elength): e1[x] = elistm[x] e2[x] = ord(e1[x]) e3[x] = 158 - e2[x] emessage_out += chr(e3[x]) # concatenate each character onto string count = 0 print emessage_out # move out of loop elif eod in ("decrypt", "dencrypt", "d", "d"): print "enter message here:" dmessage_in = raw_input("> ") dlength = len(dmessage_in) dlistm = list(dmessage_in) dmessage_out = '' # initialize empty string y in range(0, dlength): d3[y] = dlistm[y] d2[y] = ord(d3[y]) d1[y] = 158 - d2[y] dmessage_out += chr(d1[y]) # concatenate each character onto string count = 0 print dmessage_out # move out of loop
Comments
Post a Comment