File tree 1 file changed +41
-0
lines changed 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 13
13
import random
14
14
import os
15
15
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
+ }
16
41
17
42
18
43
# --------------------------------------------------
@@ -72,6 +97,22 @@ def test_choose():
72
97
random .setstate (state )
73
98
74
99
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
+
75
116
# --------------------------------------------------
76
117
if __name__ == '__main__' :
77
118
main ()
You can’t perform that action at this time.
0 commit comments