lab_encryption/caesar_cracker.py

15 lines
368 B
Python

from collections import Counter
from easybits import Bits
def crack_caesar(ciphertext):
frequencies = Counter(ciphertext)
most_common = frequencies.most_common(1)[0]
most_common_character = most_common[0]
space_value = Bits(' ').int
character_value = Bits(most_common_character).int
shift = character_value - space_value
return shift