For a random project, I'm writing a python program that randomly generates "encryption" and "decryption" routines for strings. The resulting routines are mean to be used in
eval()
def buildRoutines(routine_len):
instructions = ['+', '-', '^']
pairs = {'+': '-', '-': '+', '^': '^'}
encrypt = ""
decrypt = ""
random.seed()
for _ in range(0, routine_len):
i = random.randrange(3)
j = random.randrange(100)
encrypt += 'e=' + 'chr((' + 'ord(e)' + instructions[i] + str(j) + ')%255)' + ';'
decrypt = 'e=' + 'chr((' + 'ord(e)' + pairs[instructions[i]] + str(j) + ')%255)' + ';' + decrypt
# Do some more stuff
encrypt = 'a="";e=""\nfor b in c:e=b;' + encrypt + 'a+=e;'
decrypt = 'd="";e=""\nfor b in a:e=b;' + decrypt + 'd+=e;'
return {'encrypt': encrypt, 'decrypt': decrypt}