Spaces:
Sleeping
Sleeping
Create coding.py
Browse files
coding.py
ADDED
@@ -0,0 +1,154 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
coding = {
|
2 |
+
"e": "000",
|
3 |
+
"s": "0010",
|
4 |
+
"r": "0011",
|
5 |
+
"o": "0100",
|
6 |
+
"'": "010100000",
|
7 |
+
"P": "010100001",
|
8 |
+
"S": "01010001",
|
9 |
+
"T": "01010010",
|
10 |
+
"A": "01010011",
|
11 |
+
";": "01010100000",
|
12 |
+
"Q": "0101010000100",
|
13 |
+
"]": "01010100001010",
|
14 |
+
"+": "010101000010110",
|
15 |
+
"*": "01010100001011100",
|
16 |
+
"^": "010101000010111010",
|
17 |
+
"\u007f": "0101010000101110110000",
|
18 |
+
"\u001f": "01010100001011101100010",
|
19 |
+
"\u001e": "01010100001011101100011",
|
20 |
+
"<": "010101000010111011001",
|
21 |
+
"\u000f": "01010100001011101101000",
|
22 |
+
"\u000e": "01010100001011101101001",
|
23 |
+
"\r": "01010100001011101101010",
|
24 |
+
"\f": "01010100001011101101011",
|
25 |
+
"\u001d": "01010100001011101101100",
|
26 |
+
"\u001c": "01010100001011101101101",
|
27 |
+
"\u001b": "01010100001011101101110",
|
28 |
+
"\u001a": "01010100001011101101111",
|
29 |
+
"\u0017": "01010100001011101110000",
|
30 |
+
"\u0016": "01010100001011101110001",
|
31 |
+
"\u0015": "01010100001011101110010",
|
32 |
+
"\u0014": "01010100001011101110011",
|
33 |
+
"\u0013": "01010100001011101110100",
|
34 |
+
"\u0012": "01010100001011101110101",
|
35 |
+
"\u0019": "01010100001011101110110",
|
36 |
+
"\u0018": "01010100001011101110111",
|
37 |
+
"\u000b": "01010100001011101111000",
|
38 |
+
"\b": "01010100001011101111001",
|
39 |
+
"\u0005": "01010100001011101111010",
|
40 |
+
"\u0004": "01010100001011101111011",
|
41 |
+
"\u0003": "01010100001011101111100",
|
42 |
+
"\u0002": "01010100001011101111101",
|
43 |
+
"\u0001": "01010100001011101111110",
|
44 |
+
"\u0000": "01010100001011101111111",
|
45 |
+
"~": "0101010000101111",
|
46 |
+
"%": "010101000011",
|
47 |
+
"q": "0101010001",
|
48 |
+
"x": "010101001",
|
49 |
+
"V": "01010101000",
|
50 |
+
":": "01010101001",
|
51 |
+
"6": "0101010101",
|
52 |
+
"9": "010101011",
|
53 |
+
"\"": "010101100",
|
54 |
+
"-": "010101101",
|
55 |
+
"=": "01010111",
|
56 |
+
"g": "010110",
|
57 |
+
"1": "01011100",
|
58 |
+
"B": "010111010",
|
59 |
+
"7": "0101110110",
|
60 |
+
"z": "0101110111",
|
61 |
+
"M": "010111100",
|
62 |
+
"J": "0101111010",
|
63 |
+
"L": "0101111011",
|
64 |
+
"4": "0101111100",
|
65 |
+
"U": "0101111101",
|
66 |
+
"}": "010111111000000",
|
67 |
+
"{": "010111111000001",
|
68 |
+
"X": "01011111100001",
|
69 |
+
"/": "0101111110001",
|
70 |
+
"$": "0101111110010",
|
71 |
+
"Z": "0101111110011",
|
72 |
+
"K": "01011111101",
|
73 |
+
"O": "0101111111",
|
74 |
+
"n": "0110",
|
75 |
+
"i": "0111",
|
76 |
+
"d": "10000",
|
77 |
+
"p": "100010",
|
78 |
+
"f": "100011",
|
79 |
+
"t": "1001",
|
80 |
+
"l": "10100",
|
81 |
+
".": "1010100",
|
82 |
+
"v": "1010101",
|
83 |
+
"0": "10101100",
|
84 |
+
"k": "10101101",
|
85 |
+
"5": "1010111000",
|
86 |
+
"8": "1010111001",
|
87 |
+
"W": "1010111010",
|
88 |
+
"3": "1010111011",
|
89 |
+
"\n": "10101111",
|
90 |
+
"a": "1011",
|
91 |
+
" ": "110",
|
92 |
+
"h": "11100",
|
93 |
+
"m": "111010",
|
94 |
+
"D": "1110110000",
|
95 |
+
"F": "1110110001",
|
96 |
+
"G": "1110110010",
|
97 |
+
"E": "1110110011",
|
98 |
+
"N": "1110110100",
|
99 |
+
"H": "1110110101",
|
100 |
+
"C": "111011011",
|
101 |
+
"b": "1110111",
|
102 |
+
"u": "111100",
|
103 |
+
",": "1111010",
|
104 |
+
"(": "1111011000",
|
105 |
+
")": "1111011001",
|
106 |
+
"I": "111101101",
|
107 |
+
"R": "1111011100",
|
108 |
+
"Y": "111101110100",
|
109 |
+
"!": "1111011101010000",
|
110 |
+
"#": "11110111010100010",
|
111 |
+
"|": "1111011101010001100",
|
112 |
+
"\u0011": "11110111010100011010000",
|
113 |
+
"\u0010": "11110111010100011010001",
|
114 |
+
"\u0007": "11110111010100011010010",
|
115 |
+
"\u0006": "11110111010100011010011",
|
116 |
+
"@": "1111011101010001101010",
|
117 |
+
"`": "1111011101010001101011",
|
118 |
+
">": "11110111010100011011",
|
119 |
+
"_": "111101110101000111",
|
120 |
+
"?": "1111011101010010",
|
121 |
+
"\\": "1111011101010011",
|
122 |
+
"&": "111101110101010",
|
123 |
+
"[": "111101110101011",
|
124 |
+
"\t": "1111011101011",
|
125 |
+
"j": "11110111011",
|
126 |
+
"2": "111101111",
|
127 |
+
"w": "1111100",
|
128 |
+
"y": "1111101",
|
129 |
+
"c": "111111"
|
130 |
+
}
|
131 |
+
decoding = {v: k for k, v in coding.items()}
|
132 |
+
def decimal_to_binary(n):
|
133 |
+
return bin(n)[2:]
|
134 |
+
def binary_to_decimal(n):
|
135 |
+
return int(n,2)
|
136 |
+
def convert_to_binary(text):
|
137 |
+
binary_text = ""
|
138 |
+
for char in text:
|
139 |
+
binary_text += coding[char]
|
140 |
+
return binary_text
|
141 |
+
def convert_to_text(binary):
|
142 |
+
text = ""
|
143 |
+
chunk = ""
|
144 |
+
for i in binary:
|
145 |
+
chunk += i
|
146 |
+
if chunk in decoding:
|
147 |
+
text += decoding[chunk]
|
148 |
+
chunk = ""
|
149 |
+
return text
|
150 |
+
t = ""
|
151 |
+
for i in range(128):
|
152 |
+
t+="b"+coding[chr(i)]+"\n"
|
153 |
+
with open("list.txt", "w") as f:
|
154 |
+
f.write(t)
|