Exemplo n.º 1
0
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)
Exemplo n.º 2
0
# -*- 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)
Exemplo n.º 3
0
    print("=" * 80)
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    print(machine.decrypt(enc))


cm0 = CryptMachine(cipher, key)

cm = cm0
cm.set_alphabet(al.ENGLISH)
cm.set_key(key)
plaintext = "I don't love non-alphabet characters. I will remove all of them: ^,&@$~(*;?&#. Great!"
encdec(cm, plaintext)

cm = Block(cm, length=4, sep="/=/")
cm.set_alphabet(al.SWEDISH + al.DECIMAL)
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)
Exemplo n.º 4
0
    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"Θέλει αρετή και τόλμη η ελευθερία. (Ανδρέας Κάλβος)"
Exemplo n.º 5
0
        "--------------------------------------------------------------------")
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    print(machine.decrypt(enc))


cm0 = CryptMachine(cipher, key)

cm = cm0
cm.set_alphabet(al.ENGLISH)
cm.set_key("yzabchijkdeflmntuvwxopqrsg")
plaintext = "I don't love non-alphabet characters. I will remove all of them: ^,&@$~(*;?&#. Great!"
encdec(cm, plaintext)

cm = 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)
key = ("n", "g", "a", "b", "l", "s", "t", "u", "v", "c", "m", "o", "p", "q",
       "h", "ij", "k", "w", "x", "y", "r", "d", "e", "f", "z")
cm.set_key(key)
plaintext = "Jj becomes Ii because we use ENGLISH_SQUARE_IJ!"
encdec(cm, plaintext)

alphabet = u"abcdABCDEfghijFGHIJ"
Exemplo n.º 6
0
encdec(cm, plaintext)

plaintext = u"Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste."
cm.set_alphabet(al.GERMAN)
encdec(cm, plaintext)

plaintext = u"FAQ om Schweiz: Klöv du trång pjäxby?"
cm.set_alphabet(al.SWEDISH)
encdec(cm, plaintext)

cm.set_alphabet(al.JAPANESE_HIRAGANA)
cm.set_key(1)
plaintext = u"あいうえおかきくけこがぎぐげごさしすせそざじずぜぞたちつてとだぢづでどなにぬねのはひふへほばびぶべぼぱぴぷぺぽまみむめもやゆよらりるれろわをんゃゅょぁぇ"
encdec(cm, plaintext)

cm = Block(cm)
encdec(cm, plaintext)
'''
----------------------------------
The quick brown fox jumps over the lazydog.
gurdhvpxoebjasbkwhzcfbiregurynmlqbt
thequickbrownfoxjumpsoverthelazydog
----------------------------------
Why did the chicken cross the road? Gb trg gb gur bgure fvqr
Jul qvq gur puvpxra pebff gur ebnq? To get to the other side
Why did the chicken cross the road? Gb trg gb gur bgure fvqr
----------------------------------
Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste.
Sxt wtxot Kjatcüdßüüt bfläet Öpi füs Gxreßcxp yp qmdt pfu stö Htv qxd kfc Zndet.
Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste.
----------------------------------
Exemplo n.º 7
0
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)
Exemplo n.º 8
0
        "--------------------------------------------------------------------")
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    print(machine.decrypt(enc))


cm0 = CryptMachine(cipher, key)

cm = cm0
cm.set_alphabet(al.ENGLISH)
cm.set_key("keys")
plaintext = "I don't love non-alphabet characters. I will remove all of them: ^,&@$~(*;?&#. Great!"
encdec(cm, plaintext)

cm = 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)
Exemplo n.º 9
0
def encdec(machine, plaintext):
    print("----------------------------------")
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    dec = machine.decrypt(enc)
    print(dec)


plaintext = u"The man has 536 dogs! How many dogs do you have?"

cm = CryptMachine(Rot18())
encdec(cm, plaintext)

cm1 = Block(cm)
encdec(cm1, plaintext)

cm = SaveAll(cm)
encdec(cm, plaintext)

cm = UpperCase(cm)
encdec(cm, plaintext)
'''
----------------------------------
The man has 536 dogs! How many dogs do you have?
gurznaunf081qbtfubjznalqbtfqblbhunir
themanhas536dogshowmanydogsdoyouhave
----------------------------------
The man has 536 dogs! How many dogs do you have?
gurzn aunf0 81qbt fubjz nalqb tfqbl bhuni r
Exemplo n.º 10
0
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)

cm.set_alphabet(al.GREEK_SQUARE)
key = (u"ίκλειδ", u"κλειδί", u"λειδίκ")
cm.set_key(key)
plaintext = u"Θέλει αρετή και τόλμη η ελευθερία. (Ανδρέας Κάλβος)"
encdec(cm, plaintext)

cm = UpperCase(Block(CryptMachine(ThreeSquare())))
cm.set_alphabet(al.GREEK_SQUARE)
key = (u"ίκλειδ", u"κλειδί", u"λειδίκ")
cm.set_key(key)
encdec(cm, plaintext)
'''
================================================================================
The quick brown fox jumps over the lazy dog!
TPGEDELYICAWBACHSYNNJOSUJJTYRPSUWHWYINTBJELCBTXYSFONMV
THEOUICKBROWNFOXJUMPSOVERTHELAZYDOGZ
================================================================================
The quick brown fox jumps over the lazy dog!
TPJ LDONY IAAEX ARB SOUNH OSXS JVM RMMU EHW!OWNZBJEGCAKXKSFYUMU
THE OUICK BROWN FOX JUMPS OVER THE LAZY DOG!Z
================================================================================
Attack at dawns!!!
Exemplo n.º 11
0
    print("=" * 80)
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    print(machine.decrypt(enc))


key = "manykeys"
cm0 = CryptMachine(cipher, key)

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)

cm = SaveAll(cm0)
plaintext = "I love non-alphabet characters. These are : ^,&@$~(*;?&#. That's it!"
encdec(cm, plaintext)

cm.set_alphabet(al.JAPANESE_HIRAGANA)
cm.set_key(u"だやぎへ")
plaintext = u"text あい だやぎへぐゆぢ"
encdec(cm, plaintext)

cm.set_alphabet(al.ENGLISH_SQUARE_IJ)
cm.set_key(u"keyj")
plaintext = "ENGLISH_SQUARE_IJ doesn't change Ii to Jj because it's a transposition cipher!"
Exemplo n.º 12
0
    print("--------------------------------------------------------------------")
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    print(machine.decrypt(enc))


cm0 = CryptMachine(cipher, key)

cm = cm0
cm.set_alphabet(al.ENGLISH)
cm.set_key("tomatokey")
plaintext = "I don't love non-alphabet characters. I will remove all of them: ^,&@$~(*;?&#. Great!"
encdec(cm, plaintext)

cm = 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)
cm.set_key(u"かぎはにかぎ")
plaintext = u"text いろはにほへと ちりぬるを わかよたれそ つねならむ うゐのおくやま けふこえて あさきゆめみし ゑひもせす !"
encdec(cm, plaintext)

cm = UpperCase(cm)
alphabet = al.GREEK
cm.set_alphabet(alphabet)
Exemplo n.º 13
0
    print(machine.decrypt(enc))
    print("----------------------------------")


key = 5
cm = CryptMachine(Bifid(), key)
alphabet = [
    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"я", u"1", u"2", u"3", u"4", u"5", u"6"
]
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"