#!/usr/bin/python
import random
import sys
#genera la llave con numeros random
def get_randkey(texto):
a=\'0\'
b=\'9\'
for i in range(0,len(texto)-1):
a += \'0\'
b += \'9\'
key = random.randint(int(a), int(b))
return str(key)
#utiliza xor para cifrar y descifrar el texto
def crypt_decrypt(texto, key):
cipher_text = ""
for char in texto:
for ch in key:
char = chr(ord(char)^ ord(ch))
cipher_text += char
return (cipher_text)
def main():
while True:
print """
1. Encrypt
2. Decrypt
3. Change key
4. Exit
--->
"""
opcion=raw_input()
if(opcion==\'1\'):
texto = raw_input("Message: ")
key = get_randkey(texto)
texto = crypt_decrypt(texto,key)
print "Key: ", key
print "Encrypted message:\\n", texto
elif(opcion==\'2\'):
texto = crypt_decrypt(texto,key)
print "Decrypted message:\\n", texto
elif(opcion==\'3\'):
key = get_randkey(texto)
print key
elif(opcion==\'4\'):
sys.exit()
main()