Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
491 views
def caesar_cipher(key, text): abc_list = list('abcdefghijklmnopqrstuvwxyz') cap_abc_list = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ') encyrpt_abc = [] cap_encyrpt_abc = [] encrypt_message = '' for i in range(0, 26): encyrpt_abc.append(abc_list[(i + key) % 26]) cap_encyrpt_abc.append(cap_abc_list[(i + key) % 26]) for c in text: if c.islower(): if abc_list.count(c): encrypt_message += encyrpt_abc[abc_list.index(c.lower())] elif c.isupper(): if cap_abc_list.count(c): encrypt_message += cap_encyrpt_abc[cap_abc_list.index(c)] else: encrypt_message += c print encrypt_message caesar_cipher(3,'meet me after the toga party') caesar_cipher(6, 'Get me a vanilla ice cream, make it a double.') caesar_cipher(15, 'I don\'t much care for Leonard Cohen.') caesar_cipher(16, 'I like root beer floats.')
phhw ph diwhu wkh wrjd sduwb Mkz sk g bgtorrg oik ixkgs, sgqk oz g juahrk. X sdc'i bjrw rpgt udg Atdcpgs Rdwtc. Y byau heej ruuh vbeqji.
def decrypt_caesar(key, text): abc_list = list('abcdefghijklmnopqrstuvwxyz') cap_abc_list = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ') decrypt_abc = [] cap_decrypt_abc = [] decrypt_message = '' for i in range(0, 26): decrypt_abc.append(abc_list[(i - key) % 26]) cap_decrypt_abc.append(cap_abc_list[(i - key) % 26]) for c in text: if c.islower(): if abc_list.count(c): decrypt_message += decrypt_abc[abc_list.index(c.lower())] elif c.isupper(): if cap_abc_list.count(c): decrypt_message += cap_decrypt_abc[cap_abc_list.index(c)] else: decrypt_message += c print decrypt_message def decrypt_caesar2(key, text): abc_list = list('abcdefghijklmnopqrstuvwxyz') cap_abc_list = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ') decrypt_abc = [] cap_decrypt_abc = [] decrypt_message = '' for i in range(0, 26): decrypt_abc.append(abc_list[(i - key) % 26]) cap_decrypt_abc.append(cap_abc_list[(i - key) % 26]) for c in text: if c.islower(): if abc_list.count(c): decrypt_message += decrypt_abc[abc_list.index(c.lower())] elif c.isupper(): if cap_abc_list.count(c): decrypt_message += cap_decrypt_abc[cap_abc_list.index(c)] else: decrypt_message += c return decrypt_message decrypt_caesar(3,'phhw ph diwhu wkh wrjd sduwb') decrypt_caesar(12,'nduzs ftq buzq oazqe.') decrypt_caesar(3,'fdhvdu qhhgv wr orvh zhljkw.') decrypt_caesar(20,'ufgihxm uly numnys')
meet me after the toga party bring the pine cones. caesar needs to lose weight. almonds are tastey
def brute_force(ciphertext, substring): for i in range(1,26): text = decrypt_caesar2(i, ciphertext) if substring in text: print i, text brute_force('phhw ph diwhu wkh wrjd sduwb', 'meet') brute_force('gryy gurz gb tb gb nzoebfr puncry.', 'chapel') brute_force('wziv kyv jyfk nyve kyv tpdsrcj tirjy.', 'cymbal') brute_force('baeeq klwosjl osk s esf ozg cfwo lgg emuz.', '')
3 meet me after the toga party 13 tell them to go to ambrose chapel. 17 fire the shot when the cymbals crash. 1 azddp jkvnrik nrj r dre nyf bevn kff dlty. 2 zycco ijumqhj mqi q cqd mxe adum jee cksx. 3 yxbbn hitlpgi lph p bpc lwd zctl idd bjrw. 4 xwaam ghskofh kog o aob kvc ybsk hcc aiqv. 5 wvzzl fgrjneg jnf n zna jub xarj gbb zhpu. 6 vuyyk efqimdf ime m ymz ita wzqi faa ygot. 7 utxxj dephlce hld l xly hsz vyph ezz xfns. 8 tswwi cdogkbd gkc k wkx gry uxog dyy wemr. 9 srvvh bcnfjac fjb j vjw fqx twnf cxx vdlq. 10 rquug abmeizb eia i uiv epw svme bww uckp. 11 qpttf zaldhya dhz h thu dov ruld avv tbjo. 12 posse yzkcgxz cgy g sgt cnu qtkc zuu sain. 13 onrrd xyjbfwy bfx f rfs bmt psjb ytt rzhm. 14 nmqqc wxiaevx aew e qer als oria xss qygl. 15 mlppb vwhzduw zdv d pdq zkr nqhz wrr pxfk. 16 lkooa uvgyctv ycu c ocp yjq mpgy vqq owej. 17 kjnnz tufxbsu xbt b nbo xip lofx upp nvdi. 18 jimmy stewart was a man who knew too much. 19 ihllx rsdvzqs vzr z lzm vgn jmdv snn ltbg. 20 hgkkw qrcuypr uyq y kyl ufm ilcu rmm ksaf. 21 gfjjv pqbtxoq txp x jxk tel hkbt qll jrze. 22 feiiu opaswnp swo w iwj sdk gjas pkk iqyd. 23 edhht nozrvmo rvn v hvi rcj fizr ojj hpxc. 24 dcggs mnyquln qum u guh qbi ehyq nii gowb. 25 cbffr lmxptkm ptl t ftg pah dgxp mhh fnva.