Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 905cfbd

Browse files
committed
added leet encoder for soultion 12
1 parent 5748f49 commit 905cfbd

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

12_ransom/ransom.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,31 @@
1313
import random
1414
import os
1515
import io
16+
from typing import Final
17+
18+
CHAR_ENCODING: Final = {
19+
'A': '4',
20+
'B': '|3',
21+
'C': '(',
22+
'D': '|)',
23+
'E': '3',
24+
'F': '|=',
25+
'G': '(-',
26+
'H': '|-|',
27+
'I': '1',
28+
'J': '_|',
29+
'K': '|<',
30+
'L': '|_',
31+
'M': '|\\/|',
32+
'N': '|\\|',
33+
'P': '|`',
34+
'Q': '',
35+
'R': '',
36+
'S': '5',
37+
'T': '+',
38+
'V': '\\/',
39+
'W': '\\/\\/'
40+
}
1641

1742

1843
# --------------------------------------------------
@@ -72,6 +97,22 @@ def test_choose():
7297
random.setstate(state)
7398

7499

100+
def encode_chars(char: str):
101+
"""Leet encoder"""
102+
return CHAR_ENCODING.get(char.upper(), char) \
103+
if random.choice([False, True]) else char
104+
105+
106+
def test_encode():
107+
"""Test our leet encoder"""
108+
text = 'The quick brown fox jumps over the lazy dog.'
109+
state = random.getstate()
110+
random.seed(1)
111+
assert "".join(map(encode_chars, text.rstrip().lower())) \
112+
== 'th3 u1(k |3ro\\/\\/n |=ox jump5 ove t|-|e |_4zy dog.'
113+
random.setstate(state)
114+
115+
75116
# --------------------------------------------------
76117
if __name__ == '__main__':
77118
main()

0 commit comments

Comments
 (0)