generated from mwc/lab_encryption
Checkpoint 1 completed
This commit is contained in:
31
caesar_cracker.py
Normal file
31
caesar_cracker.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from easybits import Bits
|
||||
from collections import Counter
|
||||
from ciphers.caesar import CaesarCipher
|
||||
|
||||
|
||||
def crack_caesar(ciphertext):
|
||||
fulltext = ''
|
||||
with open(ciphertext,"r") as text:
|
||||
for line in text:
|
||||
cleanline = line.strip()
|
||||
for char in cleanline:
|
||||
fulltext += char
|
||||
counter = Counter(fulltext)
|
||||
countdict = dict(counter)
|
||||
|
||||
print(countdict)
|
||||
|
||||
maximum = max(countdict.values())
|
||||
target = ''
|
||||
for char in countdict:
|
||||
if countdict[char] == maximum:
|
||||
target = char
|
||||
|
||||
diff = Bits(target,8).int - Bits(" ",8).int
|
||||
cipher = CaesarCipher(diff)
|
||||
decryptedtext = cipher.decrypt(fulltext)
|
||||
|
||||
return diff, decryptedtext
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user