document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #!/usr/bin/python                                                                                      
  2.  
  3. import random
  4. import sys
  5.  
  6. #genera la llave con numeros random
  7. def get_randkey(texto):                                                                                            
  8.     a=\'0\'
  9.     b=\'9\'                                                                                        
  10.     for i in range(0,len(texto)-1):
  11.         a += \'0\'
  12.         b += \'9\'
  13.  
  14.     key = random.randint(int(a), int(b))
  15.     return str(key)
  16.  
  17. #utiliza xor para cifrar y descifrar el texto
  18. def crypt_decrypt(texto, key):
  19.  
  20.     cipher_text = ""
  21.     for char in texto:
  22.         for ch in key:
  23.             char = chr(ord(char)^ ord(ch))
  24.         cipher_text += char
  25.     return (cipher_text)
  26.  
  27.  
  28. def main():
  29.     while True:
  30.         print """                                                                                      
  31. 1. Encrypt                                                                                              
  32. 2. Decrypt                                                                                              
  33. 3. Change key                                                                                          
  34. 4. Exit                                                                                                
  35. --->                                                                                                    
  36. """
  37.         opcion=raw_input()
  38.         if(opcion==\'1\'):
  39.             texto = raw_input("Message: ")
  40.             key = get_randkey(texto)
  41.             texto = crypt_decrypt(texto,key)
  42.             print "Key: ", key
  43.             print "Encrypted message:\\n", texto
  44.         elif(opcion==\'2\'):
  45.             texto = crypt_decrypt(texto,key)
  46.             print "Decrypted message:\\n", texto
  47.         elif(opcion==\'3\'):
  48.             key = get_randkey(texto)
  49.             print key
  50.         elif(opcion==\'4\'):
  51.             sys.exit()
  52.  
  53. main()
');