SHARE
TWEET

Caeser decrypter

a guest Mar 23rd, 2016 416 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import os
  2.  
  3. def clear():
  4.     os.system('cls' if os.name=='nt' else 'clear')
  5.    
  6. def pause():
  7.     input("\nPress ENTER to continue!")
  8.    
  9. def caesarDecrypt(text):
  10.     frequencyLetters = [0 for i in range(26)]
  11.     for c in text:
  12.         ucode = ord(c)
  13.         ucode -= 97
  14.            
  15.         if ucode < 26 and ucode >= 0:
  16.             frequencyLetters[ucode] += 1
  17.    
  18.     clear()
  19.     print("-=|-=|-=|Decrypted Texts sorted by frequency|=-|=-|=-")
  20.    
  21.     for i in range(26):
  22.         MostOftenLetter = 0
  23.         for c in range(len(frequencyLetters)):
  24.             if frequencyLetters[MostOftenLetter] < frequencyLetters[c]:
  25.                 MostOftenLetter = c
  26.        
  27.         print(str(MostOftenLetter) + " : " + str(frequencyLetters[MostOftenLetter]))
  28.         input()
  29.        
  30.         if frequencyLetters[MostOftenLetter] == 0:
  31.             break
  32.            
  33.         frequencyLetters[MostOftenLetter] = 0
  34.        
  35.         key = MostOftenLetter - 4
  36.         print("Decrypted Text with key " + str(key) + ":")
  37.         textDecrypted = decryptCaesarKey(text, key)
  38.        
  39.         if len(textDecrypted) < 80:
  40.             print(textDecrypted)
  41.         else:
  42.             print(textDecrypted[0:80])
  43.         print()
  44.        
  45. def decryptCaesarKey(text, key):
  46.     textDecrypted = []
  47.     for c in text:
  48.         c = c.lower()
  49.         ucode = ord(c)
  50.         ucode -= 97
  51.        
  52.         if ucode < 0 or ucode > 25:
  53.             textDecrypted.append(c)
  54.             continue
  55.            
  56.         c = ucode - key + 97
  57.         if c < 97:
  58.             c = 26 + c
  59.            
  60.         elif c > 122:
  61.             c = c - 26
  62.            
  63.         c = chr(c)
  64.         textDecrypted.append(c)
  65.        
  66.     textDecrypted = "".join(textDecrypted)
  67.     return textDecrypted
  68.    
  69.     #####################################
  70.     #                                   #
  71.     #            Entry Point            #
  72.     #                                   #
  73.     #####################################
  74.    
  75. while True:
  76.     clear()
  77.     print("-~=-~=-~=Decrypt Manager by PowerOfRandom=~-=~-=~-")
  78.     print("1 - Decrypt Caeser via Input")
  79.    
  80.     eingabe = input("\nChose: ")
  81.    
  82.     if eingabe == "1":
  83.         clear()
  84.         encryptedText = input("Encrypted Text: ")
  85.        
  86.         caesarDecrypt(encryptedText)
  87.        
  88.         pause()
  89.    
  90.     else:
  91.         print("\nChose one of the numbers to start!")
  92.         pause()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top