Fix bug in auto-decrypt.
This commit is contained in:
parent
6a5e31d8f4
commit
baa81c46d1
|
@ -70,10 +70,6 @@ def decrypt():
|
||||||
for c in ciphertext: # For every letter in the ciphertext
|
for c in ciphertext: # For every letter in the ciphertext
|
||||||
while letterPos < 26: # While the letter's position in the alphabet is less than 26 (and thus valid), continue.
|
while letterPos < 26: # While the letter's position in the alphabet is less than 26 (and thus valid), continue.
|
||||||
|
|
||||||
if not commonletter == 0:
|
|
||||||
if commonletter == letters[letterPos]: # If the most frequent letter matches the current letter, set the shift to that letter because that is the shift for the cipher. Forgot the double equals for comparison.
|
|
||||||
shiftNum = letterPos - 4
|
|
||||||
|
|
||||||
if ciphertext[letterCount] == letters[letterPos]: # Match the letter in the ciphertext to a letter in the alphabet and once they match, continue.
|
if ciphertext[letterCount] == letters[letterPos]: # Match the letter in the ciphertext to a letter in the alphabet and once they match, continue.
|
||||||
letter = int(letterPos) - int(shiftNum) # Take the position of the letter and the shift number and add them for the enciphered letter.
|
letter = int(letterPos) - int(shiftNum) # Take the position of the letter and the shift number and add them for the enciphered letter.
|
||||||
|
|
||||||
|
@ -98,8 +94,25 @@ def freq():
|
||||||
# Grab global variables.
|
# Grab global variables.
|
||||||
global ciphertext
|
global ciphertext
|
||||||
global commonletter
|
global commonletter
|
||||||
|
global letterPos
|
||||||
|
global shiftNum
|
||||||
|
print(shiftNum)
|
||||||
|
|
||||||
commonletter = collections.Counter(ciphertext).most_common()[0][0] # Find most common letter and thus the shift https://stackoverflow.com/questions/47251934/how-to-count-the-most-frequent-letter-in-a-string
|
commonletter = collections.Counter(ciphertext).most_common()[0][0] # Find most common letter and thus the shift https://stackoverflow.com/questions/47251934/how-to-count-the-most-frequent-letter-in-a-string
|
||||||
|
|
||||||
|
for c in ciphertext:
|
||||||
|
while letterPos < 26:
|
||||||
|
|
||||||
|
if not commonletter == 0:
|
||||||
|
if commonletter == letters[letterPos]: # If the most frequent letter matches the current letter, set the shift to that letter because that is the shift for the cipher. Forgot the double equals for comparison.
|
||||||
|
|
||||||
|
shiftNum = letterPos - 4
|
||||||
|
|
||||||
|
if letterPos > 25: # If the letter position is greater than 25, cycle back through the alphabet.
|
||||||
|
letterPos = letterPos - 26
|
||||||
|
|
||||||
|
letterPos = letterPos + 1 # Iterate through letter positions in the alphabet. (neccessary to find one that matches.)
|
||||||
|
|
||||||
decrypt() # Decrypt using the frequency found in here.
|
decrypt() # Decrypt using the frequency found in here.
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue