Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.11 KB | None | 0 0
  1. #This requires a string with no spaces or punctuation and just a straight string this website http://textmechanic.com/text-tools/basic-text-tools/remove-extra-spaces/ followed by this website http://www.striphtml.com/ can do this
  2. cipher = "PIZZG"  
  3.  
  4. plaintext = open("plaintext.txt", "r+")
  5. for i in range(27):
  6.  
  7.     #Initialize the array
  8.     freqlist = []
  9.  
  10.     #Shift all the letters in the input
  11.     for a in cipher:
  12.         b = ord(a)
  13.         b -= i
  14.         if b > ord("Z"):
  15.             b -= 26
  16.         elif b < ord("A"):
  17.             b+=26
  18.         freqlist.append(b)
  19.  
  20.     #Now put the shifted letters back together
  21.     shifted = ""
  22.     for a in freqlist:
  23.         d = chr(a)
  24.         #Append the shifted letter onto our output
  25.         shifted += d
  26.        
  27.     plaintext.write(" ")
  28.     plaintext.write(str(shifted))
  29.     plaintext.write("\n")
  30.  
  31.     #After we put the decrypted string back together, print it
  32.     #Note this is outside the letter loops,
  33.     #But still inside the possible shifts loop
  34.     #Thus printing all possible shifts for the given message
  35.     print(shifted)
  36. plaintext.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement