generated from mwc/lab_encryption
Writing my own code helped me understand and solve
the problem. In Checkpoint 1, writing the code itself was a means of solving the problem. Figuring out what worked and what didn't work led to conceptual understanding of the problem. Honestly, I was fairly confidant in my oringinal approach to checkpoint 1, as I have solved similar problems in the past. For checkpoint 2, I assigned each character its value in the ASCII, since the first printable character at 32 and ends at the last printable character at 126. We look for reapeated character chunks like in the Kasiski examination method, and find the distance between them. In this case it was 42. Then possible periods are factors of 42. Testing each of these, the only one that spelled a valid english word was a period of 6, giving the word python. Then, when we use that key we can decrpyt the strings using frequency analysis.
This commit is contained in:
24
caesar_cracker.py
Normal file
24
caesar_cracker.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from easybits import Bits
|
||||
from collections import Counter
|
||||
from ciphers.caesar import CaesarCipher
|
||||
|
||||
def crack_caesar(ciphertext):
|
||||
counted = Counter(ciphertext)
|
||||
charlist = list(counted.keys())
|
||||
commonchar = charlist[0]
|
||||
for char in charlist:
|
||||
if counted[char] > counted[commonchar]:
|
||||
commonchar = char
|
||||
return Bits(commonchar).int - Bits(" ").int
|
||||
|
||||
with open("secrets/secret4.txt") as f:
|
||||
ciphertext = f.read()
|
||||
|
||||
|
||||
|
||||
secret = crack_caesar(ciphertext)
|
||||
cipher = CaesarCipher(secret)
|
||||
plaintext = cipher.decrypt(ciphertext)
|
||||
|
||||
print(secret)
|
||||
print(plaintext)
|
||||
Reference in New Issue
Block a user