code-break-party/code/fried.py

26 lines
5.5 KiB
Python
Raw Normal View History

import numpy as np
transposes = ['GADSJFEDVAWFYJSGLSGFVELTSWZGKNYGWGKWFZWZJFJZFDLFJKFLLJLESJUVFHMJWKJNWAVSKSHWSWHGWEZWGATVDJLMWWWWODAUUJFTSDFFLSWAAEUFKJQSKJFGYWAAVFVLSSVLJWTVSWJLJFFFZJWLQSAGQFAZEDFSZGDFVSKEJXDLFOZGVKHNGETLLKGKWHJLZLJEXGWDHWAGLJGGOKSLHMSXWAVWGZWEWAAJVSJGWYXUAKXYZVXJGYFDGXMKFASFAAHGDAHYJJZWXWWGWXJZWLHVLDIFJWJWLGALFEWWMAFKZLAWLAZGVHXQSKGZJLLDVWFWAYWFZFVWYFSDDDXMWWAWQQLXZGFYFAVBSALVJDAJGELLGDW', 'BUSYARSCSBFUSOAAHHFCWSVSFFCCVOVAOFHFHSBSSGIDHZOSSHUCWSFPHSSCRFZVBOISPKGACAWFFOSCFCOFRBHFSSVBGBCGVSGVYSROAZAOOHTRGMSKOMVAASRDHBFBOCOVBACKRRSIZADOSMUHSBQKQBGQUHBHSMWBSFZZWWOSSCDBPOGJCHHSCSIHVDBGKCHSSSQIFKASSTFFVCOIVWBTDBGORGSRDCCCBBBOOHRCJWHMBCMFOCMCFOUSHWFCRBRWCBZSJBZCSSHBFBFCRZWZGVWBVSISUBODVDFVHDSGBGQVOFGPSASFWFPHHPHWFVOQAOCORSEBOCCYUHBISIHZOGHAPVVASFBGUBPIAGVSSOACBMVZBZF', 'CHIAACORDGEANPBEEMOTSMERAWSREITMSRLAMAORAASUHESVSIOOSNAEEAAONEGENILNUAOEFENDCRNRERTITGIEVAEBTONPINPOTMNCBMEGPLOISWLHNEEOYTNEHWTTSFYECIRIOARPLYENTBMOGDOORDARRRGLWNGSREEYSNNALRAOESEEOUUHRATIEOEOOUHRRRETINOASODEEKPBATDRYMTSFSNIELFRSGTICIAREBOUKMOISMOAEGBEHENMMIANNGIREGIESTTSOSATOOEEESTEY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NXBCBLNADUXCWRONNWQNORQWCCYRVWWJKCRDKWNBDHBFBXCJQANNQXXNQXQECPOBWQCDCXNBNRNRJBJUCNBEURCQBQNMUXXNYBRUDNNOCNEKXCRWRCJQJYJCUNADWRJKVPBUXCXWTCJVMADNNRBBYJNAEWJWCRQXXXJXN', 'VHNHRECRWUJNYVCAYNBAHJNQPRQHAMXBAQXJQJUNRCOAVQAKXNACBWHXACVCVVXWAMXYLWHPHPQCAACBQWBRWPVXMNNWBWCBFBMNUQVQRRPJVQUCWJNNHUCMGRVONHCNAWNKNXQXNLACJAWWBDWPMXWPQCDJWWNCUWCXEJWQBPCCKXPQAMAVABCKLVNUKCRJMWQOORCCEXFVXCENNYTJNCJDFUXURNUQUWNNPJWNNXJXWHPLCRCWWRCEJNURQWVQCVNLCNJBCNJJNQADNPXROLMKQNCONOTWXQAJRUUNNNXCXJWAUUCUUXECNRENXMNCRBBRXVJWQNANAPBAJYQQJTQTNNJTXCXXEACRBJUVJNPCMXWJAVFCAM', 'IWDONOTNAYPOIYIIIRAEISCSETEIRSWUOERDOMERLAETEFOEWATIIGCMERBIOYNGSARLTGOAOTAIEEHSITSSDDIRTBWDGDHTOIADEIOENTSREAYHGTTASEITPNOLRATPATNENPEFRHCOBDDGEICBSFCHOHRSCDNEOTOTERGEOHTTOTTUYWDBBCAEHONYUHFTOGEELSHHENIYWHEDSLEIROUNHDWLLBLIABVRUNGEDFNNKSFYTRHLTRIETSLNOOYIDYCULLTELLTLROEMEBSNTHHYERERSFIDSTMILI
def compute_frequencies(block):
letter_count = {}
letters = [chr(i) for i in range(ord('A'), ord('Z')+1)]
for l in letters:
letter_count[l] = block.count(l)
return letter_count
def coincidence(block):
compute_frequencies(block)
freq = compute_frequencies(block)
sum = 0
for f in freq:
sum += freq[f] * (freq[f]-1)
kappa = float(sum)/(len(block) * (len(block)-1))
return kappa
for t in transposes:
print("kappa", coincidence(t))
for t in transposes:
d = compute_frequencies(t)
print(chr((ord('E') - ord(d.keys()[np.argmax(d.values())]))%26+65))