projects
/
cipher-tools.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
e354c8a
)
Can now do frequency analysis
author
Neil Smith
<neil.git@njae.me.uk>
Thu, 3 Oct 2013 19:34:21 +0000
(20:34 +0100)
committer
Neil Smith
<neil.git@njae.me.uk>
Thu, 3 Oct 2013 19:34:21 +0000
(20:34 +0100)
cipher.py
patch
|
blob
|
history
diff --git
a/cipher.py
b/cipher.py
index f938f3677f321d02805688ac443328314af0406f..c4b28ba321ea4a55953af22f914c5b94a7843b6f 100644
(file)
--- a/
cipher.py
+++ b/
cipher.py
@@
-1,4
+1,5
@@
import string
+import collections
def caesar_cipher_letter(letter, shift):
@@
-21,3
+22,11
@@
def caesar_cipher_message(message, shift):
def caesar_decipher_message(message, shift):
return caesar_cipher_message(message, -shift)
+
+def letter_frequencies(message):
+ frequencies = collections.defaultdict(int)
+ for letter in message:
+ if letter in string.ascii_letters:
+ frequencies[letter.lower()]+=1
+ return frequencies
+