generated from mwc/lab_encryption
13 lines
310 B
Python
13 lines
310 B
Python
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 |