cm = UpperCase(Block(CryptMachine(ADFGVX(), key), 4)) alphabet = ( u"n", u"a", u"1", u"c", u"3", u"h", u"8", u"t", u"b", u"2", u"o", u"m", u"e", u"5", u"w", u"r", u"p", u"d", u"4", u"f", u"6", u"g", u"7", u"i", u"9", u"j", u"0", u"k", u"l", u"q", u"s", u"u", u"v", u"x", u"y", u"z", ) cm.set_alphabet(alphabet) plaintext = "Attack at 12.00am!" encdec(cm, plaintext) key = "pangram" cm.set_key(key) plaintext = "The quick brown fox jumps over the lazy dog." encdec(cm, plaintext) alphabet = ( u"5", u"б", u"в", u"г", u"д", u"её", u"ж", u"з", u"ий", u"к", u"л", u"м", u"н", u"о", u"п", u"р", u"с", u"т", u"у", u"ф", u"х", u"ц", u"ч", u"ш", u"щ", u"ы", u"ьъ", u"э", u"ю", u"я", u"0", u"1", u"2", u"3", u"4", u"а", ) cm.set_alphabet(alphabet) key = "russian" cm.set_key(key) plaintext = u"Эй, жлоб! Где туз? Прячь юных съёмщиц в шкаф."
encdec(cm, plaintext) cm = UpperCase(Block(cm, length=5, sep="-")) plaintext = "This text is divided by blocks of length 5!" encdec(cm, plaintext) cm = SaveAll(cm0) plaintext = "I love non-alphabet characters. These are : ^,&@$~(*;?&#. That's it!" encdec(cm, plaintext) cm.set_alphabet(al.ENGLISH_SQUARE_IJ) plaintext = "Jj becomes Ii because we use ENGLISH_SQUARE_IJ!" encdec(cm, plaintext) cm.set_alphabet(al.JAPANESE_HIRAGANA) cm.set_key(u"かぎ") plaintext = u"text いろはにほへと ちりぬるを わかよたれそ つねならむ うゐのおくやま けふこえて あさきゆめみし ゑひもせす !" encdec(cm, plaintext) cm = UpperCase(cm) alphabet = al.GREEK cm.set_alphabet(alphabet) cm.set_key(u"κλειδί") plaintext = u"Θέλει αρετή και τόλμη η ελευθερία. (Ανδρέας Κάλβος)" encdec(cm, plaintext) ''' thequickbrownfoxjumpsoverthelazydog rblmscefuojviyjwdshkpjtlorblgqzxnja thequickbrownfoxjumpsoverthelazydog -------------------------------------------------------------------- I don't love non-alphabet characters. I will remove all of them: ^,&@$~(*;?&#. Great!
def encdec(machine, plaintext): print("=" * 80) print(plaintext) enc = machine.encrypt(plaintext) print(enc) dec = machine.decrypt(enc) print(dec) cm = UpperCase(CryptMachine(Bazeries())) cm.set_alphabet(al.ENGLISH_SQUARE_IJ) key = (81257, u"eightyonethousandtwohundredfiftyseven") cm.set_key(key) plaintext = u"Whoever has made a voyage up the Hudson" \ u" must remember the Kaatskill mountains" encdec(cm, plaintext) cm = SaveAll(cm) encdec(cm, plaintext) cm = UpperCase(SaveAll(CryptMachine(Bazeries(), key))) cm.set_alphabet(al.ENGLISH_SQUARE_IJ) plaintext = u"The quick brown fox jumps over the lazy dog!" encdec(cm, plaintext) cm.set_alphabet(al.GREEK_SQUARE) cm.set_key((2358, u"κλειδί")) plaintext = u"Θέλει αρετή και τόλμη η ελευθερία. (Ανδρέας Κάλβος)"
alphabet = "ptlnbqdeoysfavzkgjrihwxumc" # RIGHT WHEEL PT key = "hxuczvamdslkpefjrigtwobnyq" # LEFT WHEEL CT cm = UpperCase(SaveAll(CryptMachine(Chao(), key))) cm.set_alphabet(alphabet) plaintext = "well done is better than well said" encdec(cm, plaintext) plaintext = "plaintext" encdec(cm, plaintext) cm.set_alphabet(alphabets.ENGLISH) cm.set_key(alphabets.ENGLISH) plaintext = "do not use pc" encdec(cm, plaintext) ''' Output: well done is better than well said OAHQ HCNY NX TSZJRR HJBY HQKS OUJY WELL DONE IS BETTER THAN WELL SAID ------------------------------- plaintext HULROKQUA PLAINTEXT ------------------------------- do not use pc DN LLQ QYM MW