So I created a custom encryption algorithm that I call Grid. Here's the code:
print('')
print("Welcome to the Project Grid encryption tool.")
print("Note that this encryption method is not completely secure.")
print("Anyone with this program can learn the encryption.")
print("Encrypted documents may be confused if numbers are used.")
print("Happy Encrypting!")
print("")
e = raw_input()
o = e.lower()
list(o)
o = [s.replace('a','11') for s in o] #all of this is just to do the encryption
o = [s.replace('b','12') for s in o]
o = [s.replace('c','13') for s in o]
o = [s.replace('d','14') for s in o]
o = [s.replace('e','15') for s in o]
o = [s.replace('f','21') for s in o]
o = [s.replace('g','22') for s in o]
o = [s.replace('h','23') for s in o]
o = [s.replace('i','24') for s in o]
o = [s.replace('j','25') for s in o]
o = [s.replace('k','31') for s in o]
o = [s.replace('l','32') for s in o]
o = [s.replace('m','33') for s in o]
o = [s.replace('n','34') for s in o]
o = [s.replace('o','35') for s in o]
o = [s.replace('p','41') for s in o]
o = [s.replace('q','42') for s in o]
o = [s.replace('r','43') for s in o]
o = [s.replace('s','44') for s in o]
o = [s.replace('t','45') for s in o]
o = [s.replace('u','51') for s in o]
o = [s.replace('v','52') for s in o]
o = [s.replace('w','53') for s in o]
o = [s.replace('x','54') for s in o]
o = [s.replace('y','55') for s in o]
o = [s.replace('z','61') for s in o]
o = [s.replace('.', '') for s in o] #This just removes any punctuation, so as to not mess the cypher up.
o = [s.replace('?', '') for s in o]
o = [s.replace('!', '') for s in o]
o = [s.replace("'", '') for s in o]
o = [s.replace('"', '') for s in o]
o = [s.replace(',', '') for s in o]
o = [s.replace(' ', '.') for s in o]
f = ''.join(o)
print f
with open('encrypted.txt', 'a') as the_file: #writes the encryption to a file
the_file.write(f + ' <br> ')
Here's my problem: I'm working on a decryption algorithm, but I'm having a quite a bit of trouble with converting the number lines that it returns back into the letter - containing codes and therefore can't make it actually decrypt. Here's the decryption code.
print('')
print("Welcome to the Project Grid decryption tool.")
print("Happy Decrypting!")
print("")
r = raw_input()
r = [s.replace('.', '62') for s in r]
x = [int(i) for i in r]
n = 2
o = [x[i:i+n] for i in range(0, len(x), n)]
print o
o = [s.replace('11','a') for s in o]
o = [s.replace('12','b') for s in o]
o = [s.replace('13','c') for s in o]
o = [s.replace('14','d') for s in o]
o = [s.replace('15','e') for s in o]
o = [s.replace('21','f') for s in o]
o = [s.replace('22','g') for s in o]
o = [s.replace('23','h') for s in o]
o = [s.replace('24','i') for s in o]
o = [s.replace('25','j') for s in o]
o = [s.replace('31','k') for s in o]
o = [s.replace('32','l') for s in o]
o = [s.replace('33','m') for s in o]
o = [s.replace('34','n') for s in o]
o = [s.replace('35','o') for s in o]
o = [s.replace('41','p') for s in o]
o = [s.replace('42','q') for s in o]
o = [s.replace('43','r') for s in o]
o = [s.replace('44','s') for s in o]
o = [s.replace('45','t') for s in o]
o = [s.replace('51','u') for s in o]
o = [s.replace('52','v') for s in o]
o = [s.replace('53','w') for s in o]
o = [s.replace('54','x') for s in o]
o = [s.replace('55','y') for s in o]
o = [s.replace('61','z') for s in o]
o = [s.replace('62',' ') for s in o]
f = ''.join(o)
print f
with open('decrypted.txt', 'a') as the_file:
the_file.write(f + ' <br> ')
Any help would be appreciated. Also, any slimming down that you do could help too, just because I feel like there has to be a better way to do it. Thanks in advance guys! -Richard
forloops and use adictionaryto map plaintext characters to their numeric string cyphertext, and vice versa.