Skip to content

Commit 0b70b83

Browse files
committed
Added __examples__ to each codec for automated tests
1 parent 22d65b0 commit 0b70b83

20 files changed

Lines changed: 198 additions & 28 deletions

File tree

codext/base/ascii85.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
from ..__common__ import *
1515

1616

17+
__examples__ = {'enc(ascii85|ascii-85|ascii_85)': {'this is a test': "FD,B0+DGm>@3BZ'F*%"}}
18+
19+
1720
if PY3:
1821
def ascii85_encode(input, errors='strict'):
1922
return base64.a85encode(b(input)), len(input)

codext/crypto/bacon.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
from ..__common__ import *
1313

1414

15+
__examples__ = {
16+
'enc(bacon|bacon_cipher|baconian-cipher|bacon-ab|bacon-AB)': {
17+
'this is a test': "baaba aabbb abaaa baaab abaaa baaab aaaaa baaba aabaa baaab baaba",
18+
},
19+
'enc(bacon-01)': {'this is a test': "10010 00111 01000 10001 01000 10001 00000 10010 00100 10001 10010"},
20+
}
21+
22+
1523
ENCMAP = {
1624
'A': "aaaaa", 'B': "aaaab", 'C': "aaaba", 'D': "aaabb", 'E': "aabaa", 'F': "aabab", 'G': "aabba", 'H': "aabbb",
1725
'I': "abaaa", 'J': "abaaa", 'K': "abaab", 'L': "ababa", 'M': "ababb", 'N': "abbaa", 'O': "abbab", 'P': "abbba",
@@ -20,5 +28,5 @@
2028
}
2129

2230

23-
add_map("bacon", ENCMAP, sep=" ", ignore_case="encode", pattern=r"bacon(?:(?:ian)?[-_]cipher)?([\-_].{2})?$")
31+
add_map("bacon", ENCMAP, sep=" ", ignore_case="both", pattern=r"bacon(?:(?:ian)?[-_]cipher)?([\-_].{2})?$")
2432

codext/crypto/barbie.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@
1515
from ..__common__ import *
1616

1717

