generated from mwc/lab_encryption
checkpoint 1:Writing my own code for Checkpoint 1 was challenging
at first, but it ended up helping me understand the problem much better. Instead of just thinking about how the Caesar cipher works, I had to actually apply the logic step-by-step in code. Using `Counter` to find the most common character and then calculating the shift made the idea of frequency analysis much clearer. At first, I struggled with errors and figuring out how everything connected, but once it worked, it made sense why the most common character could be used to guess the shift. Writing the code forced me to think about how characters are represented as numbers and how shifting works mathematically. Overall, coding the solution helped turn an abstract idea into something concrete, and it made me feel more confident solving similar problems in the future. checkpoint 2: To find the polyalphabetic secret word, I compared the given plaintext and ciphertext character by character. For each pair of characters, I calculated the shift by subtracting their ASCII values. This gave me a list of numbers representing how much each character was shifted. When I looked at the sequence of shifts, I noticed that the pattern repeated, which showed that the cipher was using a repeating key. From this repeating pattern, I was able to identify the secret word as “supersecret.” To decrypt the final message, I used the same key and applied it repeatedly across the ciphertext. For each character, I subtracted the corresponding key character’s value (looping through the key as needed). This reversed the encryption process and produced the original readable English message. This strategy worked because polyalphabetic ciphers rely on repeating shifts, so once the pattern is discovered, the entire message can be decrypted.
This commit is contained in:
13
caesar_cracker.py.save
Normal file
13
caesar_cracker.py.save
Normal file
@@ -0,0 +1,13 @@
|
||||
from collections import Counter
|
||||
|
||||
def crack_caesar(ciphertext):
|
||||
|
||||
counts = Counter(ciphertext.upper())
|
||||
|
||||
most_common_letter = counts.most_common(1)[0][0]
|
||||
|
||||
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
|
||||
shift = (alphabet.index(most_common_letter) - alphabet.index("E")) % 26
|
||||
|
||||
return shift
|
||||
Reference in New Issue
Block a user