Skip to content

Instantly share code, notes, and snippets.

@RdlP
Created February 22, 2019 18:19
Show Gist options
  • Save RdlP/feb78da9cf91dd9f1f74f8a0462dfd79 to your computer and use it in GitHub Desktop.
Save RdlP/feb78da9cf91dd9f1f74f8a0462dfd79 to your computer and use it in GitHub Desktop.
import sys
from collections import Counter
english_frequencies = [" ","E","T","A","O","I","N","S","R","H","D","L","U","C","M","F","Y","W","G","P","B","V","K","X","Q","J","Z"]
founds = open(sys.argv[1]).read()
grams = int(sys.argv[2])
#preprocess
founds = founds.replace(" ","")
founds = founds.replace('\n', "")
result=[]
for i in range(grams):
result.append(Counter())
for j in range(0,len(founds)):
result[i].update([founds[j:j+i+1]])
print("================={}-gramas más frecuentes=================".format(i+1))
print(result[i].most_common())
plaintext=""
manual_subs = {'S':'E','J':'T','D':'H', 'Q':'A', 'G':'N','W':'D','C':'I','U':'S','N':'R','B':'O','Z':'C','V':'L','M':'U','Y':'P','L':'Y','E':'G','K':'W','F':'K','X':'F', 'T':'M','H':'Q','A':'B','O':'X'}
print("=====Intentando descibrar con las siguientes sustituciones=====")
print(manual_subs)
for i in founds:
if (i in manual_subs):
plaintext+=manual_subs[i]
else:
plaintext+='*'
print(plaintext)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment