import os
import binascii
import math

# get plaintext and user input
print('Enter plaintext: ')
plaintext = input()
print('Enter Shift (0 for brute force): ')
shift = input()
print('Enter second shift (0 for ceaser or brute-force): ')
shift2 = input()
print('A: Ceaser Cipher Encode')
print('B: Ceaser Cipher Decode')
print('C: Ceaser Cipher Brute-Force')
print('D: Affine Cipher Encode')
print('E: Affine Cipher Decode')
print('F: Affine Cipher Brute-Force')
print('What would you like to do: ')
mode = input()

# functions to convert numbers to letters and vice versa
def lnumtolet(num):
    num = num % 26
    letarray = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',]
    return letarray[num - 1]

def unumtolet(num):
    num = num % 26
    letarray = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',]
    return letarray[num - 1]

def llettonum(let):
    return (ord(let) - 96)

def ulettonum(let):
    return (ord(let) - 96)

def split(s):
    return [char for char in s]

# ceaser cipher function
def ceaser(shift, args):
    shifter = int(shift)
    shift = shifter % 26
    ret = []
    for i in args:
        splited = split(i)
        for j in splited:
            # encrypt each letter individually
            if j.isalpha():
                if j.islower():
                    tempnum = llettonum(j)
                    num = int(tempnum)
                    num = num + shift
                    let = lnumtolet(num)
                    ret.append(let)
                else:
                    j = j.lower()
                    tempnumu = ulettonum(j)
                    numu = int(tempnumu)
                    numu = numu + shift
                    letu = unumtolet(numu)
                    ret.append(letu)
            else:
                ret.append(j)
        ret.append(' ')
    returner = ''.join(ret)
    return returner

#affine cipher
def ac(a, b, args):
    shift1 = int(a)
    shift2 = int(b)
    ret = []
    for i in args:
        splited = split(i)
        for j in splited:
            if j.isalpha():
                if j.islower():
                    tempnum = llettonum(j)
                    num = int(tempnum)
                    num = ((num * shift1) + shift2) % 26
                    let = lnumtolet(num)
                    ret.append(let)
                else:
                    j = j.lower()
                    tempnumu = ulettonum(j)
                    numu = int(tempnumu)
                    numu = ((numu * shift1) + shift2) % 26
                    letu = unumtolet(numu)
                    ret.append(letu)
            else:
                ret.append(j)
        ret.append(' ')
    retu = ''.join(ret)
    return retu

#get list of common words
w = open('../assets/wordlist.txt', 'r')
#split into array
wordlist = (w.read()).split('\n')

# check if word is in wordlist
def is_word(text):
    words = 0
    plaintext = text.split(' ')
    for word in plaintext:
        if word in wordlist:
            words += 1
    return words


def compare_word(text):
    num_words = is_word(text)
    return num_words


if mode == 'A':
    # encode with shift
    print('Encoded text: ' + ceaser(shift, plaintext)[::2])
elif mode == 'B':
    #decode with shift
    print('Decoded text: ' + ceaser((26 - int(shift)), plaintext)[::2])
elif mode == 'C':
    #brute force decode
    attempts = {}
    # try every combination
    for i in range(1, 26):
        attempt = ceaser((26 - i), plaintext)[::2]
        # append to dictionary with number of valid words
        attempts[attempt] = compare_word(attempt)
        # sort dictionary with largest number of words first
    ordered = dict(sorted(attempts.items(), key=lambda a: a[1], reverse=True))
    print('Brute Force Complete! Best guesses printed below.')
    # print 5 best guesses
    for i in range(5):
        print(list(ordered.keys())[i] + ' - score = ' + str(list(ordered.values())[i]))
# repeat for affine cipher
elif mode == 'D':
    print('Encoded text: ' + ac(shift, shift2, plaintext)[::2])
elif mode == 'E':
    print('Decoded text: ' + ac(shift, shift2, plaintext)[::2])
elif mode == 'F':
    attempts = {}
    for i in range(1, 26):
        for j in range(1, 26):
            attempt = ac(i, j, plaintext)[::2]
            attempts[attempt] = compare_word(attempt)
    print(attempts)
    ordered = dict(sorted(attempts.items(), key=lambda a: a[1], reverse=True))
    print('Brute Force Complete! Best guesses printed below.')
    for i in range(5):
        print(list(ordered.keys())[i] + ' - score = ' + str(list(ordered.values())[i]))
Enter plaintext: 
Enter Shift (0 for brute force): 
Enter second shift (0 for ceaser or brute-force): 
A: Ceaser Cipher Encode
B: Ceaser Cipher Decode
C: Ceaser Cipher Brute-Force
D: Affine Cipher Encode
E: Affine Cipher Decode
F: Affine Cipher Brute-Force
What would you like to do: 
{'zlqxkvxsby jn nzxxq': 0, 'amrylwytcz ko oayyr': 1, 'bnszmxzuda lp pbzzs': 1, 'cotanyaveb mq qcaat': 0, 'dpubozbwfc nr rdbbu': 1, 'eqvcpacxgd os seccv': 1, 'frwdqbdyhe pt tfddw': 1, 'gsxercezif qu ugeex': 0, 'htyfsdfajg rv vhffy': 1, 'iuzgtegbkh sw wiggz': 1, 'jvahufhcli tx xjhha': 1, 'kwbivgidmj uy ykiib': 0, 'lxcjwhjenk vz zljjc': 0, 'mydkxikfol wa amkkd': 1, 'nzelyjlgpm xb bnlle': 0, 'oafmzkmhqn yc commf': 0, 'pbgnalniro zd dpnng': 0, 'qchobmojsp ae eqooh': 1, 'rdipcnpktq bf frppi': 0, 'sejqdoqlur cg gsqqj': 1, 'tfkreprmvs dh htrrk': 1, 'uglsfqsnwt ei iussl': 0, 'vhmtgrtoxu fj jvttm': 0, 'winuhsupyv gk kwuun': 0, 'xjovitvqzw hl lxvvo': 1, 'ywguuqukcw sa ayuug': 1, 'zxhvvrvldx tb bzvvh': 1, 'ayiwwswmey uc cawwi': 1, 'bzjxxtxnfz vd dbxxj': 0, 'cakyyuyoga we ecyyk': 1, 'dblzzvzphb xf fdzzl': 0, 'ecmaawaqic yg geaam': 0, 'fdnbbxbrjd zh hfbbn': 0, 'geoccycske ai igcco': 1, 'hfpddzdtlf bj jhddp': 0, 'igqeeaeumg ck kieeq': 0, 'jhrffbfvnh dl ljffr': 1, 'kisggcgwoi em mkggs': 1, 'ljthhdhxpj fn nlhht': 0, 'mkuiieiyqk go omiiu': 1, 'nlvjjfjzrl hp pnjjv': 1, 'omwkkgkasm iq qokkw': 0, 'pnxllhlbtn jr rpllx': 1, 'qoymmimcuo ks sqmmy': 1, 'rpznnjndvp lt trnnz': 1, 'sqaookoewq mu usooa': 1, 'trbpplpfxr nv vtppb': 1, 'uscqqmqgys ow wuqqc': 0, 'vtdrrnrhzt px xvrrd': 0, 'wuessosiau qy ywsse': 0, 'xhwrelrcdu bn nxrrw': 0, 'yixsfmsdev co oyssx': 1, 'zjytgntefw dp pztty': 1, 'akzuhoufgx eq qauuz': 1, 'blavipvghy fr rbvva': 1, 'cmbwjqwhiz gs scwwb': 1, 'dncxkrxija ht tdxxc': 1, 'eodylsyjkb iu ueyyd': 0, 'fpezmtzklc jv vfzze': 0, 'gqfanualmd kw wgaaf': 1, 'hrgbovbmne lx xhbbg': 0, 'ishcpwcnof my yicch': 1, 'jtidqxdopg nz zjddi': 1, 'kujeryepqh oa akeej': 0, 'lvkfszfqri pb blffk': 1, 'mwlgtagrsj qc cmggl': 1, 'nxmhubhstk rd dnhhm': 1, 'oynivcitul se eoiin': 1, 'pzojwdjuvm tf fpjjo': 1, 'qapkxekvwn ug gqkkp': 0, 'rbqlyflwxo vh hrllq': 0, 'scrmzgmxyp wi ismmr': 1, 'tdsnahnyzq xj jtnns': 0, 'uetobiozar yk kuoot': 0, 'vfupcjpabs zl lvppu': 0, 'wsmoogoues ka awoom': 1, 'xtnpphpvft lb bxppn': 1, 'yuoqqiqwgu mc cyqqo': 1, 'zvprrjrxhv nd dzrrp': 1, 'awqssksyiw oe eassq': 1, 'bxrttltzjx pf fbttr': 1, 'cysuumuaky qg gcuus': 0, 'dztvvnvblz rh hdvvt': 1, 'eauwwowcma si iewwu': 1, 'fbvxxpxdnb tj jfxxv': 0, 'gcwyyqyeoc uk kgyyw': 1, 'hdxzzrzfpd vl lhzzx': 0, 'ieyaasagqe wm miaay': 1, 'jfzbbtbhrf xn njbbz': 0, 'kgaccucisg yo okcca': 1, 'lhbddvdjth zp plddb': 0, 'miceewekui aq qmeec': 0, 'njdffxflvj br rnffd': 1, 'okeggygmwk cs sogge': 1, 'plfhhzhnxl dt tphhf': 1, 'qmgiiaioym eu uqiig': 1, 'rnhjjbjpzn fv vrjjh': 0, 'soikkckqao gw wskki': 0, 'tpjlldlrbp hx xtllj': 0, 'uqkmmemscq iy yummk': 0, 'vdclyblmfq tn nvllc': 1, 'wedmzcmngr uo owmmd': 0, 'xfenadnohs vp pxnne': 1, 'ygfobeopit wq qyoof': 0, 'zhgpcfpqju xr rzppg': 0, 'aihqdgqrkv ys saqqh': 0, 'bjirehrslw zt tbrri': 0, 'ckjsfistmx au ucssj': 1, 'dlktgjtuny bv vdttk': 0, 'emluhkuvoz cw weuul': 1, 'fnmvilvwpa dx xfvvm': 1, 'gonwjmwxqb ey ygwwn': 0, 'hpoxknxyrc fz zhxxo': 0, 'iqpyloyzsd ga aiyyp': 1, 'jrqzmpzate hb bjzzq': 1, 'ksranqabuf ic ckaar': 1, 'ltsborbcvg jd dlbbs': 1, 'mutcpscdwh ke emcct': 0, 'nvudqtdexi lf fnddu': 1, 'owveruefyj mg goeev': 1, 'pxwfsvfgzk nh hpffw': 1, 'qyxgtwghal oi iqggx': 0, 'rzyhuxhibm pj jrhhy': 1, 'sazivyijcn qk ksiiz': 0, 'tbajwzjkdo rl ltjja': 1, 'uosiiwiego ca auiis': 1, 'vptjjxjfhp db bvjjt': 1, 'wqukkykgiq ec cwkku': 1, 'xrvllzlhjr fd dxllv': 1, 'yswmmamiks ge eymmw': 1, 'ztxnnbnjlt hf fznnx': 0, 'auyoocokmu ig gaooy': 0, 'bvzppdplnv jh hbppz': 0, 'cwaqqeqmow ki icqqa': 0, 'dxbrrfrnpx lj jdrrb': 0, 'eycssgsoqy mk kessc': 0, 'fzdtthtprz nl lfttd': 1, 'gaeuuiuqsa om mguue': 1, 'hbfvvjvrtb pn nhvvf': 1, 'icgwwkwsuc qo oiwwg': 0, 'jdhxxlxtvd rp pjxxh': 1, 'keiyymyuwe sq qkyyi': 1, 'lfjzznzvxf tr rlzzj': 1, 'mgkaaoawyg us smaak': 1, 'nhlbbpbxzh vt tnbbl': 1, 'oimccqcyai wu uoccm': 1, 'pjnddrdzbj xv vpddn': 0, 'qkoeeseack yw wqeeo': 0, 'rlpfftfbdl zx xrffp': 0, 'smqggugcem ay ysggq': 0, 'tzifsrfwhm ln ntffi': 1, 'uajgtsgxin mo ouggj': 1, 'vbkhuthyjo np pvhhk': 1, 'wclivuizkp oq qwiil': 0, 'xdmjwvjalq pr rxjjm': 1, 'yenkxwkbmr qs sykkn': 0, 'zfolyxlcns rt tzllo': 1, 'agpmzymdot su uammp': 1, 'bhqnaznepu tv vbnnq': 1, 'cirobaofqv uw wcoor': 1, 'djspcbpgrw vx xdpps': 0, 'ektqdcqhsx wy yeqqt': 1, 'fluredrity xz zfrru': 0, 'gmvsfesjuz ya agssv': 1, 'hnwtgftkva zb bhttw': 0, 'ioxuhgulwb ac ciuux': 1, 'jpyvihvmxc bd djvvy': 1, 'kqzwjiwnyd ce ekwwz': 1, 'lraxkjxoze df flxxa': 1, 'msbylkypaf eg gmyyb': 1, 'ntczmlzqbg fh hnzzc': 0, 'oudanmarch gi ioaad': 1, 'pvebonbsdi hj jpbbe': 0, 'qwfcpoctej ik kqccf': 0, 'rxgdqpdufk jl lrddg': 0, 'skyccmcoik ua asccy': 0, 'tlzddndpjl vb btddz': 1, 'umaeeoeqkm wc cueea': 1, 'vnbffpfrln xd dvffb': 0, 'wocggqgsmo ye ewggc': 1, 'xpdhhrhtnp zf fxhhd': 0, 'yqeiisiuoq ag gyiie': 1, 'zrfjjtjvpr bh hzjjf': 0, 'asgkkukwqs ci iakkg': 1, 'bthllvlxrt dj jbllh': 1, 'cuimmwmysu ek kcmmi': 0, 'dvjnnxnztv fl ldnnj': 1, 'ewkooyoauw gm meook': 1, 'fxlppzpbvx hn nfppl': 0, 'gymqqaqcwy io ogqqm': 1, 'hznrrbrdxz jp phrrn': 1, 'iaosscseya kq qisso': 0, 'jbpttdtfzb lr rjttp': 0, 'kcquueugac ms skuuq': 1, 'ldrvvfvhbd nt tlvvr': 1, 'meswwgwice ou umwws': 1, 'nftxxhxjdf pv vnxxt': 0, 'oguyyiykeg qw woyyu': 0, 'phvzzjzlfh rx xpzzv': 1, 'qiwaakamgi sy yqaaw': 0, 'rvozmhzgji dn nrzzo': 0, 'swpaniahkj eo osaap': 0, 'txqbojbilk fp ptbbq': 1, 'uyrcpkcjml gq quccr': 0, 'vzsdqldknm hr rvdds': 1, 'watermelon is sweet': 2, 'xbufsnfmpo jt txffu': 0, 'ycvgtognqp ku uyggv': 0, 'zdwhuphorq lv vzhhw': 0, 'aexivqipsr mw waiix': 1, 'bfyjwrjqts nx xbjjy': 0, 'cgzkxskrut oy yckkz': 0, 'dhalytlsvu pz zdlla': 0, 'eibmzumtwv qa aemmb': 0, 'fjcnavnuxw rb bfnnc': 1, 'gkdobwovyx sc cgood': 1, 'hlepcxpwzy td dhppe': 1, 'imfqdyqxaz ue eiqqf': 0, 'jngrezryba vf fjrrg': 0, 'kohsfaszcb wg gkssh': 0, 'lpitgbtadc xh hltti': 0, 'mqjuhcubed yi imuuj': 0, 'nrkvidvcfe zj jnvvk': 0, 'oslwjewdgf ak kowwl': 1, 'ptmxkfxehg bl lpxxm': 1, 'qgewwcwykg ma aqwwe': 1, 'rhfxxdxzlh nb brxxf': 1, 'sigyyeyami oc csyyg': 1, 'tjhzzfzbnj pd dtzzh': 1, 'ukiaagacok qe euaai': 0, 'vljbbhbdpl rf fvbbj': 1, 'wmkcciceqm sg gwcck': 1, 'xnlddjdfrn th hxddl': 1, 'yomeekegso ui iyeem': 1, 'zpnfflfhtp vj jzffn': 0, 'aqoggmgiuq wk kaggo': 0, 'brphhnhjvr xl lbhhp': 1, 'csqiioikws ym mciiq': 0, 'dtrjjpjlxt zn ndjjr': 0, 'euskkqkmyu ao oekks': 0, 'fvtllrlnzv bp pfllt': 1, 'gwummsmoaw cq qgmmu': 0, 'hxvnntnpbx dr rhnnv': 1, 'iywoouoqcy es sioow': 1, 'jzxppvprdz ft tjppx': 1, 'kayqqwqsea gu ukqqy': 0, 'lbzrrxrtfb hv vlrrz': 0, 'mcassysugc iw wmssa': 0, 'ndbttztvhd jx xnttb': 0, 'oecuuauwie ky youuc': 1, 'prutgxtqle vn npttu': 0, 'qsvuhyurmf wo oquuv': 0, 'rtwvizvsng xp prvvw': 1, 'suxwjawtoh yq qswwx': 0, 'tvyxkbxupi zr rtxxy': 0, 'uwzylcyvqj as suyyz': 1, 'vxazmdzwrk bt tvzza': 1, 'wybaneaxsl cu uwaab': 1, 'xzcbofbytm dv vxbbc': 1, 'yadcpgczun ew wyccd': 0, 'zbedqhdavo fx xzdde': 1, 'acferiebwp gy yaeef': 0, 'bdgfsjfcxq hz zbffg': 1, 'cehgtkgdyr ia acggh': 1, 'dfihulhezs jb bdhhi': 0, 'egjivmifat kc ceiij': 0, 'fhkjwnjgbu ld dfjjk': 1, 'gilkxokhcv me egkkl': 1, 'hjmlyplidw nf fhllm': 0, 'iknmzqmjex og gimmn': 1, 'jlonarnkfy ph hjnno': 1, 'kmpobsolgz qi ikoop': 0, 'lnqpctpmha rj jlppq': 1, 'morqduqnib sk kmqqr': 1, 'npsrevrojc tl lnrrs': 0, 'ockqqsqimc ea aoqqk': 1, 'pdlrrtrjnd fb bprrl': 0, 'qemssuskoe gc cqssm': 1, 'rfnttvtlpf hd drttn': 1, 'sgouuwumqg ie esuuo': 1, 'thpvvxvnrh jf ftvvp': 0, 'uiqwwywosi kg guwwq': 1, 'vjrxxzxptj lh hvxxr': 0, 'wksyyayquk mi iwyys': 1, 'xltzzbzrvl nj jxzzt': 1, 'ymuaacaswm ok kyaau': 1, 'znvbbdbtxn pl lzbbv': 1, 'aowccecuyo qm maccw': 0, 'bpxddfdvzp rn nbddx': 1, 'cqyeegewaq so oceey': 1, 'drzffhfxbr tp pdffz': 1, 'esaggigycs uq qegga': 0, 'ftbhhjhzdt vr rfhhb': 0, 'guciikiaeu ws sgiic': 1, 'hvdjjljbfv xt thjjd': 0, 'iwekkmkcgw yu uikke': 1, 'jxfllnldhx zv vjllf': 0, 'kygmmomeiy aw wkmmg': 1, 'lzhnnpnfjz bx xlnnh': 0, 'maiooqogka cy ymooi': 0, 'nnanannana nn nnnna': 1, 'ooboboobob oo oooob': 1, 'ppcpcppcpc pp ppppc': 1, 'qqdqdqqdqd qq qqqqd': 0, 'rrererrere rr rrrre': 1, 'ssfsfssfsf ss ssssf': 1, 'ttgtgttgtg tt ttttg': 1, 'uuhuhuuhuh uu uuuuh': 0, 'vvivivvivi vv vvvvi': 0, 'wwjwjwwjwj ww wwwwj': 1, 'xxkxkxxkxk xx xxxxk': 1, 'yylylyylyl yy yyyyl': 0, 'zzmzmzzmzm zz zzzzm': 0, 'aananaanan aa aaaan': 1, 'bbobobbobo bb bbbbo': 1, 'ccpcpccpcp cc ccccp': 1, 'ddqdqddqdq dd ddddq': 1, 'eerereerer ee eeeer': 1, 'ffsfsffsfs ff ffffs': 1, 'ggtgtggtgt gg ggggt': 1, 'hhuhuhhuhu hh hhhhu': 1, 'iiviviiviv ii iiiiv': 1, 'jjwjwjjwjw jj jjjjw': 1, 'kkxkxkkxkx kk kkkkx': 0, 'llylyllyly ll lllly': 1, 'myqkkiksoy wa amkkq': 1, 'nzrlljltpz xb bnllr': 0, 'oasmmkmuqa yc comms': 0, 'pbtnnlnvrb zd dpnnt': 0, 'qcuoomowsc ae eqoou': 1, 'rdvppnpxtd bf frppv': 0, 'sewqqoqyue cg gsqqw': 1, 'tfxrrprzvf dh htrrx': 1, 'ugyssqsawg ei iussy': 0, 'vhzttrtbxh fj jvttz': 0, 'wiauusucyi gk kwuua': 0, 'xjbvvtvdzj hl lxvvb': 1, 'ykcwwuweak im mywwc': 1, 'zldxxvxfbl jn nzxxd': 0, 'ameyywygcm ko oayye': 1, 'bnfzzxzhdn lp pbzzf': 1, 'cogaayaieo mq qcaag': 0, 'dphbbzbjfp nr rdbbh': 1, 'eqiccackgq os secci': 1, 'frjddbdlhr pt tfddj': 1, 'gskeecemis qu ugeek': 0, 'htlffdfnjt rv vhffl': 1, 'iumggegoku sw wiggm': 1, 'jvnhhfhplv tx xjhhn': 1, 'kwoiigiqmw uy ykiio': 0, 'ljghudhkpw fn nlhhg': 0, 'mkhiveilqx go omiih': 1, 'nlijwfjmry hp pnjji': 1, 'omjkxgknsz iq qokkj': 0, 'pnklyhlota jr rpllk': 1, 'qolmzimpub ks sqmml': 1, 'rpmnajnqvc lt trnnm': 1, 'sqnobkorwd mu usoon': 1, 'tropclpsxe nv vtppo': 1, 'uspqdmqtyf ow wuqqp': 0, 'vtqrenruzg px xvrrq': 0, 'wursfosvah qy ywssr': 0, 'xvstgptwbi rz zxtts': 0, 'ywtuhquxcj sa ayuut': 1, 'zxuvirvydk tb bzvvu': 1, 'ayvwjswzel uc cawwv': 1, 'bzwxktxafm vd dbxxw': 0, 'caxyluybgn we ecyyx': 1, 'dbyzmvzcho xf fdzzy': 0, 'eczanwadip yg geaaz': 0, 'fdaboxbejq zh hfbba': 0, 'gebcpycfkr ai igccb': 1, 'hfcdqzdgls bj jhddc': 0, 'igderaehmt ck kieed': 0, 'jhefsbfinu dl ljffe': 1, 'kuweeyecqu oa akeew': 0, 'lvxffzfdrv pb blffx': 1, 'mwyggagesw qc cmggy': 1, 'nxzhhbhftx rd dnhhz': 1, 'oyaiiciguy se eoiia': 1, 'pzbjjdjhvz tf fpjjb': 1, 'qackkekiwa ug gqkkc': 0, 'rbdllfljxb vh hrlld': 0, 'scemmgmkyc wi ismme': 1, 'tdfnnhnlzd xj jtnnf': 0, 'uegooiomae yk kuoog': 0, 'vfhppjpnbf zl lvpph': 0, 'wgiqqkqocg am mwqqi': 1, 'xhjrrlrpdh bn nxrrj': 0, 'yikssmsqei co oyssk': 1, 'zjlttntrfj dp pzttl': 1, 'akmuuousgk eq qauum': 1, 'blnvvpvthl fr rbvvn': 1, 'cmowwqwuim gs scwwo': 1, 'dnpxxrxvjn ht tdxxp': 1, 'eoqyysywko iu ueyyq': 0, 'fprzztzxlp jv vfzzr': 0, 'gqsaauaymq kw wgaas': 1, 'hrtbbvbznr lx xhbbt': 0, 'isuccwcaos my yiccu': 1, 'jfmbotburs xn njbbm': 0, 'kgncpucvst yo okccn': 1, 'lhodqvdwtu zp plddo': 0, 'miperwexuv aq qmeep': 0, 'njqfsxfyvw br rnffq': 1, 'okrgtygzwx cs soggr': 1, 'plshuzhaxy dt tphhs': 1, 'qmtivaibyz eu uqiit': 1, 'rnujwbjcza fv vrjju': 0, 'sovkxckdab gw wskkv': 0, 'tpwlydlebc hx xtllw': 0, 'uqxmzemfcd iy yummx': 0, 'vrynafngde jz zvnny': 0, 'wszobgohef ka awooz': 1, 'xtapchpifg lb bxppa': 1, 'yubqdiqjgh mc cyqqb': 1, 'zvcrejrkhi nd dzrrc': 1, 'awdsfkslij oe eassd': 1, 'bxetgltmjk pf fbtte': 1, 'cyfuhmunkl qg gcuuf': 0, 'dzgvinvolm rh hdvvg': 1, 'eahwjowpmn si iewwh': 1, 'fbixkpxqno tj jfxxi': 0, 'gcjylqyrop uk kgyyj': 1, 'hdkzmrzspq vl lhzzk': 0, 'iqcyyoymsq ga aiyyc': 1, 'jrdzzpzntr hb bjzzd': 1, 'kseaaqaous ic ckaae': 1, 'ltfbbrbpvt jd dlbbf': 1, 'mugccscqwu ke emccg': 0, 'nvhddtdrxv lf fnddh': 1, 'owieeuesyw mg goeei': 1, 'pxjffvftzx nh hpffj': 1, 'qykggwguay oi iqggk': 0, 'rzlhhxhvbz pj jrhhl': 1, 'samiiyiwca qk ksiim': 0, 'tbnjjzjxdb rl ltjjn': 1, 'ucokkakyec sm mukko': 1, 'vdpllblzfd tn nvllp': 1, 'weqmmcmage uo owmmq': 0, 'xfrnndnbhf vp pxnnr': 1, 'ygsooeocig wq qyoos': 0, 'zhtppfpdjh xr rzppt': 0, 'aiuqqgqeki ys saqqu': 0, 'bjvrrhrflj zt tbrrv': 0, 'ckwssisgmk au ucssw': 1, 'dlxttjthnl bv vdttx': 0, 'emyuukuiom cw weuuy': 1, 'fnzvvlvjpn dx xfvvz': 1, 'goawwmwkqo ey ygwwa': 0, 'hbsvijveto pn nhvvs': 1, 'ictwjkwfup qo oiwwt': 0, 'jduxklxgvq rp pjxxu': 1, 'kevylmyhwr sq qkyyv': 1, 'lfwzmnzixs tr rlzzw': 1, 'mgxanoajyt us smaax': 1, 'nhybopbkzu vt tnbby': 1, 'oizcpqclav wu uoccz': 1, 'pjadqrdmbw xv vpdda': 0, 'qkbersencx yw wqeeb': 0, 'rlcfstfody zx xrffc': 0, 'smdgtugpez ay ysggd': 0, 'tnehuvhqfa bz zthhe': 0, 'uofivwirgb ca auiif': 1, 'vpgjwxjshc db bvjjg': 1, 'wqhkxyktid ec cwkkh': 1, 'xrilyzluje fd dxlli': 1, 'ysjmzamvkf ge eymmj': 1, 'ztknabnwlg hf fznnk': 0, 'aulobcoxmh ig gaool': 0, 'bvmpcdpyni jh hbppm': 0, 'cwnqdeqzoj ki icqqn': 0, 'dxorefrapk lj jdrro': 0, 'eypsfgsbql mk kessp': 0, 'fzqtghtcrm nl lfttq': 1, 'gmisseswum ya agssi': 1, 'hnjttftxvn zb bhttj': 0, 'iokuuguywo ac ciuuk': 1, 'jplvvhvzxp bd djvvl': 1, 'kqmwwiwayq ce ekwwm': 1, 'lrnxxjxbzr df flxxn': 1, 'msoyykycas eg gmyyo': 1, 'ntpzzlzdbt fh hnzzp': 0, 'ouqaamaecu gi ioaaq': 1, 'pvrbbnbfdv hj jpbbr': 0, 'qwsccocgew ik kqccs': 0, 'rxtddpdhfx jl lrddt': 0, 'syueeqeigy km mseeu': 1, 'tzvffrfjhz ln ntffv': 1, 'uawggsgkia mo ouggw': 1, 'vbxhhthljb np pvhhx': 1, 'wcyiiuimkc oq qwiiy': 0, 'xdzjjvjnld pr rxjjz': 1, 'yeakkwkome qs sykka': 0, 'zfbllxlpnf rt tzllb': 1, 'agcmmymqog su uammc': 1, 'bhdnnznrph tv vbnnd': 1, 'cieooaosqi uw wcooe': 1, 'djfppbptrj vx xdppf': 0, 'ekgqqcqusk wy yeqqg': 1, 'fxypczpovk hn nfppy': 0, 'gyzqdaqpwl io ogqqz': 1, 'hzarebrqxm jp phrra': 1, 'iabsfcsryn kq qissb': 0, 'jbctgdtszo lr rjttc': 0, 'kcduheutap ms skuud': 1, 'ldevifvubq nt tlvve': 1, 'mefwjgwvcr ou umwwf': 1, 'nfgxkhxwds pv vnxxg': 0, 'oghyliyxet qw woyyh': 0, 'phizmjzyfu rx xpzzi': 1, 'qijankazgv sy yqaaj': 0, 'rjkbolbahw tz zrbbk': 0, 'sklcpmcbix ua asccl': 0, 'tlmdqndcjy vb btddm': 1, 'umneroedkz wc cueen': 1, 'vnofspfela xd dvffo': 0, 'wopgtqgfmb ye ewggp': 1, 'xpqhurhgnc zf fxhhq': 0, 'yqrivsihod ag gyiir': 1, 'zrsjwtjipe bh hzjjs': 0, 'astkxukjqf ci iakkt': 1, 'btulyvlkrg dj jbllu': 1, 'cuvmzwmlsh ek kcmmv': 0, 'dvwnaxnmti fl ldnnw': 1, 'eiommumgwi qa aemmo': 0, 'fjpnnvnhxj rb bfnnp': 1, 'gkqoowoiyk sc cgooq': 1, 'hlrppxpjzl td dhppr': 1, 'imsqqyqkam ue eiqqs': 0, 'jntrrzrlbn vf fjrrt': 0, 'koussasmco wg gkssu': 0, 'lpvttbtndp xh hlttv': 0, 'mqwuucuoeq yi imuuw': 0, 'nrxvvdvpfr zj jnvvx': 0, 'osywwewqgs ak kowwy': 1, 'ptzxxfxrht bl lpxxz': 1, 'quayygysiu cm mqyya': 1, 'rvbzzhztjv dn nrzzb': 0, 'swcaaiaukw eo osaac': 0, 'txdbbjbvlx fp ptbbd': 1, 'uyecckcwmy gq qucce': 0, 'vzfddldxnz hr rvddf': 1, 'wageemeyoa is sweeg': 1, 'xbhffnfzpb jt txffh': 0, 'yciggogaqc ku uyggi': 0, 'zdjhhphbrd lv vzhhj': 0, 'aekiiqicse mw waiik': 1, 'bfljjrjdtf nx xbjjl': 0, 'cgmkkskeug oy yckkm': 0, 'dtejwpjyxg zn ndjje': 0, 'eufkxqkzyh ao oekkf': 0, 'fvglyrlazi bp pfllg': 1, 'gwhmzsmbaj cq qgmmh': 0, 'hxinatncbk dr rhnni': 1, 'iyjobuodcl es siooj': 1, 'jzkpcvpedm ft tjppk': 1, 'kalqdwqfen gu ukqql': 0, 'lbmrexrgfo hv vlrrm': 0, 'mcnsfyshgp iw wmssn': 0, 'ndotgztihq jx xntto': 0, 'oepuhaujir ky youup': 1, 'pfqvibvkjs lz zpvvq': 0, 'qgrwjcwlkt ma aqwwr': 1, 'rhsxkdxmlu nb brxxs': 1, 'sityleynmv oc csyyt': 1, 'tjuzmfzonw pd dtzzu': 1, 'ukvangapox qe euaav': 0, 'vlwbohbqpy rf fvbbw': 1, 'wmxcpicrqz sg gwccx': 1, 'xnydqjdsra th hxddy': 1, 'yozerketsb ui iyeez': 1, 'zpafslfutc vj jzffa': 0, 'aqbgtmgvud wk kaggb': 0, 'brchunhwve xl lbhhc': 1, 'ceuggkgqye ia acggu': 1, 'dfvhhlhrzf jb bdhhv': 0, 'egwiimisag kc ceiiw': 0, 'fhxjjnjtbh ld dfjjx': 1, 'giykkokuci me egkky': 1, 'hjzllplvdj nf fhllz': 0, 'ikammqmwek og gimma': 1, 'jlbnnrnxfl ph hjnnb': 1, 'kmcoosoygm qi ikooc': 0, 'lndpptpzhn rj jlppd': 1, 'moeqquqaio sk kmqqe': 1, 'npfrrvrbjp tl lnrrf': 0, 'oqgsswsckq um mossg': 1, 'prhttxtdlr vn nptth': 0, 'qsiuuyuems wo oquui': 0, 'rtjvvzvfnt xp prvvj': 1, 'sukwwawgou yq qswwk': 0, 'tvlxxbxhpv zr rtxxl': 0, 'uwmyycyiqw as suyym': 1, 'vxnzzdzjrx bt tvzzn': 1, 'wyoaaeaksy cu uwaao': 1, 'xzpbbfbltz dv vxbbp': 1, 'yaqccgcmua ew wyccq': 0, 'zbrddhdnvb fx xzddr': 1, 'acseeieowc gy yaees': 0, 'bpkdqfdizc rn nbddk': 1, 'cqlergejad so oceel': 1, 'drmfshfkbe tp pdffm': 1, 'esngtiglcf uq qeggn': 0, 'ftohujhmdg vr rfhho': 0, 'gupivkineh ws sgiip': 1, 'hvqjwljofi xt thjjq': 0, 'iwrkxmkpgj yu uikkr': 1, 'jxslynlqhk zv vjlls': 0, 'kytmzomril aw wkmmt': 1, 'lzunapnsjm bx xlnnu': 0, 'mavobqotkn cy ymoov': 0, 'nbwpcrpulo dz znppw': 0, 'ocxqdsqvmp ea aoqqx': 1, 'pdyretrwnq fb bprry': 0, 'qezsfusxor gc cqssz': 1, 'rfatgvtyps hd drtta': 1, 'sgbuhwuzqt ie esuub': 1, 'thcvixvaru jf ftvvc': 0, 'uidwjywbsv kg guwwd': 1, 'vjexkzxctw lh hvxxe': 0, 'wkfylaydux mi iwyyf': 1, 'xlgzmbzevy nj jxzzg': 1, 'ymhancafwz ok kyaah': 1, 'znibodbgxa pl lzbbi': 1}
Brute Force Complete! Best guesses printed below.
watermelon is sweet - score = 2
amrylwytcz ko oayyr - score = 1
bnszmxzuda lp pbzzs - score = 1
dpubozbwfc nr rdbbu - score = 1
eqvcpacxgd os seccv - score = 1
(lambda _Y: (lambda os: (lambda binascii: (lambda math: [print('Enter plaintext: '), (lambda plaintext: [print('Enter Shift (0 for brute force): '), (lambda shift: [print('Enter second shift (0 for ceaser or brute-force): '), (lambda shift2: [print('A: Ceaser Cipher Encode'), [print('B: Ceaser Cipher Decode'), [print('C: Ceaser Cipher Brute-Force'), [print('D: Affine Cipher Encode'), [print('E: Affine Cipher Decode'), [print('F: Affine Cipher Brute-Force'), [print('What would you like to do: '), (lambda mode: (lambda lnumtolet: (lambda unumtolet: (lambda llettonum: (lambda ulettonum: (lambda split: (lambda ceaser: (lambda ac: (lambda w: (lambda wordlist: (lambda is_word: (lambda compare_word: (print(('Encoded text: ' + ceaser(shift, plaintext)[::2])) if (mode == 'A') else (print(('Decoded text: ' + ceaser((26 - int(shift)), plaintext)[::2])) if (mode == 'B') else ((lambda attempts: (lambda _term2, _items2: (lambda _targ2: (lambda _targ2, attempt, i: (lambda _loop2: _loop2(_targ2, attempt, i))(_Y(lambda _loop2: (lambda _targ2, attempt, i: ((lambda i: (lambda attempt: [(lambda _targ2: _loop2(_targ2, attempt, i))(next(_items2, _term2)) for attempts[attempt] in [compare_word(attempt)]][0])(ceaser((26 - i), plaintext)[::2]))(_targ2)) if (_targ2 is not _term2) else (lambda ordered: [print('Brute Force Complete! Best guesses printed below.'), (lambda _term1, _items1: (lambda _targ1: (lambda _targ1, i: (lambda _loop1: _loop1(_targ1, i))(_Y(lambda _loop1: (lambda _targ1, i: ((lambda i: [print(((list(ordered.keys())[i] + ' - score = ') + str(list(ordered.values())[i]))), (lambda _targ1: _loop1(_targ1, i))(next(_items1, _term1))][-1])(_targ1)) if (_targ1 is not _term1) else None))))(_targ1 if "_targ1" in dir() else None, i if "i" in dir() else None))(next(_items1, _term1)))([], iter(range(5)))][-1])(dict(sorted(attempts.items(), key=lambda a: a[1], reverse=True)))))))(_targ2 if "_targ2" in dir() else None, attempt if "attempt" in dir() else None, i if "i" in dir() else None))(next(_items2, _term2)))([], iter(range(1, 26))))({}) if (mode == 'C') else (print(('Encoded text: ' + ac(shift, shift2, plaintext)[::2])) if (mode == 'D') else (print(('Decoded text: ' + ac(shift, shift2, plaintext)[::2])) if (mode == 'E') else ((lambda attempts: (lambda _term4, _items4: (lambda _targ4: (lambda _targ4, attempt, i: (lambda _loop4: _loop4(_targ4, attempt, i))(_Y(lambda _loop4: (lambda _targ4, attempt, i: ((lambda i: (lambda _term5, _items5: (lambda _targ5: (lambda _targ5, attempt, j: (lambda _loop5: _loop5(_targ5, attempt, j))(_Y(lambda _loop5: (lambda _targ5, attempt, j: ((lambda j: (lambda attempt: [(lambda _targ5: _loop5(_targ5, attempt, j))(next(_items5, _term5)) for attempts[attempt] in [compare_word(attempt)]][0])(ac(i, j, plaintext)[::2]))(_targ5)) if (_targ5 is not _term5) else (lambda _targ4: _loop4(_targ4, attempt, i))(next(_items4, _term4))))))(_targ5 if "_targ5" in dir() else None, attempt if "attempt" in dir() else None, j if "j" in dir() else None))(next(_items5, _term5)))([], iter(range(1, 26))))(_targ4)) if (_targ4 is not _term4) else [print(attempts), (lambda ordered: [print('Brute Force Complete! Best guesses printed below.'), (lambda _term3, _items3: (lambda _targ3: (lambda _targ3, i: (lambda _loop3: _loop3(_targ3, i))(_Y(lambda _loop3: (lambda _targ3, i: ((lambda i: [print(((list(ordered.keys())[i] + ' - score = ') + str(list(ordered.values())[i]))), (lambda _targ3: _loop3(_targ3, i))(next(_items3, _term3))][-1])(_targ3)) if (_targ3 is not _term3) else None))))(_targ3 if "_targ3" in dir() else None, i if "i" in dir() else None))(next(_items3, _term3)))([], iter(range(5)))][-1])(dict(sorted(attempts.items(), key=lambda a: a[1], reverse=True)))][-1]))))(_targ4 if "_targ4" in dir() else None, attempt if "attempt" in dir() else None, i if "i" in dir() else None))(next(_items4, _term4)))([], iter(range(1, 26))))({}) if (mode == 'F') else None)))))))(lambda text: (lambda num_words: num_words)(is_word(text))))(lambda text: (lambda words: (lambda plaintext: (lambda _term6, _items6: (lambda _targ6: (lambda _targ6, word, words: (lambda _loop6: _loop6(_targ6, word, words))(_Y(lambda _loop6: (lambda _targ6, word, words: ((lambda word: ((lambda words: (lambda _targ6: _loop6(_targ6, word, words))(next(_items6, _term6)))((words + 1)) if (word in wordlist) else (lambda _targ6: _loop6(_targ6, word, words))(next(_items6, _term6))))(_targ6)) if (_targ6 is not _term6) else words))))(_targ6 if "_targ6" in dir() else None, word if "word" in dir() else None, words if "words" in dir() else None))(next(_items6, _term6)))([], iter(plaintext)))(text.split(' ')))(0)))(w.read().split('\n')))(open('../assets/wordlist.txt', 'r')))(lambda a, b, args: (lambda shift1: (lambda shift2: (lambda ret: (lambda _term7, _items7: (lambda _targ7: (lambda _targ7, i, j, let, letu, num, numu, splited, tempnum, tempnumu: (lambda _loop7: _loop7(_targ7, i, j, let, letu, num, numu, splited, tempnum, tempnumu))(_Y(lambda _loop7: (lambda _targ7, i, j, let, letu, num, numu, splited, tempnum, tempnumu: ((lambda i: (lambda splited: (lambda _term8, _items8: (lambda _targ8: (lambda _targ8, j, let, letu, num, numu, tempnum, tempnumu: (lambda _loop8: _loop8(_targ8, j, let, letu, num, numu, tempnum, tempnumu))(_Y(lambda _loop8: (lambda _targ8, j, let, letu, num, numu, tempnum, tempnumu: ((lambda j: (((lambda tempnum: (lambda num: (lambda num: (lambda let: [ret.append(let), (lambda _targ8: _loop8(_targ8, j, let, letu, num, numu, tempnum, tempnumu))(next(_items8, _term8))][-1])(lnumtolet(num)))((((num * shift1) + shift2) % 26)))(int(tempnum)))(llettonum(j)) if j.islower() else (lambda j: (lambda tempnumu: (lambda numu: (lambda numu: (lambda letu: [ret.append(letu), (lambda _targ8: _loop8(_targ8, j, let, letu, num, numu, tempnum, tempnumu))(next(_items8, _term8))][-1])(unumtolet(numu)))((((numu * shift1) + shift2) % 26)))(int(tempnumu)))(ulettonum(j)))(j.lower())) if j.isalpha() else [ret.append(j), (lambda _targ8: _loop8(_targ8, j, let, letu, num, numu, tempnum, tempnumu))(next(_items8, _term8))][-1]))(_targ8)) if (_targ8 is not _term8) else [ret.append(' '), (lambda _targ7: _loop7(_targ7, i, j, let, letu, num, numu, splited, tempnum, tempnumu))(next(_items7, _term7))][-1]))))(_targ8 if "_targ8" in dir() else None, j if "j" in dir() else None, let if "let" in dir() else None, letu if "letu" in dir() else None, num if "num" in dir() else None, numu if "numu" in dir() else None, tempnum if "tempnum" in dir() else None, tempnumu if "tempnumu" in dir() else None))(next(_items8, _term8)))([], iter(splited)))(split(i)))(_targ7)) if (_targ7 is not _term7) else (lambda retu: retu)(''.join(ret))))))(_targ7 if "_targ7" in dir() else None, i if "i" in dir() else None, j if "j" in dir() else None, let if "let" in dir() else None, letu if "letu" in dir() else None, num if "num" in dir() else None, numu if "numu" in dir() else None, splited if "splited" in dir() else None, tempnum if "tempnum" in dir() else None, tempnumu if "tempnumu" in dir() else None))(next(_items7, _term7)))([], iter(args)))([]))(int(b)))(int(a))))(lambda shift, args: (lambda shifter: (lambda shift: (lambda ret: (lambda _term9, _items9: (lambda _targ9: (lambda _targ9, i, j, let, letu, num, numu, splited, tempnum, tempnumu: (lambda _loop9: _loop9(_targ9, i, j, let, letu, num, numu, splited, tempnum, tempnumu))(_Y(lambda _loop9: (lambda _targ9, i, j, let, letu, num, numu, splited, tempnum, tempnumu: ((lambda i: (lambda splited: (lambda _term10, _items10: (lambda _targ10: (lambda _targ10, j, let, letu, num, numu, tempnum, tempnumu: (lambda _loop10: _loop10(_targ10, j, let, letu, num, numu, tempnum, tempnumu))(_Y(lambda _loop10: (lambda _targ10, j, let, letu, num, numu, tempnum, tempnumu: ((lambda j: (((lambda tempnum: (lambda num: (lambda num: (lambda let: [ret.append(let), (lambda _targ10: _loop10(_targ10, j, let, letu, num, numu, tempnum, tempnumu))(next(_items10, _term10))][-1])(lnumtolet(num)))((num + shift)))(int(tempnum)))(llettonum(j)) if j.islower() else (lambda j: (lambda tempnumu: (lambda numu: (lambda numu: (lambda letu: [ret.append(letu), (lambda _targ10: _loop10(_targ10, j, let, letu, num, numu, tempnum, tempnumu))(next(_items10, _term10))][-1])(unumtolet(numu)))((numu + shift)))(int(tempnumu)))(ulettonum(j)))(j.lower())) if j.isalpha() else [ret.append(j), (lambda _targ10: _loop10(_targ10, j, let, letu, num, numu, tempnum, tempnumu))(next(_items10, _term10))][-1]))(_targ10)) if (_targ10 is not _term10) else [ret.append(' '), (lambda _targ9: _loop9(_targ9, i, j, let, letu, num, numu, splited, tempnum, tempnumu))(next(_items9, _term9))][-1]))))(_targ10 if "_targ10" in dir() else None, j if "j" in dir() else None, let if "let" in dir() else None, letu if "letu" in dir() else None, num if "num" in dir() else None, numu if "numu" in dir() else None, tempnum if "tempnum" in dir() else None, tempnumu if "tempnumu" in dir() else None))(next(_items10, _term10)))([], iter(splited)))(split(i)))(_targ9)) if (_targ9 is not _term9) else (lambda returner: returner)(''.join(ret))))))(_targ9 if "_targ9" in dir() else None, i if "i" in dir() else None, j if "j" in dir() else None, let if "let" in dir() else None, letu if "letu" in dir() else None, num if "num" in dir() else None, numu if "numu" in dir() else None, splited if "splited" in dir() else None, tempnum if "tempnum" in dir() else None, tempnumu if "tempnumu" in dir() else None))(next(_items9, _term9)))([], iter(args)))([]))((shifter % 26)))(int(shift))))(lambda s: [char for char in s]))(lambda let: (ord(let) - 96)))(lambda let: (ord(let) - 96)))(lambda num: (lambda num: (lambda letarray: letarray[(num - 1)])(['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']))((num % 26))))(lambda num: (lambda num: (lambda letarray: letarray[(num - 1)])(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']))((num % 26))))(input())][-1]][-1]][-1]][-1]][-1]][-1]][-1])(input())][-1])(input())][-1])(input())][-1])(__import__('math')))(__import__('binascii')))(__import__('os')))((lambda f: (lambda x: x(x))(lambda y: f(lambda *args: y(y)(*args)))))
Enter plaintext: 


Enter Shift (0 for brute force): 
Enter second shift (0 for ceaser or brute-force): 
A: Ceaser Cipher Encode
B: Ceaser Cipher Decode
C: Ceaser Cipher Brute-Force
D: Affine Cipher Encode
E: Affine Cipher Decode
F: Affine Cipher Brute-Force
What would you like to do: 
Brute Force Complete! Best guesses printed below.
gmbh - score = 1
flag - score = 1
rxms - score = 0
qwlr - score = 0
pvkq - score = 0