generated from mwc/lab_encryption
I have created the code in caesar_cracker.py along with finding the secret numbers for each secret txt that are answered in answers.md.
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.
This commit is contained in:
22
caesar_cracker.py
Normal file
22
caesar_cracker.py
Normal file
@@ -0,0 +1,22 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user