enc = cipher.encrypt(plaintext, key, alphabet) print(enc) print(cipher.decrypt(enc, key, alphabet)) print("----------------------------------") def encdec(machine, plaintext): print(plaintext) enc = machine.encrypt(plaintext) print(enc) print(machine.decrypt(enc)) print("----------------------------------") cm0 = CryptMachine(cipher, key) cm = UpperCase(Block(cm0)) cm.set_alphabet(alphabet) plaintext = u"Attack at once!" encdec(cm, plaintext) cm1 = SaveAll(cm0) plaintext = u"Attack at once!" encdec(cm1, plaintext) alphabet = al.GERMAN_SQUARE key = "german" cm.set_key(key) cm.set_alphabet(alphabet) plaintext = u"Schweißgequält vom öden Text zürnt Typograf Jakob" encdec(cm, plaintext)
# -*- encoding: utf-8 -*- from secretpy import Bazeries, CryptMachine, alphabets as al from secretpy.cmdecorators import UpperCase, SaveAll 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)
from secretpy import Playfair from secretpy import CryptMachine from secretpy.cmdecorators import NoSpaces, UpperCase def encdec(machine, plaintext): print(plaintext) enc = machine.encrypt(plaintext) print(enc) dec = machine.decrypt(enc) print(dec) print("----------------------------------") cm = NoSpaces(UpperCase(CryptMachine(Playfair()))) alphabet = [ u"p", u"l", u"a", u"y", u"f", u"i", u"r", u"e", u"x", u"m", u"b", u"c", u"d", u"g",
def encdec(machine, plaintext): print(plaintext) enc = machine.encrypt(plaintext) print(enc) dec = machine.decrypt(enc) print(dec) print("----------------------------------") alphabet = alphabets.ENGLISH_SQUARE_OQ key = (u"example", u"keyword") cm = UpperCase(CryptMachine(TwoSquare())) cm.set_alphabet(alphabet) cm.set_key(key) plaintext = u"Help me Obi wan Kenobi" encdec(cm, plaintext) plaintext = u"Help me Obi wan Kenobi y" encdec(cm, plaintext) ''' Help me Obi wan Kenobi XGDLXWSDJYRYHOTKDG HELPMEOBIWANKENOBI ---------------------------------- Help me Obi wan Kenobi y XGDLXWSDJYRYHOTKDGZX
from secretpy import ThreeSquare, CryptMachine, alphabets as al from secretpy.cmdecorators import UpperCase, SaveAll, Block def encdec(machine, plaintext): print("=" * 80) print(plaintext) enc = machine.encrypt(plaintext) print(enc) dec = machine.decrypt(enc) print(dec) key = (u"example", u"keyword", u"third") cm = UpperCase(CryptMachine(ThreeSquare())) cm.set_alphabet(al.ENGLISH_SQUARE_OQ) cm.set_key(key) plaintext = u"The quick brown fox jumps over the lazy dog!" encdec(cm, plaintext) cm = SaveAll(cm) encdec(cm, plaintext) cm = SaveAll(CryptMachine(ThreeSquare())) cm.set_alphabet(al.ENGLISH_SQUARE_IJ) key = (u"criptog", u"segurt", u"mars") cm.set_key(key) plaintext = u"Attack at dawns!!!" encdec(cm, plaintext)
dec = cipher.decrypt(enc, key, alphabet) print(dec) def encdec(machine, plaintext): print("=" * 80) print(plaintext) enc = machine.encrypt(plaintext) print(enc) print(machine.decrypt(enc)) cm0 = CryptMachine(cipher, key) cm = cm0 cm = UpperCase(Block(cm0)) key = 5 cm.set_key(key) cm.set_alphabet(al.ENGLISH) plaintext = "WE ARE DISCOVERED FLEE AT ONCE" encdec(cm, plaintext) cm = cm0 cm.set_alphabet(al.ENGLISH) plaintext = "I don't love non-alphabet characters and uppercase. I will remove all of them: ^,&@$~(*;?&#." encdec(cm, plaintext) cm = Block(cm, length=5, sep=" ") plaintext = "This text is divided by blocks of length 5!" encdec(cm, plaintext)
from secretpy import alphabets from secretpy.cmdecorators import NoSpaces, UpperCase def encdec(machine, plaintext): print(plaintext) enc = machine.encrypt(plaintext) print(enc) dec = machine.decrypt(enc) print(dec) print("----------------------------------") alphabet = alphabets.ENGLISH_SQUARE_OQ key = (u"example", u"keyword") cm = NoSpaces(UpperCase(CryptMachine(TwoSquare()))) cm.set_alphabet(alphabet) cm.set_key(key) plaintext = u"Help me Obi wan Kenobi" encdec(cm, plaintext) ''' Help me Obi wan Kenobi XGDLXWSDJYRYHOTKDG HELPMEOBIWANKENOBI ---------------------------------- '''
"--------------------------------------------------------------------") print(plaintext) enc = machine.encrypt(plaintext) print(enc) print(machine.decrypt(enc)) cm0 = CryptMachine(cipher, key) cm = cm0 cm.set_alphabet(al.DECIMAL + al.ENGLISH) cm.set_key("manykeys") plaintext = "I don't love non-alphabet characters. I will remove all of them: ^,&@$~(*;?&#. Great!" 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)
def encdec(machine, plaintext): print(plaintext) enc = machine.encrypt(plaintext) print(enc) dec = machine.decrypt(enc) print(dec) print("----------------------------------") alphabet = alphabets.ENGLISH_SQUARE_OQ key = (u"exampl", u"keyword") cm = NoSpaces(UpperCase(CryptMachine(FourSquare()))) cm.set_alphabet(alphabet) cm.set_key(key) plaintext = u"Help me Obi wan Kenobi" encdec(cm, plaintext) alphabet = alphabets.ENGLISH_SQUARE_IJ cm.set_alphabet(alphabet) key = (u"criptog", u"segurt") cm.set_key(key) plaintext = u"attack at dawn" encdec(cm, plaintext) ''' Help me Obi wan Kenobi FYGMKYHOBXMFKKKIMD
def encdec(machine, plaintext): print('-' * 80) print(plaintext) enc = machine.encrypt(plaintext) print(enc) print(machine.decrypt(enc)) cm0 = CryptMachine(cipher, key) cm = cm0 plaintext = "I don't love non-alphabet characters. I will remove all of them: ^,&@$~(*;?&#. Great!" 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) ''' ================================================================================ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa uwmmfkclcsqbwssepjlncolndnmlgulxemxrlmmconlrw aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -------------------------------------------------------------------------------- I don't love non-alphabet characters. I will remove all of them: ^,&@$~(*;?&#. Great! keqceemxifxtwwogpmtxaslpdverbdoloqzapagjpnaxzldgaajxodo idontlovenonalphabetcharactersiwillremoveallofthemgreat
cm.set_alphabet(alphabet) plaintext = u"Текст здесь, много!!!" encdec(cm, plaintext) cm1 = Block(cm) alphabet = [ u"p", u"h", u"q", u"g", u"m", u"e", u"a", u"y", u"l", u"n", u"o", u"f", u"d", u"x", u"k", u"r", u"c", u"v", u"s", u"z", u"w", u"b", u"u", u"t", u"ij" ] cm1.set_alphabet(alphabet) plaintext = u"Defend the East Wall of the Castle!" encdec(cm1, plaintext) cm1 = UpperCase(cm1) alphabet = [ u"b", u"g", u"w", u"k", u"z", u"q", u"p", u"n", u"d", u"s", u"ij", u"o", u"a", u"x", u"e", u"f", u"c", u"l", u"u", u"m", u"t", u"h", u"y", u"v", u"r" ] cm1.set_alphabet(alphabet) cm1.set_key(10) plaintext = "flee at once" encdec(cm1, plaintext) cm = SaveAll(cm) alphabet = al.GREEK_SQUARE cm.set_alphabet(alphabet) plaintext = u"Θέλει αρετή και τόλμη η ελευθερία. (Ανδρέας Κάλβος)"
from secretpy import Chao, CryptMachine, alphabets from secretpy.cmdecorators import UpperCase, SaveAll def encdec(machine, plaintext): print(plaintext) enc = machine.encrypt(plaintext) print(enc) print(machine.decrypt(enc)) print("-------------------------------") 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:
from secretpy import Chao, CryptMachine, alphabets from secretpy.cmdecorators import UpperCase, SaveSpaces def encdec(machine, plaintext): print(plaintext) enc = machine.encrypt(plaintext) print(enc) print(machine.decrypt(enc)) print("-------------------------------") alphabet = "ptlnbqdeoysfavzkgjrihwxumc" # RIGHT WHEEL PT key = "hxuczvamdslkpefjrigtwobnyq" # LEFT WHEEL CT cm = SaveSpaces(UpperCase(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:
# -*- encoding: utf-8 -*- from secretpy import Playfair, CryptMachine from secretpy.cmdecorators import UpperCase def encdec(machine, plaintext): print(plaintext) enc = machine.encrypt(plaintext) print(enc) dec = machine.decrypt(enc) print(dec) print("----------------------------------") cm = UpperCase(CryptMachine(Playfair())) alphabet = [ u"p", u"l", u"a", u"y", u"f", u"i", u"r", u"e", u"x", u"m", u"b", u"c", u"d", u"g",
plaintext = "This text is divided by blocks of length 4!" 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) plaintext = u"text いろはにほへと ちりぬるを わかよたれそ つねならむ うゐのおくやま けふこえて あさきゆめみし ゑひもせす !" encdec(cm, plaintext) cm = UpperCase(cm) alphabet = al.GREEK cm.set_alphabet(alphabet) plaintext = u"Θέλει αρετή και τόλμη η ελευθερία. (Ανδρέας Κάλβος)" encdec(cm, plaintext) ''' thequickbrownfoxjumpsoverthelazydog lfkqsmwapxcgvrcntsojeczkxlfkhibudcy thequickbrownfoxjumpsoverthelazydog ================================================================================ I don't love non-alphabet characters. I will remove all of them: ^,&@$~(*;?&#. Great! mdcvlhczkvcvihjfipklwfixiwlkxemgmhhxkoczkihhcrlfkoyxkil idontlovenonalphabetcharactersiwillremoveallofthemgreat ================================================================================ This text is divided by blocks of length 4! yszr/=/y7ny/=/zr0z/=/9z07/=/0pup/=/höwa/=/röeh/=/7vly/=/sf
from secretpy import alphabets from secretpy.cmdecorators import NoSpaces, UpperCase def encdec(machine, plaintext): print(plaintext) enc = machine.encrypt(plaintext) print(enc) dec = machine.decrypt(enc) print(dec) print("----------------------------------") alphabet = alphabets.ENGLISH_SQUARE_IJ key = (81257, u"eightyonethousandtwohundredfiftyseven") cm = NoSpaces(UpperCase(CryptMachine(Bazeries()))) cm.set_alphabet(alphabet) cm.set_key(key) plaintext = u"Whoever has made a voyage up the Hudson" \ u" must remember the Kaatskill mountains" encdec(cm, plaintext) ''' Whoever has made a voyage up the Hudson must remember the Kaatskill mountains DUMTMCDSENRTEMVEQXMOELCCRVXDMDKWXNNMUKRDKUMYNMBPRKEEPMGNGEKWXCRWB WHOEVERHASMADEAVOYAGEUPTHEHUDSONMUSTREMEMBERTHEKAATSKILLMOUNTAINS ---------------------------------- '''
print( "--------------------------------------------------------------------") print(plaintext) enc = machine.encrypt(plaintext) print(enc) print(machine.decrypt(enc)) cm0 = CryptMachine(cipher, key) cm0.set_alphabet(al.ENGLISH + al.DECIMAL) cm = cm0 plaintext = "I don't love non-alphabet characters. I will remove all of them: ^,&@$~(*;?&#. Great!" 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.JAPANESE_HIRAGANA) plaintext = u"text いろはにほへと ちりぬるを わかよたれそ つねならむ うゐのおくやま けふこえて あさきゆめみし ゑひもせす !" encdec(cm, plaintext) cm = UpperCase(cm) alphabet = al.GREEK cm.set_alphabet(alphabet) plaintext = u"Θέλει αρετή και τόλμη η ελευθερία. (Ανδρέας Κάλβος)"
# -*- encoding: utf-8 -*- from secretpy import Atbash, CryptMachine, alphabets from secretpy.cmdecorators import UpperCase, SaveAll def encdec(machine, plaintext): print("-" * 80) print(plaintext) enc = machine.encrypt(plaintext) print(enc) dec = machine.decrypt(enc) print(dec) cm = UpperCase(CryptMachine(Atbash())) plaintext = u"attackatdawn" encdec(cm, plaintext) plaintext = u"במקום" cm.set_alphabet(alphabets.HEBREW) encdec(cm, plaintext) cm = SaveAll(cm) plaintext = u"The quick brown fox jumps over the lazy dog." cm.set_alphabet(alphabets.GERMAN) encdec(cm, plaintext) plaintext = u"Achtung Minen!!!" encdec(cm, plaintext)
# -*- encoding: utf-8 -*- from secretpy import ADFGVX, CryptMachine from secretpy.cmdecorators import Block, UpperCase def encdec(machine, plaintext): print(plaintext) enc = machine.encrypt(plaintext) print(enc) print(machine.decrypt(enc)) print("-------------------------------") key = "privacy" 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 = u"thequickbrownfoxjumpsoverthelazydog" key = 3 cipher = Caesar() cm = CryptMachine(cipher, key) encdec(cm, plaintext) cm.set_alphabet(alphabets.GERMAN) encdec(cm, plaintext) cm = SaveSpaces(cm) cm.set_key(9) plaintext = u"the quick brown fox jumps over the lazy dog" encdec(cm, plaintext) cm = NoSpaces(UpperCase(cm)) cm.set_cipher(Atbash()) plaintext = u"Achtung Minen" encdec(cm, plaintext) ''' Output: thequickbrownfoxjumpsoverthelazydog wkhtxlfneurzqiramxpsvryhuwkhodcbgrj thequickbrownfoxjumpsoverthelazydog ----------------------------------- thequickbrownfoxjumpsoverthelazydog wkhtxlfneurzqirämxpsvryhuwkhodüögrj thequickbrownfoxjumpsoverthelazydog -----------------------------------