Added some extra code :)

This commit is contained in:
Chris Proctor 2024-05-09 11:35:41 -04:00
parent de981ca670
commit d85c23c3c8
1 changed files with 24 additions and 0 deletions

24
letter_distribution.py Normal file
View File

@ -0,0 +1,24 @@
from collections import defaultdict, Counter
def get_letter_distribution(message):
"""We want something like
{
"a": 15,
"b": 3,
"c": 2
}
"""
return Counter(message).items()
def has_lots_of_spaces(message):
char, count = Counter(message).most_common(1)[0]
return char == ' '
message = """
For our first encryption, we will use the Caesarian cipher, named so because Julius Caesar (yes that one) used it in sending his own messages. A Caesarian cipher simply shifts each letter the same number of places down the alphabet, with later numbers wrapping around back to the beginning. In other words, if we associated each letter to a number between 0 and 25, with 'A' as 0 and 'Z' as 25, we might add 1 mod 25. This is our old friend, modular arithmetic, where 20+6=1 because it's the remainder we get when we divide 26 by 25. In other words, it's precisely 1 more than a multiple of 25. A cipher that just adds 1 mod 25 would turn CAT into DBU.
"""
print(has_lots_of_spaces(message))