generated from mwc/lab_encryption
Developing this code was not the easiest. I did run into some trouble at first with it returning a different secret number from the example in the notes online but then after changing the code and debugging it I got it to return the secret number to be 34. I was able to understand how Caesar Cipher actually works.
23 lines
533 B
Python
23 lines
533 B
Python
from collections import Counter
|
|
from ciphers.caesar import CaesarCipher
|
|
from easybits import Bits
|
|
|
|
class CaesarCracker:
|
|
|
|
def crack_caesar(self, ciphertext):
|
|
|
|
freq = Counter(ciphertext)
|
|
|
|
most_common_cipher_char = freq.most_common(1)[0][0]
|
|
|
|
space_int = Bits(' ').int
|
|
cipher_int = Bits(most_common_cipher_char).int
|
|
|
|
secret = cipher_int - space_int
|
|
|
|
return secret
|
|
|
|
def crack_caesar(ciphertext):
|
|
cracker = CaesarCracker()
|
|
return cracker.crack_caesar(ciphertext)
|