18+
__examples__ = {
19+
'enc(barbie)': None,
20+
'enc(barbie1)': {'\r': None},
21+
'enc(barbie1|barbie_1|barbie-1)': {'this is a test': "hstf tf i hafh"},
22+
'enc(barbie2|barbie_2|barbie-2)': {'this is a test': "sfhp hp t sips"},
23+
'enc(barbie3|barbie_3|barbie-3)': {'this is a test': "fpsu su h ftuf"},
24+
'enc(barbie4|barbie_4|barbie-4)': {'this is a test': "pufq fq s phqp"},
25+
}
26+
27+
1828
STD = [
1929
"abcdefghijklmnopqrstuvABCDEFGHIJKLMNOPQRSTUVWXYZ0123456 \n\t",
2030
"icolapxstvybjeruknfhqg>FAUTCYOLVJDZINQKSEHG<.1PB5234067 \n\t",

codext/crypto/rot.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
from ..__common__ import *
1313

1414

15+
__examples__ = {
16+
'enc(rot0|rot--10|rot100)': None,
17+
'enc(rot1|rot-1|rot_1|ROT1|ROT-1|ROT_1)': {'this is a test': "uijt jt b uftu"},
18+
'enc(rot3)': {'this is a test': "wklv lv d whvw"},
19+
}
20+
21+
1522
def _rotn(text, n=13):
1623
n = n % 26
1724
t = maketrans(LC + UC, LC[n:] + LC[:n] + UC[n:] + UC[:n])

codext/crypto/scytale.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
from ..__common__ import *
1313

1414

15+
__examples__ = {
16+
'enc(scytale0|scytale--10|scytale01)': None,
17+
'enc(scytale2|scytale-2|scytale_2)': {'this is a test': "ti satshsi et"},
18+
'enc(scytale5|scytale-5|scytale_5)': {'this is a test': "tithsei ssat "},
19+
}
20+
21+
1522
PADDING_CHAR = ""
1623

1724

codext/crypto/shift.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
from ..__common__ import *
1111

1212

13+
__examples__ = {
14+
'enc(shift0|shift--10|shift256)': None,
15+
'enc(shift1|SHIFT_1|shift-1)': {'this is a test': "uijt!jt!b!uftu"},
16+
'enc(shift9|shift_9|SHIFT-9)': {'this is a test': "}qr|)r|)j)}n|}"},
17+
}
18+
19+
1320
def ord_shift_decode(i):
1421
return ord_shift_encode(-i)
1522

@@ -21,6 +28,5 @@ def encode(text, errors="strict"):
2128
return encode
2229

2330

24-
add("shift", ord_shift_encode, ord_shift_decode,
25-
r"(?i)(?:ord(?:inal)?[-_]?)?shift[-_]?([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$")
31+
add("shift", ord_shift_encode, ord_shift_decode, r"(?i)shift[-_]?([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$")
2632

codext/crypto/xor.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010
from ..__common__ import *
1111

1212

13+
__examples__ = {
14+
'enc(xor0|xor--10|xor256|xor300)': None,
15+
'enc(xor3|xor-3|xor_3)': {'this is a test': "wkjp#jp#b#wfpw"},
16+
'enc(xor3|xor-3|xor_3)': {'wkjp#jp#b#wfpw': "this is a test"},
17+
'enc(XOR6|XOR-6|XOR_6)': {'this is a test': "rnou&ou&g&rcur"},
18+
}
19+
20+
1321
def _xorn(text, n=1):
1422
return "".join(chr(ord(c) ^ (n % 256)) for c in text)
1523

codext/languages/braille.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
from ..__common__ import *
1111

1212

13+
__examples__ = {
14+
'enc(braille)': {'this is a test': "⠞⠓⠊⠎⠀⠊⠎⠀⠁⠀⠞⠑⠎⠞"},
15+
}
16+
17+
1318
ENCMAP = {
1419
# digits
1520
'0': '⠴', '1': '⠂', '2': '⠆', '3': '⠒', '4': '⠲', '5': '⠢', '6': '⠖', '7': '⠶', '8': '⠦', '9': '⠔',

codext/languages/morse.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
from ..__common__ import *
1111

1212

13+
__examples__ = {
14+
'enc(morse|morse/-.)': {'this is a test': "- .... .. ... / .. ... / .- / - . ... -"},
15+
'enc(morse-/AB)': {'this is a test': "A BBBB BB BBB / BB BBB / BA / A B BBB A"},
16+
'enc(morse-01)': {'this is a test': "0 1111 11 111 - 11 111 - 10 - 0 1 111 0"},
17+
}
18+
19+
1320
ENCMAP = {
1421
# letters
1522
'a': ".-", 'b': "-...", 'c': "-.-.", 'd': "-..", 'e': ".", 'f': "..-.", 'g': "--.", 'h': "....", 'i': "..",

codext/languages/radio.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
from ..__common__ import *
1111

1212

13+
__examples__ = {
14+
'enc(radio|military-alphabet)': {'test': "Tango Echo Sierra Tango"},
15+
'enc(nato-alphabet|radio-phonetic)': {'string': "Sierra Tango Romeo India November Golf"},
16+
}
17+
18+
1319
ENCMAP = {
1420
'A': "Alpha", 'B': "Bravo", 'C': "Charlie", 'D': "Delta", 'E': "Echo", 'F': "Foxtrot", 'G': "Golf", 'H': "Hotel",
1521
'I': "India", 'J': "Juliett", 'K': "Kilo", 'L': "Lima", 'M': "Mike", 'N': "November", 'O': "Oscar", 'P': "Papa",
@@ -19,5 +25,5 @@
1925

2026

2127
add_map("radio", ENCMAP, sep=" ", ignore_case="both",
22-
pattern=r"^(?:military|nato|radio)(?:[-_]phonetic)?[-_]alphabet?$")
28+
pattern=r"^(?:military|nato|radio)(?:(?:[-_]phonetic)?(?:[-_]alphabet)?)?$")
2329

0 commit comments

Comments
 (0)