diff --git a/answers.md b/answers.md index f125e69..165df03 100644 --- a/answers.md +++ b/answers.md @@ -3,23 +3,24 @@ ## Checkpoint 1 0. `secrets/secret0.txt` is encrypted using a Caesar Cipher. What is - its secret number? + its secret number? 78 1. `secrets/secret1.txt` is encrypted using a Caesar Cipher. What is - its secret number? + its secret number? 1 2. `secrets/secret2.txt` is encrypted using a Caesar Cipher. What is - its secret number? + its secret number? 44 3. `secrets/secret3.txt` is encrypted using a Caesar Cipher. What is - its secret number? + its secret number? 59 4. `secrets/secret4.txt` is encrypted using a Caesar Cipher. What is - its secret number? + its secret number? 32 ## Checkpoint 2 -5. What is the polyalphabetic secret word? +5. What is the polyalphabetic secret word? supersecret 6. Decrypt this message, which was encrypted using the same secret word: "EbZhdaV[h^bTpchhQnhig]X[VmhhRP]ftXVnRfjVY]fgtO_X](" +answer: Cryptography is the practice and study of techniques for secure communication. \ No newline at end of file diff --git a/caesar_cracker.py b/caesar_cracker.py index 471ee8c..6a8cfb9 100644 --- a/caesar_cracker.py +++ b/caesar_cracker.py @@ -1,13 +1,11 @@ from collections import Counter +from easybits import Bits def crack_caesar(ciphertext): + counts = Counter(ciphertext) - counts = Counter(ciphertext.upper()) + most_common = counts.most_common(1)[0][0] - most_common_letter = counts.most_common(1)[0][0] + shift = Bits(most_common).int - Bits(' ').int - alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - - shift = (alphabet.index(most_common_letter) - alphabet.index("E")) % 26 - - return shift \ No newline at end of file + return shift diff --git a/caesar_cracker.py.save b/caesar_cracker.py.save new file mode 100644 index 0000000..15fbe56 --- /dev/null +++ b/caesar_cracker.py.save @@ -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 diff --git a/easybits.py b/easybits.py new file mode 100644 index 0000000..7a2b556 --- /dev/null +++ b/easybits.py @@ -0,0 +1,21 @@ +class Bits: + def __init__(self, value, encoding='ascii', length=None): + if isinstance(value, str): + self.int = ord(value) + elif isinstance(value, int): + self.int = value % 128 # ⚠️ change to 128 (ASCII range) + else: + raise TypeError("Unsupported type") + + @property + def ascii(self): + return chr(self.int) + + def __add__(self, other): + return Bits((self.int + other.int) % 128) + + def __sub__(self, other): + return Bits((self.int - other.int) % 128) + + def __repr__(self): + return f"Bits({self.int})"