index koincidence pro kratke zpravy nmail
authorTomas Musil <tomik.musil@gmail.com>
Tue, 4 Jun 2013 16:26:21 +0000 (18:26 +0200)
committerTomas Musil <tomik.musil@gmail.com>
Tue, 4 Jun 2013 16:26:21 +0000 (18:26 +0200)
koincidence.py
krypto.py

index 5c943ec..f49174b 100644 (file)
@@ -32,8 +32,9 @@ def index_rozkladu(text, deleni):
 
 def tabulka_indexu(text):
     """Vypise tabulku prumernych indexu pro ruzna deleni textu."""
+    n = min((len(text)/3), 11)
     return '\n'.join(['{1:>2} {0:>7.3%}'.format(
-        index_rozkladu(text, d), d) for d in range(1, 11)])
+        index_rozkladu(text, d), d) for d in range(1, n)])
 
 def rozklad(text, deleni):
     """Vrati pole retezcu, v kazdem jsou znaky z puvodniho textu jejichz pozice
index c0ed935..392e8ba 100755 (executable)
--- a/krypto.py
+++ b/krypto.py
@@ -67,11 +67,12 @@ def analyza(zprava, opsny):
         analyza.append("\nIndex koincidence (s mezerami):")
         analyza.append('{0:.2%}'.format(
                        koincidence.index_koincidence(zprava, True)))
-    if mod_x and len(zprava) >= 30:
+    if mod_x:
         #TODO tady by se spravne mela porovnavat delka ocesane zpravy
         analyza.append("\nIndexy koincidence (bez mezer):")
         analyza.append(koincidence.tabulka_indexu(zprava))
 
+
     # Vigenere
     if 'V' in opsny:
         analyza.append("\nHeslo k Vigenerovi (" + opsny[-1] + "):")