fix(wpcarro/cryptopals): Update cleartext scoring algorithm
Create a frequency table of alphabetic characters by reading each character in "Alice in Wonderland"; use this frequency table to score cleartext when decoding ciphers. Change-Id: Id322af64d792c15231a1a02794f396c46196c207 Reviewed-on: https://cl.tvl.fyi/c/depot/+/4788 Tested-by: BuildkiteCI Reviewed-by: wpcarro <wpcarro@gmail.com> Autosubmit: wpcarro <wpcarro@gmail.com>
This commit is contained in:
parent
7ab4493c75
commit
7aaddb3d31
3 changed files with 45 additions and 11 deletions
|
|
@ -2,11 +2,22 @@ import c3
|
|||
|
||||
content = None
|
||||
with open('4.txt', 'r') as f:
|
||||
c3.decode_cipher
|
||||
content = f.read().splitlines()
|
||||
if not content:
|
||||
raise Error("Need content to proceed")
|
||||
|
||||
xs = []
|
||||
for line in content:
|
||||
try:
|
||||
print(c3.decode_cipher(line))
|
||||
x = c3.decode_cipher(line)
|
||||
if x: xs.append(x)
|
||||
except:
|
||||
continue
|
||||
|
||||
freqs = c3.frequency_table()
|
||||
print(max(xs, key=lambda x: c3.score(x, freqs)))
|
||||
|
||||
################################################################################
|
||||
# Answer
|
||||
################################################################################
|
||||
"Now that the party is jumping"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue