API

ADFGX

class secretpy.ADFGX

The ADFGX Cipher

decrypt(text, key, alphabet=('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'ij', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'))

Decryption method

Parameters:
  • text (string) – Text to decrypt
  • key (integer) – Decryption key is in ENGLISH
  • alphabet (string) – Alphabet which will be used(length=25), if there is no a value, ENGLISH_SQUARE_IJ is used
Returns:

text

Return type:

string

encrypt(text, key, alphabet=('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'ij', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'))

Encryption method

Parameters:
  • text (string) – Text to encrypt
  • key (integer) – Encryption key is in ENGLISH
  • alphabet (string) – Alphabet which will be used(length=25), if there is no a value, ENGLISH_SQUARE_IJ is used
Returns:

text

Return type:

string

Examples

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/python
# -*- encoding: utf-8 -*-

from secretpy import ADFGX, CryptMachine, alphabets as al
from secretpy.cmdecorators import SaveAll, Block, UpperCase


alphabet = (
    u"b", u"t", u"a", u"l", u"p",
    u"d", u"h", u"o", u"z", u"k",
    u"q", u"f", u"v", u"s", u"n",
    u"g", u"ij", u"c", u"u", u"x",
    u"m", u"r", u"e", u"w", u"y"
)
key = "cargo"
cipher = ADFGX()
plaintext = u"attackatonce"

print(plaintext)
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)

alphabet = (
    u"uúů", u"aá", u"b", u"cč", u"dď",
    u"f", u"g", u"h", u"iíj", u"zž",
    u"k", u"l", u"m", u"nň", u"oó",
    u"p", u"q", u"rř", u"sš", u"tť",
    u"v", u"w", u"x", u"yý", u"eéě",
)
key = "czech"
cm.set_key(key)
cm.set_alphabet(alphabet)
plaintext = u"Nechť již hříšné saxofony ďáblů rozezvučí síň úděsnými tóny waltzu, tanga a quickstepu."
encdec(cm, plaintext)

alphabet = (
    u"zž", u"aáä", u"b", u"cč", u"dď",
    u"eé", u"f", u"g", u"h", u"iíj",
    u"k", u"lĺľ", u"m", u"oóô", u"p",
    u"q", u"rŕ", u"sš", u"tť", u"uú",
    u"v", u"w", u"x", u"yý", u"nň",
)
key = "slovak"
cm.set_key(key)
cm.set_alphabet(alphabet)
plaintext = u"Vypätá dcéra grófa Maxwella s IQ nižším ako kôň núti čeľaď hrýzť hŕbu jabĺk."
encdec(cm, plaintext)

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"",
)
key = "greek"
cm.set_key(key)
cm.set_alphabet(alphabet)
plaintext = u"Ξεσκεπάζω την ψυχοφθόρα σας βδελυγμία."
encdec(cm, plaintext)

'''
attackatonce
faxdfadddgdgfffafaxafafx
attackatonce
----------------------------------
Attack at once!
FAXDF ADDDG DGFFF AFAXA FAFX
ATTACKATONCE
----------------------------------
Attack at once!
Faxdfa dd dgdg!fffafaxafafx
Attack at once!
----------------------------------
Schweißgequält vom öden Text zürnt Typograf Jakob
DDAAX FFXGG FGDFF DFAAG GGGDG GAADG XGGFF AGGGG FAAAF XDXGD XXXFG DAXFG XAAGF FXGXD GGAAD GGFAA XFXDD D
SCHWEISGEQUALTVOMODENTEXTZURNTTYPOGRAFIAKOB
----------------------------------
Nechť již hříšné saxofony ďáblů rozezvučí síň úděsnými tóny waltzu, tanga a quickstepu.
FGDXD GAXFX FFXAD GAGFX XDDXD DDAXA XGGGG GFFGA ADXAG AXXGF DGAFD AGGAX FDFGX XAXDA XDAGG XGDXX DADAD AGGAX DFFGF XAFGX XGDAG GGGAX GGAAF XAGDG DGXDD GADFX AGFXF FFGFX ADGGG X
NECHTIIZHRISNESAXOFONYDABLUROZEZVUCISINUDESNYMITONYWALTZUTANGAAQUICKSTEPU
----------------------------------
Vypätá dcéra grófa Maxwella s IQ nižším ako kôň núti čeľaď hrýzť hŕbu jabĺk.
FADDD ADAGA FFXGD AXDGA XDAFD DADAA FGXGA XGGXF ADXDD DFDFX FDAXX DGADX DXGAA FFXFD DDFFG AAGGA AFXAA GGAXF GXGAF XDFDA GDFGG GDGFD DXXXA GXGDD GFDA
VYPATADCERAGROFAMAXWELLASIQNIZSIMAKOKONNUTICELADHRYZTHRBUIABLK
----------------------------------
Ξεσκεπάζω την ψυχοφθόρα σας βδελυγμία.
AXAGF XXXGF AXDXA AGFXA GFAXA GFFGA DFFFA AAAFA GXDGX DDDAD FFAGD AXDGX FAGGG D
ΞΕΣΚΕΠΑΖΩΤΗΝΨΥΧΟΦΘΟΡΑΣΑΣΒΔΕΛΥΓΜΙΑ
----------------------------------
'''

ADFGVX

class secretpy.ADFGVX

The ADFGVX Cipher

decrypt(text, key, alphabet=None)

Decryption method

Parameters:
  • text (string) – Text to decrypt
  • key (integer) – Decryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

encrypt(text, key, alphabet=None)

Encryption method

Parameters:
  • text (string) – Text to encrypt
  • key (integer) – Encryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English with numbers is used
Returns:

text

Return type:

string

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/python
# -*- 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 = "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)

'''
Attack at 12.00am!
DGDD DAGD DGAF ADDF DADV DVFA ADVX
ATTACKAT1200AM
-------------------------------
The quick brown fox jumps over the lazy dog.
DXGF VDVD VFAA GGDX AFXG XGFA GFFA DDVG DDXA FAXG ADDF XXXD AXDX VVDD DGVV FXFA VVFX XV
THEQUICKBROWNFOXJUMPSOVERTHELAZYDOG
-------------------------------
Эй, жлоб! Где туз? Прячь юных съёмщиц в шкаф.
AAXF FGXG GDDF FVDA FDDG GGVF DGXV VAAV VFXA XDDA DGAV AGDF AXFV VFDX GFVD XFVV FG
ЭИЖЛОБГДЕТУЗПРЯЧЬЮНЫХСЬЕМЩИЦВШКАФ
-------------------------------
'''

Affine

class secretpy.Affine

The Affine Cipher

decrypt(text, key, alphabet='abcdefghijklmnopqrstuvwxyz')

Decryption method

Parameters:
  • text (string) – Text to decrypt
  • key (tuple of 2 integers) – Decryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

encrypt(text, key, alphabet='abcdefghijklmnopqrstuvwxyz')

Encryption method

Parameters:
  • text (string) – Text to encrypt
  • key (tuple of 2 integers) – Encryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/python
# -*- encoding: utf-8 -*-

from secretpy import Affine, CryptMachine, alphabets as al
from secretpy.cmdecorators import UpperCase, Block, SaveAll


alphabet = al.ENGLISH
plaintext = u"thequickbrownfoxjumpsoverthelazydog"
key = (7, 8)

cipher = Affine()
print(plaintext)

