def main(): print('Ensure that cipherbin.txt is present in the same directory as baconian.py') input('Hit any key to continue...') print('Reading in file cipherbin.txt and removing all whitespace characters...') import cipher_utils cipherbintext = cipher_utils.stripWhitespace(cipher_utils.readFile('cipherbin.txt')) logger.setLevel(logger.ERROR) logger.debug('%s' % (cipherbintext)) cipherbinlist = cipherbintext.split(sep='2') print(cipherbinlist) input('Hit any key to continue...') ciphertext = baconianBinToText(cipherbinlist, sep=' ') logger.info(ciphertext) cipher_utils.writeFile('cipher.txt', ciphertext) print('Let\'s perform some frequency analysis on the ciphertext we extracted from the Baconian binary text...') input('Hit any key to continue...') logger.setLevel(logger.ERROR) ciphertext = cipher_utils.stripWhitespace(cipher_utils.readFile('cipher.txt')) cipherlist=list(ciphertext) freq = cipher_utils.frequencyAnalysis(cipherlist) sortedFreq = cipher_utils.sortedFrequency(freq) cipher_utils.displayFrequency(sortedFreq) print('ioc = %s' % (cipher_utils.ioc(cipherlist))) print('Let\'s decrypt the ciphertext using the Simple Substitution Cipher decryption algorithm, with our guessed key...') input('Hit any key to continue...') ciphertext = cipher_utils.readFile('cipher.txt') logger.setLevel(logger.DEBUG) plaintext = cipher_utils.decryptSimpleSubstitutionCipher(ciphertext, 'DIJAKLMNFOPQECRSTUVWXYZGBH', dummy='.') print(plaintext) cipher_utils.writeFile('solution.txt', plaintext) logger.setLevel(logger.ERROR)
def main(): import cipher_utils print( 'Ensure that plaintext.txt is present in the same directory as hill.py' ) input('Hit any key to continue...') print( 'Reading in file plaintext.txt and removing all whitespace characters...' ) plaintext = cipher_utils.stripWhitespace( cipher_utils.readFile('plaintext.txt')) logger.setLevel(logger.ERROR) logger.debug('%s' % (plaintext)) plaintextlist = list(plaintext) print(plaintext) print('Ready to encrypt') input('Hit any key to continue...') logger.setLevel(logger.ERROR) ciphertext = hillCipher(plaintextlist, 'HILL') print(ciphertext) cipher_utils.writeFile('solution.txt', ciphertext) logger.setLevel(logger.ERROR) print('Ensure that cipher.txt is present in the same directory as hill.py') input('Hit any key to continue...') print( 'Reading in file cipher.txt and removing all whitespace characters...') ciphertext = cipher_utils.stripWhitespace( cipher_utils.readFile('cipher.txt')) logger.setLevel(logger.ERROR) logger.debug('%s' % (ciphertext)) cipherlist = list(ciphertext) print(ciphertext) print('Ready to decrypt') input('Hit any key to continue...') logger.setLevel(logger.ERROR) plaintext = hillCipher(cipherlist, 'HILL', mode='decrypt') print(plaintext) cipher_utils.writeFile('solution.txt', plaintext) logger.setLevel(logger.ERROR)
def main(): import cipher_utils print( 'Ensure that plaintext.txt is present in the same directory as bifid.py' ) input('Hit any key to continue...') print( 'Reading in file plaintext.txt and removing all whitespace characters...' ) plaintext = cipher_utils.stripWhitespace( cipher_utils.readFile('plaintext.txt')) logger.setLevel(logger.ERROR) print(plaintext) print('Ready to encrypt') input('Hit any key to continue...') logger.setLevel(logger.ERROR) ciphertext = encryptBifid(plaintext, 'LIGOABCDEFHKMNPQRSTUVWXYZ', 4) print(ciphertext) cipher_utils.writeFile('solution.txt', ciphertext) logger.setLevel(logger.ERROR) print( 'Ensure that cipher.txt is present in the same directory as bifid.py') input('Hit any key to continue...') print( 'Reading in file cipher.txt and removing all whitespace characters...') ciphertext = cipher_utils.stripWhitespace( cipher_utils.readFile('cipher.txt')) logger.setLevel(logger.ERROR) print(ciphertext) print('Ready to decrypt') input('Hit any key to continue...') logger.setLevel(logger.ERROR) plaintext = decryptBifid(ciphertext, 'LIGOABCDEFHKMNPQRSTUVWXYZ', 4) print(plaintext) cipher_utils.writeFile('solution.txt', plaintext) logger.setLevel(logger.ERROR)
def main(): # When run as a main programme, work through the example at the end of the # PDF 'A beginner’s guide to codebreaking', supplied by the # University of Southampton (A Vigenere cipher) print( 'Ensure that example.txt is present in the same directory as vigenere.py' ) input('Hit any key to continue...') print( 'Reading in file example.txt and removing all whitespace characters...' ) ciphertext = cipher_utils.stripWhitespace( cipher_utils.readFile('example.txt')) cipherlist = list(ciphertext) print('Performing standard frequency analysis on list:') freq = cipher_utils.frequencyAnalysis(cipherlist) sortedFreq = cipher_utils.sortedFrequency(freq) cipher_utils.displayFrequency(sortedFreq) input('Hit any key to continue...') print('Turning on debugging (DEBUG Level)...') logger.setLevel(logger.DEBUG) print( 'Frequency analysis indicates a polyalphabetic cipher, so let\'s calculate the Index of Coincidence (ioc)' ) print('%s' % (cipher_utils.ioc(cipherlist))) input('Hit any key to continue...') print('Turning on debugging (INFO Level)...') logger.setLevel(logger.INFO) print('Now calculate the ioc for all possible subkeys from 1 to 9') displayIocTable(cipherlist, 9) input('Hit any key to continue...') keyLength = 6 print('Judging from the ioc table, we can guess that the keylength is %s' % (keyLength)) print('Display frequency analysis for the %s subkeys:' % (keyLength)) displaySubkeyFrequencies(cipherlist, keyLength) input('Hit any key to continue...') print( 'Most frequent letters for subkey1=X, subkey2=J, subkey3=H, subkey4=J, subkey5=Y, subkey6=Y' ) print( 'X=24 : 24-5=19 (S), J=10 : 10-5=5 (E), H=8 : 8-5=3 (C), J=10 : 10-5=5 (E), Y=25 : 25-5=20 (T), Y=25 : 25-5=20 (T)' ) print('Turning on debugging (DEBUG Level)...') logger.setLevel(logger.DEBUG) print('Attempt to decipher with keyword %s' % (deriveVigenereKeyPhrase('XJHJYY'))) input('Hit any key to continue...') solution = decryptVigenere(ciphertext, deriveVigenereKeyPhrase('XJHJYY')) print(solution) cipher_utils.writeFile('solution.txt', solution) print('This doesn\'t appear to be quite right - re-evaluate subkeys 4 & 5') print( 'Using second most frequent letters for subkeys 4 & 5: subkey1=X, subkey2=J, subkey3=H, subkey4=W, subkey5=J, subkey6=Y' ) print( 'X=24 : 24-5=19 (S), J=10 : 10-5=5 (E), H=8 : 8-5=3 (C), W=23 23-5=18 (R), J=10 : 10-5=5 (E), Y=25 : 25-5=20 (T)' ) print('Attempt to decipher with keyword %s' % (deriveVigenereKeyPhrase('XJHWJY'))) print('Turning off debugging (ERROR Level)...') logger.setLevel(logger.ERROR) input('Hit any key to continue...') solution = decryptVigenere(ciphertext, deriveVigenereKeyPhrase('XJHWJY')) print(solution) cipher_utils.writeFile('solution.txt', solution) logger.setLevel(logger.ERROR)
if decryptVigenere( cipher_utils.stripWhitespace(''' XSFJD JMNRF RUDJV LMYFT GWWHP TUDIA HWRMS XXAHJ DNBRH QTOFF NWFGH GLDJJ ATQWH UEQEM DMHRH LMCGL ZAYBT HUWIC MHDJI CGFVZ TJHWR FYBXB HTTLX AHFLY MHDKM ZKTPS SUMRH FHLRU WATHU JVLTQ LZSGS NAFWL WUGXD UYCHS WZJWH SIAIY GYLSQ CMDDF IMXHX JNNRY REFEX NWHTM LNEDJ CYDRM HIGXL VJLXQ HUYLH SLUYL TSVSH NBTQK FHWTQ DNHXU DQRYG YVSQF MMRKJ QHZOV SIMGH HTMLN EDJQB YKGZN XSFJD JMNRF XUBIG JRUKP PSSOE NVSXY GNRJQ YVYXJ JLBSF JDJMT JJFJA DDLYB XZQAA YKXLL DIYXX JWYRF WAYML NPHQY LYHFH LRUWA THBXD DQUUT XLYLT SVXTL FNQYN HMJOD NABGO WSOFG HJXIK YHPYM HZQVX UGILE FAXXL FYITX WJJUF TIFTH LJQKJ NAJUW FLXRD FDGTS BOFSL YRHJL YTUEY BTYWJ FHLKR JRUMN RFXIF JVLWU BLKLK IKBDJ IUGIV GRYOJ UQHIF UOWCG HXWAS PHQYW XQTUS ASAEJ WLJLL KRJSO FGHJX UGIXK JGTYK KYIWT WZJNK FQKKI KRDLN IGMRO JPXWQ GRUMY HJBBB HKEJN ATGAX OLJGL MYKJV MQNBS JKHLT REDJX WFWSX NKJDE XBHZO VLCOJ QGMCG YVSGI NYKGB CMBDK JHVWB HYYWI XJNHZ BRJQX PFUAN NAJDD QCXXV UTLXI VGRYG TWSGF XALUY IKNHK FATNQ KYNAJ JWWGT SVTJW TZVWY BXNUW SWKDS LNIGX BKYYF XGAIH HYVMK ZBHLW SNEDV UWUFG OWRYL XDYJM KNJGW INXPS YBXRD LNWTQ DFFFR XLKGS TQOAJ XVTGW HLTHN WWMEF LVGUK JSSYN XWQKM CWIHF BCMML FYBXR HKXUZ JVSSX NXHVY BXRWG WYVWH SYYMM HEFWA NQWZM XIWGJ HVWBH YNAJP LMILJ FGIYL WHNTF OJGSW INSGL MYNXH GKMXH UWYEX DVLMU MBHJJ MAFUW IUFTQ YYBHX HOMIG JHVJX MTFGR GNSLU FNXXH UZLXQ BLMYL JDJJE GTZFF MLDPE JNKNF WSWKD SLNIG XBKYY FXDFI BTAHS BYTPQ WXMBS WZFNX AHJDI GJLFA IEAHV MULYR HTMLJ VKYBX XDEJM XYRXX YVWHL PYRX '''), 'SECRET' ) != 'encryptionmakesthemodernworldgoroundeverytimeyoumakeamobilephonecallbuysomethingwithacreditcardinashoporontheweborevengetcashfromanatmencryptionbestowsuponthattransactiontheconfidentialityandsecuritytomakeitpossibleifyouconsiderelectronictransactionsandonlinepaymentsallthosewouldnotbepossiblewithoutencryptionsaiddrmarkmanulisaseniorlecturerincryptographyattheuniversityofsurreyatitssimplestencryptionisallabouttransformingintelligiblenumbersortextsoundsandimagesintoastreamofnonsensetherearemanymanywaystoperformthattransformationsomestraightforwardandsomeverycomplexmostinvolveswappinglettersfornumbersandusemathstodothetransformationhowevernomatterwhichmethodisusedtheresultingscrambleddatastreamshouldgivenohintsabouthowitwasencryptedduringworldwariithealliesscoredsomenotablevictoriesagainstthegermansbecausetheirencryptionsystemsdidnotsufficientlyscramblemessagesrigorousmathematicalanalysisbyalliedcodecrackerslaidbarepatternshiddenwithinthemessagesandusedthemtorecreatethemachineusedtoencryptthemthosecodesrevolvedaroundtheuseofsecretkeysthatweresharedamongthosewhoneededtocommunicatesecurelytheseareknownassymmetricencryptionsystemsandhaveaweaknessinthateveryoneinvolvedhastopossessthesamesetofsecretkeys':