Can now do frequency analysis
authorNeil Smith <neil.git@njae.me.uk>
Thu, 3 Oct 2013 19:34:21 +0000 (20:34 +0100)
committerNeil Smith <neil.git@njae.me.uk>
Thu, 3 Oct 2013 19:34:21 +0000 (20:34 +0100)
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
+