enc = cipher.encrypt(plaintext, key, alphabet)
print(enc)
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.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)

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
thistextisdividedbyblocksoflength4
================================================================================
I love non-alphabet characters. These are : ^,&@$~(*;?&#. That's it!
Z hö97 vöv-ih6sip7y wsikiwy7kr. Ys7r7 ik7 : ^,&@$~(*;?&#. Ysiy'r zy!
I love non-alphabet characters. These are : ^,&@$~(*;?&#. That's it!
================================================================================
Jj becomes Ii because we use ENGLISH_SQUARE_IJ!
Pp qmxzlmc Pp qmxircm fm rcm MSADPCH_CORIVM_PP!
Ii becomes Ii because we use ENGLISH_SQUARE_II!
================================================================================
text いろはにほへと ちりぬるを わかよたれそ つねならむ うゐのおくやま けふこえて あさきゆめみし ゑひもせす !
text さじやづぐかも ねあのくな てへよぢごる ばびたをつ ずゐぺにむべげ りぁゃとぷ けぬぱまどざほ ゑろひめぴ !
text いろはにほへと ちりぬるを わかよたれそ つねならむ うゐのおくやま けふこえて あさきゆめみし ゑひもせす !
================================================================================
Θέλει αρετή και τόλμη η ελευθερία. (Ανδρέας Κάλβος)
ΛΟΘΙΡ ΗΦΙΝΖ ΓΗΡ ΝΚΘΞΑ Α ΙΘΙΣΛΙΦΧΗ. (ΗΤΔΦΟΗΉ ΓΜΘΣΈΉ)
ΘΈΛΕΙ ΑΡΕΤΉ ΚΑΙ ΤΌΛΜΗ Η ΕΛΕΒΘΕΡΊΑ. (ΑΝΔΡΈΑΣ ΚΆΛΒΟΣ)
'''

Atbash

class secretpy.Atbash

The Atbash Cipher

decrypt(text, key=None, alphabet='abcdefghijklmnopqrstuvwxyz')

Decryption method

Parameters:
  • text (string) – Text to decrypt
  • key (integer) – is not used
  • alphabet (string or tuple of strings) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

encrypt(text, key=None, alphabet='abcdefghijklmnopqrstuvwxyz')

Encryption method

Parameters:
  • text (string) – Text to encrypt
  • key (integer) – is not used
  • alphabet (string or tuple of strings) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/python
# -*- 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)

cm.set_alphabet(alphabets.ARABIC)
plaintext = u"حريتي : أن أكون كما لا يريدون لي أن أكون"
encdec(cm, plaintext)

'''
--------------------------------------------------------------------------------
attackatdawn
ZGGZXPZGWZDM
ATTACKATDAWN
--------------------------------------------------------------------------------
במקום
שלדץם
במקום
--------------------------------------------------------------------------------
The quick brown fox jumps over the lazy dog.
KWZ NJVÖT ÜMPHQ YPG UJROL PIZM KWZ SßEF ÄPX.
THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.
--------------------------------------------------------------------------------
Achtung Minen!!!
ßÖWKJQX RVQZQ!!!
ACHTUNG MINEN!!!
--------------------------------------------------------------------------------
حريتي : أن أكون كما لا يريدون لي أن أكون
شطقزق : غس غصثس صعا فا قطقذثس فق غس غصثس
حريتي : أن أكون كما لا يريدون لي أن أكون
'''

Autokey

class secretpy.Autokey

The Autokey Cipher

decrypt(text, key, alphabet='abcdefghijklmnopqrstuvwxyz')

Decryption method

Parameters:
  • text (string) – Text to decrypt
  • key (string) – Decryption key
  • alphabet (string or tuple of strings) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

encrypt(text, key, alphabet='abcdefghijklmnopqrstuvwxyz')

Encryption method

Parameters:
  • text (string) – Text to encrypt
  • key (string) – Encryption key
  • alphabet (string or tuple of strings) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/python
# -*- encoding: utf-8 -*-

from secretpy import Autokey, CryptMachine, alphabets as al
from secretpy.cmdecorators import UpperCase, Block, SaveAll


alphabet = al.GERMAN
plaintext = u"thequickbrownfoxjumpsoverthelazydog"
key = "queenly"

cipher = Autokey()
print(plaintext)

enc = cipher.encrypt(plaintext, key, alphabet)
print(enc)
dec = cipher.decrypt(enc, key, alphabet)
print(dec)


def encdec(machine, plaintext):
    print("--------------------------------------------------------------------")
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    print(machine.decrypt(enc))


cm0 = CryptMachine(cipher, key)

cm = cm0
cm.set_alphabet(al.ENGLISH + al.DECIMAL)
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)

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

'''
thequickbrownfoxjumpsoverthelazydog
föiudtäßivamvhyyäeeüxüonhbwwzvßlwvk
thequickbrownfoxjumpsoverthelazydog
--------------------------------------------------------------------
I don't love non-alphabet characters. I will remove all of them: ^,&@$~(*;?&#. Great!
shc51o28xy28ey3uamt0cieacjtvru10z3tdmxzcimz6sf4ssrzyimz
idontlovenonalphabetcharactersiwillremoveallofthemgreat
--------------------------------------------------------------------
This text is divided by blocks of length 5!
3l6ac-l5b1w-0130g-myj1f-op0l3-2hvw1-l4li
thistextisdividedbyblocksoflength5
--------------------------------------------------------------------
I love non-alphabet characters. These are : ^,&@$~(*;?&#. That's it!
S pcdm y28-ey3uamt0 cieacjtvru. Clvax hvw : ^,&@$~(*;?&#. Xhrx'b pt!
I love non-alphabet characters. These are : ^,&@$~(*;?&#. That's it!
--------------------------------------------------------------------
Jj becomes Ii because we use ENGLISH_SQUARE_IJ!
Sn zwlwniu Wu fwlivwg wy mwa IGYPNEO_CYMHIU_CI!
Ii becomes Ii because we use ENGLISH_SQUARE_II!
--------------------------------------------------------------------
text いろはにほへと ちりぬるを わかよたれそ つねならむ うゐのおくやま けふこえて あさきゆめみし ゑひもせす !
text きうひつけえょ をすらぺだ むぁぽだぷほ すむよたし るゐざきびりよ わじすばぬ えへきありひぁ ゑじぇもあ !
text いろはにほへと ちりぬるを わかよたれそ つねならむ うゐのおくやま けふこえて あさきゆめみし ゑひもせす !
--------------------------------------------------------------------
Θέλει αρετή και τόλμη η ελευθερία. (Ανδρέας Κάλβος)
ΣΠΌΝΜ ΊΏΙΈΛ ΤΑΑ ΨΙΣΧΗ Ό ΨΆΌΗΟΚΎΎΕ. (ΥΎΉΘΟΑΣ ΨΕΓΗΟΛ)
ΉΈΛΕΙ ΑΣΕΤΉ ΚΑΘ ΤΌΚΜΗ Ή ΕΛΈΥΘΔΡΊΏ. (ΑΝΕΡΈΆΣ ΚΑΛΒΞΤ)
'''

Bazeries

class secretpy.Bazeries

The Bazeries Cipher

decrypt(text, key, alphabet=('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'ij', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'))

Decryption method

Parameters:
  • text (string) – Text to decrypt
  • key (integer) – Decryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

encrypt(text, key, alphabet=('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'ij', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'))

Encryption method

Parameters:
  • text (string) – Text to encrypt
  • key (integer) – Encryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/python
# -*- 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)

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

'''
================================================================================
Whoever has made a voyage up the Hudson must remember the Kaatskill mountains
DUMTMCDSENRTEMVEQXMOELCCRVXDMDKWXNNMUKRDKUMYNMBPRKEEPMGNGEKWXCRWB
WHOEVERHASMADEAVOYAGEUPTHEHUDSONMUSTREMEMBERTHEKAATSKILLMOUNTAINS
================================================================================
Whoever has made a voyage up the Hudson must remember the Kaatskill mountains
DUMTMCD SEN RTEM V EQXMOE LC CRV XDMDKW XNNM UKRDKUMY NMB PRKEEPMGN GEKWXCRWB
WHOEVER HAS MADE A VOYAGE UP THE HUDSON MUST REMEMBER THE KAATSKILL MOUNTAINS
================================================================================
The quick brown fox jumps over the lazy dog!
PAB XHMDK YCUFC IWS TCRQN XBZE GMD KUML CVO!
THE QUICK BROWN FOX IUMPS OVER THE LAZY DOG!
================================================================================
Θέλει αρετή και τόλμη η ελευθερία. (Ανδρέας Κάλβος)
ΥΜΡΥΕ ΒΨΥΖΚ ΒΓΕ ΧΨΡΚΦ Υ ΒΔΥΕΚΡΖΥΜ. (ΦΣΚΥΖΠΝ ΚΕΚΣΧΑ)
ΘΕΛΕΙ ΑΡΕΤΗ ΚΑΙ ΤΟΛΜΗ Η ΕΛΕΥΘΕΡΙΑ. (ΑΝΔΡΕΑΞ ΚΑΛΒΟΞ)
'''

Beaufort

class secretpy.Beaufort

The Beaufort Cipher

decrypt(text, key, alphabet='abcdefghijklmnopqrstuvwxyz')

Decryption method

Parameters:
  • text (string) – Text to decrypt
  • key (string) – Decryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

encrypt(text, key, alphabet='abcdefghijklmnopqrstuvwxyz')

Encryption method

Parameters:
  • text (string) – Text to encrypt
  • key (string) – Encryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/python
# -*- encoding: utf-8 -*-

from secretpy import Beaufort, CryptMachine, alphabets as al
from secretpy.cmdecorators import SaveAll


def encdec(cipher, plaintext, key, alphabet=al.ENGLISH):
    print('========================================================================================')
    print(plaintext)
    enc = cipher.encrypt(plaintext, key, alphabet)
    print(enc)
    print(cipher.decrypt(enc, key, alphabet))


key = "key"
cipher = Beaufort()

plaintext = u"thequickbrownfoxjumpsoverthelazydog"
encdec(cipher, plaintext, key)

alphabet = al.GERMAN
plaintext = u"schweißgequältvomödentextzürnttypografjakob"
encdec(cipher, plaintext, key, alphabet)

alphabet = al.SWEDISH
plaintext = u"faqomschweizklövdutrångpjäxby"
encdec(cipher, plaintext, key, alphabet)

# using cryptmachine


def encdec(machine, plaintext):
    print("--------------------------------------------------------------------")
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    print(machine.decrypt(enc))


cm0 = CryptMachine(cipher, key)

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

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

'''
Output:

========================================================================================
thequickbrownfoxjumpsoverthelazydog
rxuukqiuxtqcxzknveypgwjutlrgtylgvwy
thequickbrownfoxjumpsoverthelazydog
========================================================================================
schweißgequältvomödentextzürnttypografjakob
wcrsaqlüuyoüßpdäwöhalvabvjäxvfvkjäühkßpkykj
schweißgequältvomödentextzürnttypografjakob
========================================================================================
faqomschweizklövdutrångpjäxby
feizvgiåcgzöawzsbeuqäåäjbgbjj
faqomschweizklövdutrångpjäxby
--------------------------------------------------------------------
I love non-alphabet characters. These are : ^,&@$~(*;?&#. That's it!
C tkpa lwr-yzprkdur crknyilutm. Fdagg ehg : ^,&@$~(*;?&#. Lrkl'g cl!
I love non-alphabet characters. These are : ^,&@$~(*;?&#. That's it!
--------------------------------------------------------------------
Jj becomes Ii because we use ENGLISH_SQUARE_IJ!
Bw xfclyag Bw xfcyqnu oa esa UXYOBNR_SPEKOU_BW!
Ii becomes Ii because we use ENGLISH_SQUARE_II!
--------------------------------------------------------------------
text あい だやぎへぐゆぢ
text だも むもそすぇめぇ
text あい だやぎへぐゆぢ
--------------------------------------------------------------------
I don't love non-alphabet characters. I will remove all of them: ^,&@$~(*;?&#. Great!
cbkxlnwjuxqlktjdexglwdehkcfgngciqzthgskpayztkflrgsstayr
idontlovenonalphabetcharactersiwillremoveallofthemgreat
'''

Bifid

class secretpy.Bifid

The Bifid Cipher

decrypt(text, key=None, alphabet=('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'ij', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'))

Decryption method

Parameters:
  • text (string) – Text to decrypt
  • key (integer) – Decryption key
  • alphabet (string or tuple or list) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

encrypt(text, key=None, alphabet=('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'ij', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'))

Encryption method

Parameters:
  • text (string) – Text to encrypt
  • key (integer) – Encryption key
  • alphabet (string or tuple or list) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/python
# -*- encoding: utf-8 -*-

from secretpy import Bifid, CryptMachine, alphabets as al
from secretpy.cmdecorators import UpperCase, SaveAll, Block


def encdec(machine, plaintext):
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    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"
]
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"Θέλει αρετή και τόλμη η ελευθερία. (Ανδρέας Κάλβος)"
encdec(cm, plaintext)

'''
Текст здесь, много!!!
нит4яжвыяьинтбф
текстздесьмного
----------------------------------
Defend the East Wall of the Castle!
ffyhm khycp liash adtrl hcchl blr
defendtheeastwallofthecastle
----------------------------------
flee at once
UAEOL WRINS
FLEEATONCE
----------------------------------
Θέλει αρετή και τόλμη η ελευθερία. (Ανδρέας Κάλβος)
Ζλζπρ οεπκφ ζιν μζυτυ η κλφδζγεγφ. (Πγδαργγ Ρυτακς)
Θελει αρετη και τολμη η ελευθερια. (Ανδρεας Καλβος)
----------------------------------
'''

Caesar

class secretpy.Caesar

The Caesar Cipher

decrypt(text, key=3, alphabet='abcdefghijklmnopqrstuvwxyz')

Decryption method

Parameters:
  • text (string) – Text to decrypt
  • key (integer) – Decryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

decrypted text

Return type:

string

encrypt(text, key=3, alphabet='abcdefghijklmnopqrstuvwxyz')

Encryption method

Parameters:
  • text (string) – Text to encrypt
  • key (integer) – Encryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

encrypted text

Return type:

string

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/python
# -*- encoding: utf-8 -*-

from secretpy import Caesar, CryptMachine, alphabets as al
from secretpy.cmdecorators import SaveAll, Block


def encdec(cipher, plaintext, key, alphabet=al.ENGLISH):
    print('========================================================================================')
    print(plaintext)
    enc = cipher.encrypt(plaintext, key, alphabet)
    print(enc)
    print(cipher.decrypt(enc, key, alphabet))


key = 3
cipher = Caesar()

alphabet = al.SWEDISH
plaintext = u"faqomschweizklövdutrångpjäxby"
encdec(cipher, plaintext, key, alphabet)

# using cryptmachine


def encdec(machine, plaintext):
    print("--------------------------------------------------------------------")
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    print(machine.decrypt(enc))


cm0 = CryptMachine(cipher, key)

cm = cm0
cm.set_alphabet(al.ENGLISH)
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(1)
plaintext = u"text あい だやぎへぐゆぢ"
encdec(cm, plaintext)

alphabet = u"abcdeABCDEfghijFGHIJ"
cm.set_alphabet(alphabet)
cm.set_key(3)
plaintext = u"Text aBcdeHijf"
encdec(cm, plaintext)

'''
Output:

========================================================================================
faqomschweizklövdutrångpjäxby
idtrpvfkzhlönocygxwuaqjsmbåeä
faqomschweizklövdutrångpjäxby
--------------------------------------------------------------------
I don't love non-alphabet characters. I will remove all of them: ^,&@$~(*;?&#. Great!
lgrqworyhqrqdoskdehwfkdudfwhuvlzloouhpryhdooriwkhpjuhdw
idontlovenonalphabetcharactersiwillremoveallofthemgreat
--------------------------------------------------------------------
This text is divided by blocks of length 5!
wklvw-hawlv-glylg-hgebe-orfnv-riohq-jwk
thistextisdividedbyblocksoflength
--------------------------------------------------------------------
I love non-alphabet characters. These are : ^,&@$~(*;?&#. That's it!
L oryh qrq-doskdehw fkdudfwhuv. Wkhvh duh : ^,&@$~(*;?&#. Wkdw'v lw!
I love non-alphabet characters. These are : ^,&@$~(*;?&#. That's it!
--------------------------------------------------------------------
Jj becomes Ii because we use ENGLISH_SQUARE_IJ!
Mm ehfrphv Mm ehfdxvh zh xvh HQKOMVL_VTXDUH_MM!
Ii becomes Ii because we use ENGLISH_SQUARE_II!
--------------------------------------------------------------------
text あい だやぎへぐゆぢ
text いう ぢゆぐほげよづ
text あい だやぎへぐゆぢ
--------------------------------------------------------------------
Text aBcdeHijf
TCxt dEABCaGHi
Text aBcdeHijf
'''

Caesar Progressive

class secretpy.CaesarProgressive

The Caesar Progressive Cipher

decrypt(text, key=3, alphabet='abcdefghijklmnopqrstuvwxyz')

Decryption method

Parameters:
  • text (string) – Text to decrypt
  • key (integer) – Decryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

decrypted text

Return type:

string

encrypt(text, key=3, alphabet='abcdefghijklmnopqrstuvwxyz')

Encryption method

Parameters:
  • text (string) – Text to encrypt
  • key (integer) – Encryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

encrypted text

Return type:

string

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/python
# -*- encoding: utf-8 -*-

from secretpy import CaesarProgressive, CryptMachine, alphabets as al
from secretpy.cmdecorators import SaveAll


def encdec(cipher, plaintext, key, alphabet=al.ENGLISH):
    print('========================================================================================')
    print(plaintext)
    enc = cipher.encrypt(plaintext, key, alphabet)
    print(enc)
    print(cipher.decrypt(enc, key, alphabet))


plaintext = u"thequickbrownfoxjumpsoverthelazydog"
key = 3
cipher = CaesarProgressive()

encdec(cipher, plaintext, key)

alphabet = al.GERMAN
plaintext = u"schweißgequältvomödentextzürnttypografjakob"
encdec(cipher, plaintext, key, alphabet)

alphabet = al.SWEDISH
plaintext = u"faqomschweizklövdutrångpjäxby"
encdec(cipher, plaintext, key, alphabet)

# using cryptmachine


def encdec(machine, plaintext):
    print("--------------------------------------------------------------------")
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    print(machine.decrypt(enc))


cm0 = CryptMachine(cipher, key)

plaintext = "I love non-alphabet characters. These are : ^,&@$~(*;?&#. That's it!"
cm = SaveAll(cm0)
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(1)
plaintext = u"text あい だやぎへぐゆぢ"
encdec(cm, plaintext)

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

'''
Output:

========================================================================================
thequickbrownfoxjumpsoverthelazydog
wljwbqlumdbkcvfpcohlpmuesvkiqgggmyr
thequickbrownfoxjumpsoverthelazydog
========================================================================================
schweißgequältvomödentextzürnttypografjakob
vgmülqiqpüdkäficbryägnßtqxörovwüuunzjpumxüq
schweißgequältvomödentextzürnttypografjakob
========================================================================================
faqomschweizklövdutrångpjäxby
ievutålreqvkzäqkwllkuicmhåxcå
faqomschweizklövdutrångpjäxby
--------------------------------------------------------------------
I love non-alphabet characters. These are : ^,&@$~(*;?&#. That's it!
L ptbl vxx-lxcvprvl vbvnxasesu. Wljyl iao : ^,&@$~(*;?&#. Etnh'h yk!
I love non-alphabet characters. These are : ^,&@$~(*;?&#. That's it!
--------------------------------------------------------------------
Jj becomes Ii because we use ENGLISH_SQUARE_IJ!
Mn glkwvpd Vw qutsnmz sb sre FPKPOYP_AZEMDS_XY!
Ii becomes Ii because we use ENGLISH_SQUARE_II!
--------------------------------------------------------------------
text あい だやぎへぐゆぢ
text いえ でりしぼそをは
text あい だやぎへぐゆぢ
--------------------------------------------------------------------
I don't love non-alphabet characters. I will remove all of them: ^,&@$~(*;?&#. Great!
jfrryrvdnxzznzexrtxnxdxpzcuguwncptubpybjtqcdhzodbkfrfcw
idontlovenonalphabetcharactersiwillremoveallofthemgreat
'''

Chao

class secretpy.Chao

The Chaocipher

decrypt(text, key, alphabet=None)

Decryption method

Parameters:
  • text (string) – Text to decrypt
  • key (integer) – Decryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

decrypted text

Return type:

string

encrypt(text, key, alphabet=None)

Encryption method

Parameters:
  • text (string) – Text to encrypt
  • key (integer) – Encryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

encrypted text

Return type:

string

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/python
# -*- encoding: utf-8 -*-

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:

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
DO NOT USE PC
-------------------------------
'''

Columnar Transposition

class secretpy.ColumnarTransposition

The Columnar Transposition Cipher

decrypt(text, key, alphabet='abcdefghijklmnopqrstuvwxyz')

Decryption method

Parameters:
  • text (string) – Text to decrypt
  • key (string) – Decryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

encrypt(text, key, alphabet='abcdefghijklmnopqrstuvwxyz')

Encryption method

Parameters:
  • text (string) – Text to encrypt
  • key (string) – Encryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/python
# -*- encoding: utf-8 -*-

from secretpy import ColumnarTransposition, CryptMachine, alphabets as al
from secretpy.cmdecorators import SaveAll, Block


cipher = ColumnarTransposition()
alphabet = al.GERMAN
plaintext = u"schweißgequältvomödentextzürnttypografjakob"
key = u"schlüssel"

print(plaintext)
enc = cipher.encrypt(plaintext, key, alphabet)
print(enc)
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))


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!"
encdec(cm, plaintext)

'''
schweißgequältvomödentextzürnttypografjakob
cuenfgmzghäntjwlttaeöürsqdraivxpoßotobeteyk
schweißgequältvomödentextzürnttypografjakob
================================================================================
I don't love non-alphabet characters and uppercase. I will remove all of them: ^,&@$~(*;?&#.
dnbcuemfllhsrlamtacreieeieaadseoooetpiotvhrnarlnntepwvhopaacll
idontlovenonalphabetcharactersanduppercaseiwillremoveallofthem
================================================================================
This text is divided by blocks of length 5!
hsboe iontv letid shidy ftekt siblx dcg
thistextisdividedbyblocksoflength
================================================================================
I love non-alphabet characters. These are : ^,&@$~(*;?&#. That's it!
L lhse nbc-steaaeai acrrtopatt. Nteai vhr : ^,&@$~(*;?&#. Hhoe't es!
I love non-alphabet characters. These are : ^,&@$~(*;?&#. That's it!
================================================================================
text あい だやぎへぐゆぢ
text だぐ あぎぢやゆいへ
text あい だやぎへぐゆぢ
================================================================================
ENGLISH_SQUARE_IJ doesn't change Ii to Jj because it's a transposition cipher!
NSUIECG_TBUTRP_TC elsrd'n aijcea Ns op Ei qeotnij ai't s inhghajsheoes saoiir!
ENGLISH_SQUARE_IJ doesn't change Ii to Jj because it's a transposition cipher!
'''

Four Square

class secretpy.FourSquare

The Four-Square Cipher

decrypt(text, key=None, alphabet=('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'ij', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'))

Decryption method

Parameters:
  • text (string) – Text to decrypt
  • key (tuple of two strings) – Decryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

encrypt(text, key=None, alphabet=('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'ij', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'))

Encryption method

Parameters:
  • text (string) – Text to encrypt
  • key (tuple of two strings) – Encryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/python
# -*- encoding: utf-8 -*-

from secretpy import FourSquare, CryptMachine, alphabets
from secretpy.cmdecorators import 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 = UpperCase(CryptMachine(FourSquare()))

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 a"
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
HELPMEOBIWANKENOBI
----------------------------------
Help me Obi wan Kenobi a
FYGMKYHOBXMFKKKIMDPT
HELPMEOBIWANKENOBIAZ
----------------------------------
Attack at dawn!
PMMUTBPMCUXH
ATTACKATDAWN
----------------------------------
'''

Gronsfeld

class secretpy.Gronsfeld

The Gronsfeld Cipher

decrypt(text, key, alphabet='abcdefghijklmnopqrstuvwxyz')

Decryption method

Parameters:
  • text (string) – Text to decrypt
  • key (tuple of integers) – Decryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

encrypt(text, key, alphabet='abcdefghijklmnopqrstuvwxyz')

Encryption method

Parameters:
  • text (string) – Text to encrypt
  • key (tuple of integers) – Encryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/python
# -*- encoding: utf-8 -*-

from secretpy import Gronsfeld, CryptMachine, alphabets as al
from secretpy.cmdecorators import UpperCase, Block, SaveAll


alphabet = al.GERMAN
plaintext = u"schweißgequältvomödentextzürnttypografjakob"
key = (4, 17, 9)

cipher = Gronsfeld()

print(plaintext)
enc = cipher.encrypt(plaintext, key, alphabet)
print(enc)
dec = cipher.decrypt(enc, key, alphabet)
print(dec)

#######################################################


def encdec(machine, plaintext):
    print("--------------------------------------------------------------------")
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    print(machine.decrypt(enc))


key = (14, 2, 11)
cm0 = CryptMachine(cipher, key)

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

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

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

'''
schweißgequältvomödentextzürnttypografjakob
wtqävrdxnuhfpgasßghvwxvcxmhvaüxlysxäewseöxf
schweißgequältvomödentextzürnttypografjakob
--------------------------------------------------------------------
I don't love non-alphabet characters. I will remove all of them: ^,&@$~(*;?&#. Great!
wfzbvwcxpbqyonavcmsvnvccoeestdwytzncsozjglznztvssorfglh
idontlovenonalphabetcharactersiwillremoveallofthemgreat
--------------------------------------------------------------------
This text is divided by blocks of length 5!
utpuu qevje kkwuk genfd majmt amnfz nvi
thistextisdividedbyblocksoflength
--------------------------------------------------------------------
I love non-alphabet characters. These are : ^,&@$~(*;?&#. That's it!
J xvxf zvp-bxwjbnlv dthtboagse. Ajfel csq : ^,&@$~(*;?&#. Ajbf'z ku!
I love non-alphabet characters. These are : ^,&@$~(*;?&#. That's it!
--------------------------------------------------------------------
Jj becomes Ii because we use ENGLISH_SQUARE_IJ!
Kv igdatgt Vq dfphwtr dg vem GOTSLTU_ZSVNYG_KV!
Ii becomes Ii because we use ENGLISH_SQUARE_II!
--------------------------------------------------------------------
text いろはにほへと ちりぬるを わかよたれそ つねならむ うゐのおくやま けふこえて あさきゆめみし ゑひもせす !
text うえぶねばまに てるぼゅゃ をすをつろぢ どはにぇり おゐはしごよみ ざぼぎおは くすくょるめす ゑぺれざせ !
text いろはにほへと ちりぬるを わかよたれそ つねならむ うゐのおくやま けふこえて あさきゆめみし ゑひもせす !
--------------------------------------------------------------------
Θέλει αρετή και τόλμη η ελευθερία. (Ανδρέας Κάλβος)
ΙΟΡΖΊ ΊΧΖΥΡ ΠΒΊ ΔΎΝΝΠ Μ ΖΜΞΑΊΈΆΌΒ. (ΆΧΙΣΖΊΩ ΜΒΎΉΠΤ)
ΘΈΛΕΙ ΑΡΕΤΉ ΚΑΙ ΤΌΛΜΗ Η ΕΛΕΥΘΕΡΊΑ. (ΑΝΔΠΈΑΣ ΚΆΛΒΟΣ)
'''

Keyword

class secretpy.Keyword

The Keyword Cipher

decrypt(text, key, alphabet='abcdefghijklmnopqrstuvwxyz')

Decryption method

Parameters:
  • text (string) – Text to decrypt
  • key (integer) – Decryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

encrypt(text, key, alphabet='abcdefghijklmnopqrstuvwxyz')

Encryption method

Parameters:
  • text (string) – Text to encrypt
  • key (integer) – Encryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/python
# -*- encoding: utf-8 -*-
from secretpy import Keyword, CryptMachine, alphabets as al
from secretpy.cmdecorators import UpperCase, Block, SaveAll


alphabet = al.GERMAN
plaintext = u"thequickbrownfoxjumpsoverthelazydog"
key = "queenly"

cipher = Keyword()
print(plaintext)

enc = cipher.encrypt(plaintext, key, alphabet)
print(enc)
dec = cipher.decrypt(enc, key, alphabet)
print(dec)


def encdec(machine, plaintext):
    print("--------------------------------------------------------------------")
    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)

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!
c6jirgju7iji3glb347r5b3p35r7pqcvcggp7hju73ggj8rb7h9p73r
idontlovenonalphabetcharactersiwillremoveallofthemgreat
--------------------------------------------------------------------
This text is divided by blocks of length 5!
RBCQR-7WRCQ-6CUC6-764X4-GJ5FQ-J8G7I-9RBE
THISTEXTISDIVIDEDBYBLOCKSOFLENGTH5
--------------------------------------------------------------------
I love non-alphabet characters. These are : ^,&@$~(*;?&#. That's it!
C gju7 iji-3glb347r 5b3p35r7pq. Rb7q7 3p7 : ^,&@$~(*;?&#. Rb3r'q cr!
I love non-alphabet characters. These are : ^,&@$~(*;?&#. That's it!
--------------------------------------------------------------------
Jj becomes Ii because we use ENGLISH_SQUARE_IJ!
Cc aknigkq Cc aknmtqk vk tqk KHSFCQB_QOTMPK_CC!
Ii becomes Ii because we use ENGLISH_SQUARE_II!
--------------------------------------------------------------------
text いろはにほへと ちりぬるを わかよたれそ つねならむ うゐのおくやま けふこえて あさきゆめみし ゑひもせす !
text ぎろはにほへと ちりぬるを わえよたれそ つねならむ あゐのうきやま くふけいて かさおゆめみし ゑひもせす !
text いろはにほへと ちりぬるを わかよたれそ つねならむ うゐのおくやま けふこえて あさきゆめみし ゑひもせす !
--------------------------------------------------------------------
Θέλει αρετή και τόλμη η ελευθερία. (Ανδρέας Κάλβος)
ΈΑΘΊΖ ΚΡΊΤΓ ΉΚΖ ΤΌΘΜΒ Β ΊΘΊΥΈΊΡΗΚ. (ΚΝΔΡΑΚΣ ΉΛΘΕΟΣ)
ΘΈΛΕΙ ΑΡΕΤΉ ΚΑΙ ΤΌΛΜΗ Η ΕΛΕΥΘΕΡΊΑ. (ΑΝΔΡΈΑΣ ΚΆΛΒΟΣ)
'''

MyszkowskiTransposition

class secretpy.MyszkowskiTransposition

The Myszkowski Transposition Cipher

decrypt(text, key, alphabet='abcdefghijklmnopqrstuvwxyz')

Decryption method

Parameters:
  • text (string) – Text to decrypt
  • key (integer) – Decryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

encrypt(text, key, alphabet='abcdefghijklmnopqrstuvwxyz')

Encryption method

Parameters:
  • text (string) – Text to encrypt
  • key (integer) – Encryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/python
# -*- encoding: utf-8 -*-

from secretpy import MyszkowskiTransposition, CryptMachine, alphabets as al
from secretpy.cmdecorators import UpperCase, Block, SaveAll

alphabet = al.GERMAN
plaintext = u"schweißgequältvomödentextzürnttypografjakob"
key = u"schlüssel"

cipher = MyszkowskiTransposition()
print(plaintext)

enc = cipher.encrypt(plaintext, key, alphabet)
print(enc)
dec = cipher.decrypt(enc, key, alphabet)
print(dec)


def encdec(machine, plaintext):
    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)
cm.set_key(u"κλειδί")
plaintext = u"Θέλει αρετή και τόλμη η ελευθερία. (Ανδρέας Κάλβος)"
encdec(cm, plaintext)

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

'''
schweißgequältvomödentextzürnttypografjakob
cuenfgmzghäntjwelötütrasißqvodxtrpoaobeteyk
schweißgequältvomödentextzürnttypografjakob
--------------------------------------------------------------------
I don't love non-alphabet characters. I will remove all of them: ^,&@$~(*;?&#. Great!
nahivevaclleohallroncsohdloptrrimatgitnleaeweefmtebtroa
idontlovenonalphabetcharactersiwillremoveallofthemgreat
--------------------------------------------------------------------
This text is divided by blocks of length 5!
svogt-doxes-iilnh-eddbk-ehtts-iyclt-ibf
thistextisdividedbyblocksoflength
--------------------------------------------------------------------
I love non-alphabet characters. These are : ^,&@$~(*;?&#. That's it!
V acei ncs-totreoha sslnpereer. Tielb ath : ^,&@$~(*;?&#. Aata'h th!
I love non-alphabet characters. These are : ^,&@$~(*;?&#. That's it!
--------------------------------------------------------------------
text いろはにほへと ちりぬるを わかよたれそ つねならむ うゐのおくやま けふこえて あさきゆめみし ゑひもせす !
text いほとるわれつ むのまふあ きしもろへち をかそねう おゐけこさゆひ せにぬたら やてみはりよな ゑくえめす !
text いろはにほへと ちりぬるを わかよたれそ つねならむ うゐのおくやま けふこえて あさきゆめみし ゑひもせす !
--------------------------------------------------------------------
Θέλει αρετή και τόλμη η ελευθερία. (Ανδρέας Κάλβος)
ΙΚΜΥΑ ΣΣΛΤΌ ΛΊΈ ΒΕΉΛΕ Α ΑΟΑΑΗΘΝΚΘ. (ΡΙΗΕΔΆΈ ΕΤΕΡΡΛ)
ΘΈΛΕΙ ΑΡΕΤΉ ΚΑΙ ΤΌΛΜΗ Η ΕΛΕΥΘΕΡΊΑ. (ΑΝΔΡΈΑΣ ΚΆΛΒΟΣ)
--------------------------------------------------------------------
FAQ om Schweiz: Klöv du trång pjäxby?
WNI PF ELGXZJC: KRÄS TO DAÖBM UQHVÅY?
FAQ OM SCHWEIZ: KLÖV DU TRÅNG PJÄXBY?
'''

Nihilist

class secretpy.Nihilist

The Nihilist Cipher

decrypt(text, key=None, alphabet=('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'ij', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'))

Decryption method

Parameters:
  • text (string) – Text to decrypt
  • key (integer) – Decryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

encrypt(text, key=None, alphabet=('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'ij', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'))

Encryption method

Parameters:
  • text (string) – Text to encrypt
  • key (integer) – Encryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/python
# -*- encoding: utf-8 -*-

from secretpy import Nihilist, CryptMachine, alphabets as al


def encdec(cipher, plaintext, key, alphabet=al.ENGLISH):
    print(plaintext)
    enc = cipher.encrypt(plaintext, key, alphabet)
    print(enc)
    print(cipher.decrypt(enc, key, alphabet))
    print("----------------------------------")


key = "english"
plaintext = u"thequickbrownfoxjumpsoverthelazydog"
cipher = Nihilist()
encdec(cipher, plaintext, key)


def encdec(machine, plaintext):
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    print(machine.decrypt(enc))
    print("----------------------------------")


key = "mykey"
cm = CryptMachine(cipher, key)

alphabet = (
    u"z", u"e", u"b", u"r", u"a",
    u"s", u"c", u"d", u"f", u"g",
    u"h", u"ij", u"k", u"l", u"m",
    u"n", u"o", u"p", u"q", u"t",
    u"u", u"v", u"w", u"x", u"y"
)
cm.set_alphabet(alphabet)
plaintext = u"Waltz, bad nymph, for quick jigs vex."
encdec(cm, plaintext)

alphabet = (
    u"a", u"b", u"c", u"d", u"e", u"f",
    u"g", u"h", u"i", u"j", u"k", u"l",
    u"m", u"n", u"o", u"p", u"q", u"r",
    u"s", u"t", u"u", u"v", u"w", u"x",
    u"y", u"z", u"0", u"1", u"2", u"3",
    u"4", u"5", u"6", u"7", u"8", u"9",
)
cm.set_alphabet(alphabet)
key = "freedom"
cm.set_key(key)
plaintext = u"Meet thursday 2300hr!"
encdec(cm, plaintext)

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)
key = u"ключ"
cm.set_key(key)
plaintext = u"текст"
encdec(cm, plaintext)

alphabet = al.GREEK
cm.set_alphabet(alphabet)
plaintext = u"ΠΙΝΑΚΑΣ"
encdec(cm, plaintext)

'''
Output:

thequickbrownfoxjumpsoverthelazydog
57 54 36 61 66 64 35 40 44 57 59 68 73 38 48 78 45 69 54 75 63 48 76 36 62 65 63 37 41 43 73 77 37 74 43
thequickbrownfoxjumpsoverthelazydog
----------------------------------
Waltz, bad nymph, for quick jigs vex.
88 70 67 57 66 48 70 56 53 110 70 98 64 36 97 49 99 84 44 77 68 87 65 37 76 87 67 87
waltzbadnymphforquickiigsvex
----------------------------------
Meet thursday 2300hr!
47 51 30 57 56 55 74 52 77 29 26 65 88 87 69 89 37 51
meetthursday2300hr
----------------------------------
текст
60 41 79 80 60
текст
----------------------------------
ΠΙΝΑΚΑΣ
95 78 87 65 79 65 97
πινακασ
----------------------------------
'''

Playfair

class secretpy.Playfair

The Playfair Cipher

decrypt(text, key='', alphabet=('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'ij', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'))

Decryption method

Parameters:
  • text (string) – Text to decrypt
  • key (integer) – Decryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, ENGLISH_SQUARE_IJ is used
Returns:

text

Return type:

string

encrypt(text, key='', alphabet=('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'ij', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'))

Encryption method

Parameters:
  • text (string) – Text to encrypt
  • key (integer) – Encryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, ENGLISH_SQUARE_IJ is used
Returns:

text

Return type:

string

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/python
# -*- 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", u"h",
    u"k", u"n", u"o", u"q", u"s",
    u"t", u"u", u"v", u"w", u"z",
]
cm.set_alphabet(alphabet)
plaintext = u"Hide the gold in the tree stump"
encdec(cm, plaintext)

plaintext = "sometext"
encdec(cm, plaintext)

plaintext = "this is a secret message"
encdec(cm, plaintext)

'''
Hide the gold in the tree stump
BMODZBXDNABEKUDMUIXMMOUVIF
HIDETHEGOLDINTHETREESTUMP
----------------------------------
sometext
KQIXVIIW
SOMETEXT
----------------------------------
this is a secret message
ZBMKMKFORDEXZIMOOFDX
THISISASECRETMESSAGE
----------------------------------
'''

Polybius

class secretpy.Polybius

The Polybius Cipher

decrypt(text, key=None, alphabet=('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'ij', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'))

Decryption method

Parameters:
  • text (string) – Text to decrypt
  • key (integer) – Decryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

encrypt(text, key=None, alphabet=('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'ij', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'))

Encryption method

Parameters:
  • text (string) – Text to encrypt
  • key (integer) – Encryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/python
# -*- encoding: utf-8 -*-

from secretpy import Polybius, CryptMachine, alphabets as al
from secretpy.cmdecorators import SaveAll


def encdec(machine, plaintext):
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    dec = machine.decrypt(enc)
    print(dec)
    print("----------------------------------")


key = "mykey"
cm = CryptMachine(Polybius(), key)

plaintext = u"Defend the east wall of the castle"
encdec(cm, plaintext)

cm = SaveAll(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"
]
cm.set_alphabet(alphabet)
encdec(cm, plaintext)

plaintext = "thisisasecretmessage"
encdec(cm, plaintext)

cm.set_alphabet(al.GREEK)
cm.set_key(u"πινακασ")
plaintext = u"Ξεσκεπάζω την ψυχοφθόρα σας βδελυγμία."
encdec(cm, plaintext)

'''
Defend the east wall of the castle
22142314332243251414154243461532323423432514211542433214
defendtheeastwallofthecastle
----------------------------------
Defend the east wall of the castle
341433 143 1345 4211 41 424 4454512425253233542114422444542514
defend the east wall of the castle
----------------------------------
thisisasecretmessage
5421554455442444144241145411144444242314
thisisasecretmessage
----------------------------------
Ξεσκεπάζω την ψυχοφθόρα σας βδελυγμία.
422516152 511 213161513 213 565255435.434444514161446222425365223413514
ξεσκεπάζω την ψυχοφθόρα σας βδελυγμία.
----------------------------------
'''

Porta

class secretpy.Porta

The Porta Cipher

decrypt(text, key, alphabet='abcdefghijklmnopqrstuvwxyz')

Decryption method

Parameters:
  • text (string) – Text to decrypt
  • key (string) – Decryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

encrypt(text, key, alphabet='abcdefghijklmnopqrstuvwxyz')

Encryption method

Parameters:
  • text (string) – Text to encrypt
  • key (string) – Encryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/python
# -*- encoding: utf-8 -*-
from secretpy import Porta, CryptMachine, alphabets as al
from secretpy.cmdecorators import UpperCase, Block, SaveAll


alphabet = al.GERMAN
plaintext = u"schweißgequältvomödentextzürnttypografjakob"
key = u"schlüssel"

cipher = Porta()
print(plaintext)

enc = cipher.encrypt(plaintext, key, alphabet)
print(enc)
dec = cipher.decrypt(enc, key, alphabet)
print(dec)

#######################################################


def encdec(machine, plaintext):
    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("keys")
plaintext = "I don't love non-alphabet characters. I will remove all of them: ^,&@$~(*;?&#. Great!"
encdec(cm, plaintext)

cm = Block(cm, length=4, 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)

'''
'''

Rot13

class secretpy.Rot13

The Rot13 Cipher (Half)

decrypt(text, key=None, alphabet='abcdefghijklmnopqrstuvwxyz')

Decryption method

Parameters:
  • text (string) – Text to decrypt
  • key (integer) – not used
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

encrypt(text, key=None, alphabet='abcdefghijklmnopqrstuvwxyz')

Encryption method

Parameters:
  • text (string) – Text to encrypt
  • key (integer) – not used
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/python
# -*- encoding: utf-8 -*-

from secretpy import Rot13, CryptMachine, alphabets as al
from secretpy.cmdecorators import SaveAll, Block


def encdec(machine, plaintext):
    print("----------------------------------")
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    dec = machine.decrypt(enc)
    print(dec)


cm = CryptMachine(Rot13())

plaintext = u"The quick brown fox jumps over the lazydog."
encdec(cm, plaintext)

cm = SaveAll(cm)

plaintext = u"Why did the chicken cross the road? Gb trg gb gur bgure fvqr"
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.
----------------------------------
FAQ om Schweiz: Klöv du trång pjäxby?
UPB oä Drwhtxk: Zång sf eclöv aymiqj?
FAQ om Schweiz: Klöv du trång pjäxby?
----------------------------------
あいうえおかきくけこがぎぐげごさしすせそざじずぜぞたちつてとだぢづでどなにぬねのはひふへほばびぶべぼぱぴぷぺぽまみむめもやゆよらりるれろわをんゃゅょぁぇ
ねのはひふへほばびぶべぼぱぴぷぺぽまみむめもやゆよらりるれろわをんゃゅょぁぇあいうえおかきくけこがぎぐげごさしすせそざじずぜぞたちつてとだぢづでどなにぬ
あいうえおかきくけこがぎぐげごさしすせそざじずぜぞたちつてとだぢづでどなにぬねのはひふへほばびぶべぼぱぴぷぺぽまみむめもやゆよらりるれろわをんゃゅょぁぇ
----------------------------------
あいうえおかきくけこがぎぐげごさしすせそざじずぜぞたちつてとだぢづでどなにぬねのはひふへほばびぶべぼぱぴぷぺぽまみむめもやゆよらりるれろわをんゃゅょぁぇ
ねのはひふ へほばびぶ べぼぱぴぷ ぺぽまみむ めもやゆよ らりるれろ わをんゃゅ ょぁぇあい うえおかき くけこがぎ ぐげごさし すせそざじ ずぜぞたち つてとだぢ づでどなに ぬ
あいうえおかきくけこがぎぐげごさしすせそざじずぜぞたちつてとだぢづでどなにぬねのはひふへほばびぶべぼぱぴぷぺぽまみむめもやゆよらりるれろわをんゃゅょぁぇ
'''

Rot5

class secretpy.Rot5

The Rot5 Cipher

decrypt(text, key=None, alphabet=None)

Decryption method

Parameters:
  • text (string) – Text to decrypt
  • key (integer) – Decryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

encrypt(text, key=None, alphabet=None)

Encryption method

Parameters:
  • text (string) – Text to encrypt
  • key (integer) – Encryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/python
# -*- encoding: utf-8 -*-

from secretpy import Rot5, alphabets, CryptMachine


def encdec(machine, plaintext):
    print("----------------------------------")
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    dec = machine.decrypt(enc)
    print(dec)


cm = CryptMachine(Rot5())

plaintext = "My text " + alphabets.DECIMAL + " your text"
encdec(cm, plaintext)

'''
----------------------------------
My text 0123456789 your text
5678901234
0123456789
'''

Rot18

class secretpy.Rot18

The Rot18 Cipher

decrypt(text, key=None, alphabet=None)

Decryption method

Parameters:
  • text (string) – Text to decrypt
  • key (integer) – is not used
  • alphabet (string) – is not used
Returns:

text

Return type:

string

encrypt(text, key=None, alphabet=None)

Encryption method

Parameters:
  • text (string) – Text to encrypt
  • key (integer) – is not used
  • alphabet (string) – is not used
Returns:

text

Return type:

string

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/python
# -*- encoding: utf-8 -*-

from secretpy import Rot18, CryptMachine
from secretpy.cmdecorators import SaveAll, UpperCase, Block


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
themanhas536dogshowmanydogsdoyouhave
----------------------------------
The man has 536 dogs! How many dogs do you have?
Gur zna unf 081 qbtf! Ubj znal qbtf qb lbh unir?
The man has 536 dogs! How many dogs do you have?
----------------------------------
The man has 536 dogs! How many dogs do you have?
GUR ZNA UNF 081 QBTF! UBJ ZNAL QBTF QB LBH UNIR?
THE MAN HAS 536 DOGS! HOW MANY DOGS DO YOU HAVE?
'''

Rot47

class secretpy.Rot47

The Rot47 Cipher

decrypt(text, key=None, alphabet=None)

Decryption method

Parameters:
  • text (string) – Text to decrypt
  • key (integer) – Decryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

encrypt(text, key=None, alphabet=None)

Encryption method

Parameters:
  • text (string) – Text to encrypt
  • key (integer) – Encryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/python
# -*- encoding: utf-8 -*-

from secretpy import Rot47, CryptMachine
from secretpy.cmdecorators import SaveAll


def encdec(machine, plaintext):
    print("----------------------------------")
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    dec = machine.decrypt(enc)
    print(dec)


plaintext = u"The Quick Brown Fox Jumps Over The Lazy Dog."

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

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

'''
----------------------------------
The Quick Brown Fox Jumps Over The Lazy Dog.
%96"F:4<qC@H?u@IyF>AD~G6C%96{2KJs@8]
TheQuickBrownFoxJumpsOverTheLazyDog.
----------------------------------
The Quick Brown Fox Jumps Over The Lazy Dog.
%96 "F:4< qC@H? u@I yF>AD ~G6C %96 {2KJ s@8]
The Quick Brown Fox Jumps Over The Lazy Dog.
'''

Scytale

class secretpy.Scytale

The Scytale Cipher

decrypt(text, key, alphabet=None)

Decryption method

Parameters:
  • text (string) – Text to decrypt
  • key (integer) – Decryption key - Number of windings
  • alphabet – Alphabet is not used
Returns:

decrypted text

Return type:

string

encrypt(text, key, alphabet=None)

Encryption method

Parameters:
  • text (string) – Text to encrypt
  • key (integer) – Encryption key - Number of windings
  • alphabet – Alphabet is not used
Returns:

encrypted text

Return type:

string

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/python
# -*- encoding: utf-8 -*-

from secretpy import Scytale, CryptMachine, alphabets as al
from secretpy.cmdecorators import UpperCase, Block, SaveAll


alphabet = al.GERMAN
plaintext = u"thequickbrownfoxjumpsoverthelazydog"
key = 3
cipher = Scytale()

print(plaintext)
enc = cipher.encrypt(plaintext, key, alphabet)
print(enc)
dec = cipher.decrypt(enc, key, alphabet)
print(dec)


def encdec(machine, plaintext):
    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"Θέλει αρετή και τόλμη η ελευθερία. (Ανδρέας Κάλβος)"
encdec(cm, plaintext)

'''
thequickbrownfoxjumpsoverthelazydog
tqcrnxmorezohukofjpvtlygeibwousehad
thequickbrownfoxjumpsoverthelazydog
--------------------------------------------------------------------
I don't love non-alphabet characters. I will remove all of them: ^,&@$~(*;?&#. Great!
inonahehaeilevlfertdtvolatacrwlmeltmeolenpbcrtsiroaohga
idontlovenonalphabetcharactersiwillremoveallofthemgreat
--------------------------------------------------------------------
This text is divided by blocks of length 5!
TSXSV-EYOSL-G5HTT-DIDBC-OETIE-IIDBL-KFNH
THISTEXTISDIVIDEDBYBLOCKSOFLENGTH5
--------------------------------------------------------------------
I love non-alphabet characters. These are : ^,&@$~(*;?&#. That's it!
I vola tac-rheeaile npbcrtseat. Ttona heh : ^,&@$~(*;?&#. Aets'r hs!
I love non-alphabet characters. These are : ^,&@$~(*;?&#. That's it!
--------------------------------------------------------------------
text いろはにほへと ちりぬるを わかよたれそ つねならむ うゐのおくやま けふこえて あさきゆめみし ゑひもせす !
text いにとぬわたつ らのやふて きみもろほち るかれねむ おゐまこあゆし せはへりを よそなうくけえ ゑさめひす !
text いろはにほへと ちりぬるを わかよたれそ つねならむ うゐのおくやま けふこえて あさきゆめみし ゑひもせす !
--------------------------------------------------------------------
Θέλει αρετή και τόλμη η ελευθερία. (Ανδρέας Κάλβος)
ΘΕΡΉΙ ΛΗΕΕΑ ΔΑΆ ΟΈΙΕΚ Τ ΜΕΥΡΑΡΣΛΣ. (ΛΑΤΑΌΗΛ ΘΊΝΈΚΒ)
ΘΈΛΕΙ ΑΡΕΤΉ ΚΑΙ ΤΌΛΜΗ Η ΕΛΕΥΘΕΡΊΑ. (ΑΝΔΡΈΑΣ ΚΆΛΒΟΣ)
'''

Simple Substitution

class secretpy.SimpleSubstitution

The Simple Substitution Cipher

decrypt(text, key, alphabet='abcdefghijklmnopqrstuvwxyz')

Decryption method

Parameters:
  • text (string) – Text to decrypt
  • key (string) – Decryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

encrypt(text, key, alphabet='abcdefghijklmnopqrstuvwxyz')

Encryption method

Parameters:
  • text (string) – Text to encrypt
  • key (string) – Encryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/python
# -*- encoding: utf-8 -*-

from secretpy import SimpleSubstitution, CryptMachine, alphabets as al
from secretpy.cmdecorators import Block, SaveAll


cipher = SimpleSubstitution()
alphabet = al.GERMAN
plaintext = u"schweißgequältvomödentextzürnttypografjakob"
key = u"fwxyäöeßüdabcglmnpqrstuvhjoikz"

print(plaintext)
enc = cipher.encrypt(plaintext, key, alphabet)
print(enc)
dec = cipher.decrypt(enc, key, alphabet)
print(dec)

#######################################################


def encdec(machine, plaintext):
    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("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"
key = u"dABDFIJEfgCHabchijG"
cm.set_alphabet(alphabet)
cm.set_key(key)
plaintext = u"Text aBcdHijf"
encdec(cm, plaintext)

'''
schweißgequältvomödentextzürnttypografjakob
qxßuäüzeänsobrtlciyägrävrjkpgrrhmlepfödfalw
schweißgequältvomödentextzürnttypografjakob
--------------------------------------------------------------------
I don't love non-alphabet characters. I will remove all of them: ^,&@$~(*;?&#. Great!
kbnmxfnpcmnmyftjyzcxajyvyaxcvwkqkffvclnpcyffnhxjclivcyx
idontlovenonalphabetcharactersiwillremoveallofthemgreat
--------------------------------------------------------------------
This text is divided by blocks of length 5!
xjkwx-crxkw-bkpkb-cbzsz-fnaew-nhfcm-ixj
thistextisdividedbyblocksoflength
--------------------------------------------------------------------
I love non-alphabet characters. These are : ^,&@$~(*;?&#. That's it!
K fnpc mnm-yftjyzcx ajyvyaxcvw. Xjcwc yvc : ^,&@$~(*;?&#. Xjyx'w kx!
I love non-alphabet characters. These are : ^,&@$~(*;?&#. That's it!
--------------------------------------------------------------------
Jj becomes Ii because we use ENGLISH_SQUARE_IJ!
Vv glaqolw Vv glanywl dl ywl LPTMVWU_WIYNKL_VV!
Ii becomes Ii because we use ENGLISH_SQUARE_II!
--------------------------------------------------------------------
Text aBcdHijf
Text dIBDiabg
Text aBcdHijf
'''

Three Square

class secretpy.ThreeSquare

The Three Square Cipher

decrypt(text, key, alphabet=('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'ij', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'))

Decryption method

Parameters:
  • text (string) – Text to decrypt
  • key (tuple of 3 strings) – Decryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

encrypt(text, key, alphabet=('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'ij', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'))

Encryption method

Parameters:
  • text (string) – Text to encrypt
  • key (tuple of 3 strings) – Encryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/python
# -*- encoding: utf-8 -*-

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)

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!!!
Actuac vs ihctz!!!ddnwosuz
Attack at dawns!!!z
================================================================================
Θέλει αρετή και τόλμη η ελευθερία. (Ανδρέας Κάλβος)
Ινιχι ιιλβρ σετ τβκλβ θ κσωμεμογο. (Γκνιιπυ Οζεσθλ)ζπγξδεσξληςπλαβιβηνετψ
Θελει αρετη και τολμη η ελευθερια. (Ανδρεας Καλβος)ω
================================================================================
Θέλει αρετή και τόλμη η ελευθερία. (Ανδρέας Κάλβος)
ΠΝΚΛΙ ΕΙΛΒΒ ΣΙΗΤΓ ΜΛΓΑΚ ΣΔΜΕΚ ΟΗΩΓΙ ΣΙΚΠΥ ΜΖΕΠΥ ΛΒΠΓΘ ΤΕΡΞΛ ΖΕΠΕΘ ΒΚΚΗΞ ΞΤΨ
ΘΕΛΕΙΑΡΕΤΗΚΑΙΤΟΛΜΗΗΕΛΕΥΘΕΡΙΑΑΝΔΡΕΑΣΚΑΛΒΟΣΩ
'''

Trifid

class secretpy.Trifid

The Trifid Cipher

decrypt(text, key=None, alphabet=None)

Decryption method

Parameters:
  • text (string) – Text to decrypt
  • key (integer) – Decryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English with ‘.’ is used
Returns:

text

Return type:

string

encrypt(text, key=None, alphabet=None)

Encryption method

Parameters:
  • text (string) – Text to encrypt
  • key (integer) – Encryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English with ‘.’ is used
Returns:

text

Return type:

string

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/python
# -*- encoding: utf-8 -*-

from secretpy import Trifid, CryptMachine
from secretpy.cmdecorators import SaveAll


def encdec(machine, plaintext):
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    print(machine.decrypt(enc))
    print("----------------------------------")


key = 5
cm = CryptMachine(Trifid(), key)

alphabet = u"epsducvwym.zlkxnbtfgorijhaq"  # 27 characters
cm.set_alphabet(alphabet)

plaintext = u"defendtheeastwallofthecastle"
encdec(cm, plaintext)

cm1 = cm
alphabet = (
    u"aåä", u"b", u"c",
    u"d", u"e", u"f",
    u"g", u"h", u"i",

    u"j", u"k", u"l",
    u"m", u"n", u"oö",
    u"p", u"q", u"r",

    u"s", u"t", u"u",
    u"v", u"w", u"x",
    u"y", u"z", u"+",
)
cm1.set_alphabet(alphabet)

plaintext = u"Flygande bäckasiner söka hwila på mjuka tuvor!"
encdec(cm1, plaintext)

cm2 = SaveAll(cm)
alphabet = "felixmardstbcghjknopquvwyz+"
cm2.set_alphabet(alphabet)

plaintext = u"Aide-toi, le ciel t'aidera"
encdec(cm2, plaintext)


'''
defendtheeastwallofthecastle
suefecphsegyyjiximfofocejlrf
defendtheeastwallofthecastle
----------------------------------
Flygande bäckasiner söka hwila på mjuka tuvor!
fbiiajbmdmdsazckwpnujshvokdgpaqgackzkri
flygandebackasinersokahwilapamjukatuvor
----------------------------------
Aide-toi, le ciel t'aidera
Fmjf-voi, ss uftf p'ufeqqc
Aide-toi, le ciel t'aidera
----------------------------------
'''

Two Square

class secretpy.TwoSquare

The Two-Square Cipher, also called Double Playfair

decrypt(text, key=None, alphabet=('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'ij', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'))

Decryption method

Parameters:
  • text (string) – Text to decrypt
  • key (integer) – Decryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

encrypt(text, key=None, alphabet=('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'ij', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'))

Encryption method

Parameters:
  • text (string) – Text to encrypt
  • key (integer) – Encryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/python
# -*- encoding: utf-8 -*-

from secretpy import TwoSquare, CryptMachine, alphabets
from secretpy.cmdecorators import 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 = 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
HELPMEOBIWANKENOBIYZ
----------------------------------
'''

Vic

class secretpy.Vic

The Vic Cipher

decrypt(text, key=None, alphabet=('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'ij', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'))

Decryption method

Parameters:
  • text (string) – Text to decrypt
  • key (number string) – Decryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

encrypt(text, key=None, alphabet=('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'ij', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'))

Encryption method

Parameters:
  • text (string) – Text to encrypt
  • key (number string) – Encryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/python
# -*- encoding: utf-8 -*-

from secretpy import Vic, CryptMachine
from secretpy.cmdecorators import SaveAll


def encdec(machine, plaintext):
    print("----------------------------------")
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    print(machine.decrypt(enc))


key = "0452"
cm = SaveAll(CryptMachine(Vic(), key))
alphabet = [
    u"e", u"t", u"", u"a", u"o", u"n", u"", u"r", u"i", u"s",
    u"b", u"c", u"d", u"f", u"g", u"h", u"j", u"k", u"l", u"m",
    u"p", u"q", u"/", u"u", u"v", u"w", u"x", u"y", u"z", u".",
]
plaintext = u"Attack at dawn!"
cm.set_alphabet(alphabet)
encdec(cm, plaintext)

'''
Output:

----------------------------------
Attack at dawn!
Anwhrs an roae!er
Attack at dawn!
'''

Vigenere

class secretpy.Vigenere

The Vigenere Cipher

decrypt(text, key, alphabet='abcdefghijklmnopqrstuvwxyz')

Decryption method

Parameters:
  • text (string) – Text to decrypt
  • key (string) – Decryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

encrypt(text, key, alphabet='abcdefghijklmnopqrstuvwxyz')

Encryption method

Parameters:
  • text (string) – Text to encrypt
  • key (string) – Encryption key
  • alphabet (string) – Alphabet which will be used, if there is no a value, English is used
Returns:

text

Return type:

string

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/python
# -*- encoding: utf-8 -*-

from secretpy import Vigenere, CryptMachine, alphabets as al
from secretpy.cmdecorators import UpperCase, Block, SaveAll

alphabet = al.GERMAN
plaintext = u"schweißgequältvomödentextzürnttypografjakob"
key = u"schlüssel"

cipher = Vigenere()
print(plaintext)

enc = cipher.encrypt(plaintext, key, alphabet)
print(enc)
dec = cipher.decrypt(enc, key, alphabet)
print(dec)


def encdec(machine, plaintext):
    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("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)

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

'''
schweißgequältvomödentextzürnttypografjakob
geodcärkpewdwrjcqivguaclhßjfpäawdcküshqlict
schweißgequältvomödentextzürnttypografjakob
--------------------------------------------------------------------
I don't love non-alphabet characters. I will remove all of them: ^,&@$~(*;?&#. Great!
shmfdpmnormfkpnzkfclmlyjkgrwbwgospjjoqmnoejdyjrzoqejoer
idontlovenonalphabetcharactersiwillremoveallofthemgreat
--------------------------------------------------------------------
This text is divided by blocks of length 5!
dlgkd-ivlsw-bafmb-wnfwt-vsacc-sddor-elr
thistextisdividedbyblocksoflength
--------------------------------------------------------------------
I love non-alphabet characters. These are : ^,&@$~(*;?&#. That's it!
S pmno rmf-kpnzkfcl mlyjkgrwbw. Rzowc sbi : ^,&@$~(*;?&#. Rzkx'q ad!
I love non-alphabet characters. These are : ^,&@$~(*;?&#. That's it!
--------------------------------------------------------------------
Jj becomes Ii because we use ENGLISH_SQUARE_IJ!
Sn zwmskwb Ng togymbi uw dwc WWLIABM_QHDEPW_SN!
Ii becomes Ii because we use ENGLISH_SQUARE_II!
--------------------------------------------------------------------
text いろはにほへと ちりぬるを わかよたれそ つねならむ うゐのおくやま けふこえて あさきゆめみし ゑひもせす !
text きうばぶぼぽど ぬをべんお ょしろにゃだ づぼはぁよ げゐほさぐゃや そぶざけの かちぎゅらろじ ゑぷりとず !
text いろはにほへと ちりぬるを わかよたれそ つねならむ うゐのおくやま けふこえて あさきゆめみし ゑひもせす !
--------------------------------------------------------------------
Θέλει αρετή και τόλμη η ελευθερία. (Ανδρέας Κάλβος)
ΣΠΌΝΜ ΊΒΌΨΠ ΞΊΤ ΈΤΥΌΠ Ρ ΌΌΝΨΣΟΓΞΙ. (ΔΧΞΓΙΙΦ ΥΛΧΖΨΦ)
ΉΈΛΕΙ ΑΡΕΤΉ ΚΑΙ ΤΌΛΜΗ Η ΕΛΕΥΘΕΡΊΑ. (ΑΝΔΡΈΑΣ ΚΆΛΒΟΣ)
'''

Zigzag

class secretpy.Zigzag

The Zigzag Cipher (Rail-Fence)

decrypt(text, key, alphabet=None)

Decryption method

Parameters:
  • text (string) – Text to decrypt
  • key (integer) – Decryption key
  • alphabet (string) – unused
Returns:

text

Return type:

string

encrypt(text, key, alphabet=None)

Encryption method

Parameters:
  • text (string) – Text to encrypt
  • key (integer) – Encryption key
  • alphabet (string) – unused
Returns:

text

Return type:

string

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/python
# -*- encoding: utf-8 -*-

from secretpy import Zigzag


plaintext = u"thequickbrownfoxjumpsoverthelazydog"
plaintext = u"thequick"
key = 3

chipher = Zigzag()
print(plaintext)

enc = chipher.encrypt(plaintext, key)
print(enc)
dec = chipher.decrypt(enc, key)
print(dec)

#######################################################

print("----------------------------------")

plaintext = u"wearediscoveredfleeatonce"

print(plaintext)
enc = chipher.encrypt(plaintext, key)
print(enc)
dec = chipher.decrypt(enc, key)
print(dec)

#######################################################

print("----------------------------------")

plaintext = u"defendtheeastwallofthecastle"
key = 4

print(plaintext)
enc = chipher.encrypt(plaintext, key)
print(enc)
dec = chipher.decrypt(enc, key)
print(dec)

'''
thequickbrownfoxjumpsoverthelazydog
tubnjsrldhqikrwfxupoeteayoecoomvhzg
thequickbrownfoxjumpsoverthelazydog
----------------------------------
wearediscoveredfleeatonce
wecrlteerdsoeefeaocaivden
wearediscoveredfleeatonce
----------------------------------
defendtheeastwallofthecastle
dttfsedhswotatfneaalhcleelee
defendtheeastwallofthecastle
'''