def vigenereExample(): print("Vigenere Example") key = "ZEBRAS" print("The Key Is: {}\n".format(key)) print("Normal Mode") ptext = "THEQUICKBROWNFOXJUMPSOVERTHELAZYDOG" example(vigenere, ptext, key)
def multiVigenereExample(): print("Multiple Vigenere Example") key = ["ROMANCE", "KINGDOMS"] print("The Key Is: {}".format(key)) L = lcm(*[len(i) for i in key]) print("Effective Key Length: {}\n".format(L)) ptext = "THEQUICKBROWNFOXJUMPSOVERTHELAZYDOG" example(multiVigenere, ptext, key)
def nihilistExample(): ptext = "THEQUICKBROWNFOXJUMPSOVERTHELAZYDOG" key = ["SOMETHING","NIHILIST"] print("Example Of The Nihilist Cipher\n\nKey is {}\n".format(key)) c, d = example(nihilist,ptext,key) print(c)
def recursiveKeyExample(): print("Example of the Recursive Key Cipher") print("The recursive key cipher lengthens a short key by combining it with strentched out versions of itself.") print("Here the key is TABLE\n") k1 = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAATTTTT" k2 = "AAAAATTTTTAAAAABBBBBLLLLLEEEEETTTTT" k3 = "TABLETABLETABLETABLETABLETABLETABLE" n1 = alphaToNumber(k1) n2 = alphaToNumber(k2) n3 = alphaToNumber(k3) nT = [(a+b+c) % 26 for a,b,c in zip(n1,n2,n3)] kT = "".join(numberToAlpha(nT)) k1 = " TTTTT" k2 = " TTTTTAAAAABBBBBLLLLLEEEEETTTTT" k3 = "TABLETABLETABLETABLETABLETABLETABLE" print("{}\n{}\n{}\nWhich results in\n{}\n".format(k3,k2,k1,kT)) ptext = "THEQUICKBROWNFOXJUMPSOVERTHELAZYDOG" ctext, dtext = example(recursiveKey,ptext,"ZEBRAS") print(ptext) print(ctext) if dtext != ptext: print("Error")
def AMSCOExample(): print("Example of the AMSCO Cipher") ptext = "THEQUICKBROWNFOXJUMPSOVERTHELAZYDOG" key = "BIRTH" rank = uniqueRank(key) al = alternating(ptext) print("\nThe Key Is {}\n".format(key)) print("Each letter of the key is ranked to get") print(*rank) print( "\nNow the text is read into the grid by rows as alternating letters and bigrams. The key is placed above.\n" ) print(" ".join([str(i) for i in rank])) printColumns(al, 5, W=4) print( "\nFinally the grid is read off in accordance with column numbers starting with zero, then one, and so on.\n" ) ctext, dtext = example(AMSCO, ptext, key) print(ctext)
def columnarTransportExample(): print("Example of the columnar transport cipher") key = "BIRTHDAY" ptext = "THEQUICKBROWNFOXJUMPSOVERTHELAZYDOG" rank = uniqueRank(key) print("\nThe Key Is {}".format(key)) print("Each letter of the key is ranked to get") print(*rank) print("\nThe plaintext is\n{}".format(ptext)) print( "\nNow the text is read into the grid by rows. The key is placed above.\n" ) print(" ".join([str(i) for i in rank])) for i in groups(ptext, 8): print(" ".join([e for e in i])) print( "\nFinally the grid is read off in accordance with column numbers starting with zero, then one, and so on.\n" ) ctext, dtext = example(columnarTransport, ptext, key, complete=False) print(ctext)
def beaufortExample(): ptext="THEQUICKBROWNFOXJUMPSOVERTHELAZYDOG" print("Beaufort Example") key = "APPLES" print("The Key Is: {}\n".format(key)) ctext, dtext = example(beaufort,ptext,key) print(ctext)
def hillCipherExample(): print("Example of the Hill Cipher\n") key = createMatrixKey(4) print("The key is:") pprint(key) print() ptext = "THEQUICKBROWNFOXJUMPSOVERTHELAZYDOG" print(ptext) ctext, dtext = example(hillCipher, ptext, key) print(ctext)
def multiBeaufortExample(): ptext = "THEQUICKBROWNFOXJUMPSOVERTHELAZYDOG" print("Multiple Beaufort Example") key = ["AB","CDE","FGHIJ"] print("The Key Is: {}".format(key)) L = lcm( *[len(i) for i in key] ) print("Effective Key Length: {}\n".format(L)) ctext, dtext = example(multiBeaufort,ptext,key) print(ctext)
def ADFGVXExample(): print("Example of the ADFGVX Cipher\n") key = ["715ZEBRAS290","TABLES"] ptext = "THEQUICKBROWNFOXJUMPSOVERTHELAZYDOG" print("The Polybius Square:") ADFGVX(ptext,key,printkey=True) print("\nThe Columnar Transport Key:") print(key[1],end="\n\n") ctext, dtext = example(ADFGVX,ptext,key) print(ctext)
def disruptedTranspositionExample(): key = "BIRTHDAYS" ptext = "THEYHAVEDISCOVEREDTHATTHEQUICKBROWNFOXJUMPEDOVERTHELAZYDOGFLEENOW" rank = uniqueRank(key) print("Example of Completed Disrupted Transposition\n") print("The Key is: {}".format(key)) print("\nThe plaintext is\n{}".format(ptext)) #ptext = addNulls(ptext,len(key)**2) print("\nWe extend it with nulls to be\n{}".format(ptext)) print() G = ["" for i in key] # Here we copy some code from the cipher to make a nice graphic text = ptext for num in range(len(rank)): L = rank.index(num) + 1 G[num], text = text[:L], text[L:] print("The first half of the text is read into columns like this\n") print(" ".join([str(i) for i in rank])) for row in G: print(" ".join([i for i in row])) print() for num in range(len(rank)): rm = len(key) - len(G[num]) s, text = text[:rm], text[rm:] G[num] += s.lower() print( "\nThe remaining text then fills in the remaining spaces. Shown here in lowercase for ease of reading.\n" ) print(" ".join([str(i) for i in rank])) for row in G: print(" ".join([i for i in row])) print() print( "Then it is read off by columns starting with the one marked zero, then one, and so on.\n" ) print("The completed cipher:") ctext, dtext = example(disruptedTransposition, ptext, key) print(ctext)
def playfairExample(): key = "PLAYFAIREXAMPLE" ptext = "THEQUICKBROWNFOXIUMPSOVERTHELAZYDOG" print("Example of the Playfair\n") print("The key is the phrase {}\n".format(key)) print("In a 5x5 grid skipping repeated letters and turning J into I we get this:\n") playfair("",key,printkey=True,mode="IJ") print("\nTo use this key we consider pairs of letters.\n") print("Letters in the same column are each replaced with the letter below. The pair EV turns into DA.") print("Letters in the same row are each replaced with the letter to the left. The pair KS turns into NK.") print("Otherwise read across from the first letter to the column of the second and vice versa. The pair TH becomes ZB.\n") print(ptext) ctext, dtext = example(playfair,ptext,key) print(ctext)
def trithemiusExample(): print("Trithemius Example") print("The Key Is: ABCDEFGHIJKLMNOPQRSTUVWXYZ\n") ptext = "THEQUICKBROWNFOXJUMPSOVERTHELAZYDOG" example(trithemius, ptext, key="")