-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple_compress.py
159 lines (131 loc) · 18.4 KB
/
simple_compress.py
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# Original - https://github.com/Former/Python_simple/blob/main/simple_compress.py
# 2025 Alexei Bezborodov. Contacts: <[email protected]>
# Based on: https://github.com/dev-mkm/Huffman-File-Compression/blob/main/huffman.py
# License: Public domain: http://unlicense.org/
# Общественное достояние
import heapq
class HuffmanNode:
def __init__(self, char=None, freq=0, left=None, right=None):
self.char = char
self.freq = freq
self.left = left
self.right = right
def __lt__(self, other):
return self.freq < other.freq
# Encoder
def HuffmanCompress(input_string):
def _build_freq_table(input_string):
freq_table = {}
for char in input_string:
if char in freq_table:
freq_table[char] += 1
else:
freq_table[char] = 1
return freq_table
def _build_huffman_tree(freq_table):
heap = []
for char, freq in freq_table.items():
node = HuffmanNode(char, freq)
heapq.heappush(heap, node)
while len(heap) > 1:
left = heapq.heappop(heap)
right = heapq.heappop(heap)
freq = left.freq + right.freq
node = HuffmanNode(None, freq, left, right)
heapq.heappush(heap, node)
return heap[0]
def _build_encoding_table(node, code='', table={}):
if node.char:
table[node.char] = code
else:
_build_encoding_table(node.left, code+'0', table)
_build_encoding_table(node.right, code+'1', table)
return table
freq_table = _build_freq_table(input_string)
huffman_tree = _build_huffman_tree(freq_table)
encoding_table = _build_encoding_table(huffman_tree)
result = bytes("", 'utf-8')#bytes(str(freq_table)+'\n', 'utf-8')
code = ''
for char in input_string:
code += encoding_table[char]
while len(code) >= 8:
byte = int(code[:8], 2)
result += bytes([byte])
code = code[8:]
# write any remaining bits
if code:
byte = int(code.ljust(8, '0'), 2)
result += bytes([byte])
return result, freq_table
# Decoder
def HuffmanDecode(input_bytes, freq_table):
def _build_huffman_tree_from_encoding_table(encoding_table):
root = HuffmanNode()
for char, code in encoding_table.items():
node = root
for bit in code:
if bit == '0':
if not node.left:
node.left = HuffmanNode()
node = node.left
else:
if not node.right:
node.right = HuffmanNode()
node = node.right
node.char = char
return root
def _build_huffman_tree(freq_table):
heap = []
for char, freq in freq_table.items():
node = HuffmanNode(char, freq)
heapq.heappush(heap, node)
while len(heap) > 1:
left = heapq.heappop(heap)
right = heapq.heappop(heap)
freq = left.freq + right.freq
node = HuffmanNode(None, freq, left, right)
heapq.heappush(heap, node)
return heap[0]
def _build_encoding_table(node, code='', table={}):
if node.char:
table[node.char] = code
else:
_build_encoding_table(node.left, code+'0', table)
_build_encoding_table(node.right, code+'1', table)
return table
huffman_tree = _build_huffman_tree_from_encoding_table(_build_encoding_table(_build_huffman_tree(freq_table)))
result = ""
node = huffman_tree
for bit in input_bytes:
#bit = int.from_bytes(bit)
for b in format(bit, '08b'):
if b == '0':
node = node.left
else:
node = node.right
if node.char:
if freq_table[node.char] > 0:
result += node.char
freq_table[node.char] -= 1
node = huffman_tree
return result
import base64
def b64e(b):
return base64.b64encode(b).decode()
def b64d(s):
return base64.b64decode(s).decode()
def Test():
input_str = "-90,1;-90,1;-140,2;-127,6;-143,7;-123,2;-124,2;-124,0;-120,3;-106,2;-104,2;-94,2;-90,0;-95,4;-102,4;-93,4;-94,7;-97,9;-92,6;-103,4;-92,4;-87,2;-83,2;-89,9;-88,1;-77,5;-76,3;-87,0;-79,7;-81,3;-90,3;-83,7;-78,0;-78,4;-78,7;-88,8;-84,7;-103,2;-74,9;-73,6;-81,9;-101,9;-88,2;-79,5;-77,8;-90,3;-82,7;-81,5;-85,5;-82,7;-86,8;-85,2;-101,1;-86,5;-87,3;-85,1;-89,8;-83,0;-85,5;-96,4;-103,9;-84,7;-79,5;-80,5;-85,2;-93,8;-71,4;-63,6;-67,7;-82,5;-84,3;-82,5;-81,7;-87,3;-84,9;-85,1;-85,1;-83,7;-92,9;-94,9;-89,0;-82,5;-79,3;-81,4;-88,0;-81,0;-77,9;-85,4;-93,6;-85,3;-82,9;-87,8;-83,9;-86,2;-91,0;-88,2;-89,7;-93,4;-103,4;-84,0;-81,5;-84,9;-79,7;-79,6;-87,6;-97,4;-84,5;-81,7;-85,9;-102,8;-94,9;-90,8;-87,0;-83,1;-83,9;-87,0;-85,9;-81,7;-86,9;-90,0;-83,3;-77,4;-82,2;-93,4;-91,1;-95,0;-90,1;-87,0;-86,8;-80,4;-83,1;-81,6;-74,7;-55,5;-45,2;-47,5;-69,5;-70,5;-84,0;-87,5;-99,8;-84,8;-81,0;-91,0;-80,9;-86,5;-83,9;-80,1;-79,2;-86,2;-87,8;-85,4;-90,7;-75,9;-70,5;-76,2;-89,1;-88,4;-90,7;-93,7;-98,5;-97,1;-104,7;-87,9;-86,6;-85,1;-85,9;-96,6;-92,5;-92,2;-85,7;-82,5;-85,6;-89,9;-89,3;-88,8;-84,7;-85,4;-92,7;-106,3;-93,1;-98,0;-92,3;-92,0;-105,9;-95,4;-90,7;-90,8;-95,5;-98,5;-96,5;-92,2;-89,7;-92,5;-97,1;-91,4;-91,5;-97,5;-99,8;-92,5;-83,9;-72,2;-72,4;-84,4;-87,9;-87,6;-88,8;-90,1;-97,4;-90,2;-84,2;-87,9;-101,6;-91,9;-94,7;-87,4;-95,5;-88,7;-94,4;-86,4;-84,6;-90,2;-98,7;-92,2;-95,8;-87,6;-88,7;-93,1;-93,1;-82,8;-83,9;-84,7;-79,3;-80,7;-96,6;-107,3;-95,8;-97,7;-99,1;-92,8;-98,0;-99,5;-94,8;-103,7;-99,1;-94,0;-93,4;-94,3;-92,8;-85,2;-88,5;-97,5;-96,0;-95,9;-97,0;-97,7;-94,6;-88,5;-95,2;-92,8;-88,1;-96,2;-92,3;-87,4;-96,6;-97,0;-97,5;-99,3;-65,5;-59,7;-65,4;-90,4;-88,5;-93,2;-105,8;-107,3;-98,5;-92,4;-94,2;-95,1;-95,4;-104,8;-97,3;-91,1;-95,9;-96,2;-96,0;-101,2;-103,6;-96,5;-97,7;-95,8;-95,0;-99,7;-94,2;-92,2;-96,3;-104,8;-115,6;-103,8;-95,7;-94,6;-94,0;-99,0;-100,1;-101,8;-96,2;-92,5;-98,4;-98,3;-95,0;-100,9;-110,8;-104,5;-104,0;-103,8;-96,2;-97,8;-94,8;-104,3;-103,9;-94,1;-94,7;-97,8;-93,9;-94,3;-99,0;-104,2;-103,5;-99,1;-103,1;-100,0;-97,2;-98,7;-107,5;-94,3;-73,6;-70,7;-79,0;-92,2;-96,7;-93,4;-99,8;-99,3;-93,8;-92,9;-93,2;-96,7;-105,4;-109,9;-96,9;-93,0;-93,8;-102,4;-113,5;-103,6;-95,7;-95,0;-96,0;-94,4;-94,8;-98,3;-104,7;-102,4;-111,7;-105,3;-105,3;-93,1;-91,2;-93,6;-95,6;-94,9;-99,0;-98,0;-99,4;-125,2;-105,7;-106,2;-99,5;-104,9;-106,0;-96,9;-105,6;-100,0;-103,4;-99,0;-104,7;-106,3;-103,3;-104,7;-105,3;-97,6;-100,0;-108,3;-98,8;-103,1;-119,5;-107,5;-101,2;-98,4;-98,0;-102,8;-93,4;-86,8;-73,4;-68,3;-76,2;-92,6;-102,9;-99,3;-96,7;-99,3;-94,6;-95,5;-97,6;-104,1;-100,1;-107,7;-98,4;-95,7;-97,9;-100,3;-96,3;-96,5;-95,6;-95,8;-99,2;-105,9;-100,3;-95,0;-95,9;-109,0;-105,9;-106,0;-105,1;-110,9;-104,8;-103,5;-101,1;-98,7;-92,8;-93,8;-95,8;-97,8;-110,2;-104,9;-98,5;-99,0;-104,7;-93,7;-95,6;-100,2;-105,4;-99,3;-99,1;-106,9;-95,9;-97,1;-102,5;-109,2;-109,3;-95,2;-94,3;-96,2;-95,2;-93,1;-91,0;-96,3;-95,5;-98,4;-110,0;-98,1;-80,0;-69,7;-72,1;-90,3;-96,2;-100,2;-99,7;-105,7;-101,7;-97,7;-99,3;-94,1;-93,3;-102,8;-96,1;-93,5;-92,3;-98,6;-99,9;-99,5;-107,8;-103,0;-99,3;-103,0;-98,1;-103,5;-111,7;-101,3;-96,4;-102,0;-98,1;-112,9;-96,9;-101,6;-122,3;-108,3;-101,4;-97,6;-102,9;-113,3;-101,4;-99,7;-117,7;-108,6;-110,6;-111,5;-107,6;-110,4;-107,2;-106,8;-105,8;-101,8;-102,9;-103,5;-111,4;-98,3;-99,8;-100,2;-101,8;-112,4;-105,5;-109,4;-104,9;-109,4;-104,0;-111,5;-101,7;-102,8;-98,9;-93,2;-81,8;-83,8;-98,0;-115,8;-107,6;-115,3;-101,0;-99,6;-104,3;-120,1;-110,4;-103,5;-101,9;-122,8;-105,9;-105,6;-101,4;-102,7;-103,5;-103,9;-98,1;-104,8;-104,8;-103,2;-112,3;-103,3;-105,9;-99,8;-98,1;-102,9;-108,6;-103,9;-113,9;-102,2;-105,0;-104,8;-110,2;-115,6;-104,5;-97,0;-106,7;-99,3;-96,9;-112,3;-102,6;-112,6;-103,1;-112,1;-108,5;-110,2;-105,0;-103,9;-107,8;-107,9;-106,4;-107,1;-102,8;-100,1;-108,4;-108,4;-108,3;-111,5;-111,6;-105,7;-103,1;-95,0;-93,7;-97,6;-96,0;-81,1;-78,0;-86,0;-94,1;-97,8;-97,2;-97,1;-109,3;-99,7;-98,9;-104,8;-110,1;-101,6;-99,3;-102,2;-104,4;-105,8;-102,2;-106,9;-114,0;-108,4;-105,4;-103,3;-100,1;-101,3;-104,9;-100,3;-102,4;-108,4;-104,0;-102,1;-99,7;-99,6;-104,4;-112,0;-103,5;-105,9;-101,5;-99,1;-99,3;-100,4;-105,0;-102,0;-103,3;-101,2;-105,3;-110,4;-117,1;-100,3;-95,4;-99,8;-101,1;-100,1;-105,9;-113,4;-111,2;-105,5;-100,6;-103,2;-113,9;-99,3;-102,0;-109,9;-106,3;-109,5;-109,3;-100,1;-100,3;-104,3;-103,3;-88,2;-83,7;-89,9;-103,1;-108,8;-99,9;-98,3;-105,9;-101,0;-99,7;-102,1;-105,3;-114,7;-106,6;-104,2;-101,0;-100,9;-101,2;-104,7;-102,8;-105,6;-102,5;-98,2;-102,6;-108,6;-100,8;-99,2;-105,5;-106,6;-103,3;-103,2;-101,1;-97,6;-98,0;-104,0;-102,1;-99,0;-100,3;-102,8;-103,9;-100,2;-95,9;-96,2;-102,1;-101,2;-101,7;-104,4;-110,8;-99,3;-99,7;-101,8;-100,2;-105,6;-111,9;-105,3;-111,3;-97,8;-102,9;-104,0;-105,4;-107,8;-103,6;-104,8;-109,2;-112,7;-106,9;-104,0;-107,7;-108,4;-101,2;-105,2;-96,9;-92,0;-97,2;-100,2;-99,8;-104,7;-108,1;-104,0;-110,4;-113,0;-111,6;-113,8;-109,9;-123,3;-102,3;-100,6;-103,9;-103,2;-101,8;-102,7;-100,8;-100,8;-104,6;-109,3;-105,2;-102,4;-108,3;-115,1;-108,4;-116,2;-112,9;-110,9;-118,2;-104,3;-102,8;-106,6;-99,8;-101,5;-115,6;-111,7;-111,3;-104,4;-106,8;-113,8;-111,7;-103,7;-101,7;-109,7;-108,0;-108,6;-103,3;-107,0;-113,0;-104,5;-100,2;-106,1;-106,7;-112,2;-113,5;-111,4;-102,8;-100,0;-103,2;-102,1;-111,0;-106,0;-109,7;-116,9;-108,0;-105,4;-112,3;-105,6;-99,5;-111,7;-102,0;-100,4;-97,5;-105,5;-110,8;-109,5;-112,2;-109,7;-119,5;-106,4;-102,8;-100,6;-101,0;-105,6;-108,7;-116,3;-115,8;-103,5;-103,6;-112,9;-113,2;-109,9;-104,4;-108,6;-112,1;-104,3;-107,0;-105,3;-109,7;-103,1;-106,9;-101,9;-103,6;-107,5;-104,4;-107,6;-117,3;-120,0;-117,9;-102,1;-103,0;-110,4;-103,0;-105,4;-125,1;-108,2;-114,0;-109,1;-108,3;-109,5;-104,1;-107,3;-119,4;-110,9;-105,8;-102,3;-106,9;-110,4;-103,9;-104,6;-118,8;-109,9;-107,7;-116,9;-101,5;-101,2;-115,5;-109,0;-109,2;-100,1;-96,1;-99,2;-102,2;-98,3;-100,7;-103,7;-109,4;-103,1;-104,8;-113,0;-113,8;-117,1;-112,4;-104,5;-109,6;-104,1;-103,4;-110,1;-102,2;-101,1;-101,6;-111,8;-104,1;-101,6;-111,0;-124,2;-103,2;-111,4;-101,4;-99,6;-101,0;-101,2;-104,0;-104,1;-102,3;-104,5;-108,2;-103,9;-112,8;-115,3;-111,1;-105,6;-107,0;-102,7;-101,6;-107,4;-109,9;-102,8;-107,0;-109,2;-103,1;-103,9;-110,1;-106,1;-108,2;-104,0;-104,9;-101,7;-100,5;-107,4;-123,1;-107,3;-101,3;-104,2;-102,7;-102,6;-104,0;-103,0;-106,5;-109,2;-121,0;-118,9;-108,7;-99,9;-98,1;-101,8;-104,3;-108,7;-108,1;-112,2;-106,0;-108,5;-112,0;-113,6;-118,1;-113,2;-104,6;-102,5;-105,1;-103,9;-106,3;-103,9;-113,9;-110,6;-106,7;-105,0;-112,0;-102,3;-104,4;-126,3;-112,8;-106,1;-101,6;-101,5;-107,2;-106,2;-102,8;-108,1;-114,9;-103,9;-102,6;-114,3;-102,3;-101,8;-105,1;-113,4;-107,1;-107,1;-112,7;-103,1;-97,9;-100,2;-109,3;-115,7;-104,7;-109,1;-108,1;-103,0;-102,9;-115,3;-101,8;-102,6;-117,0;-116,6;-115,0;-111,1;-106,5;-112,7;-113,1;-108,9;-102,6;-100,1;-102,8;-105,2;-104,3;-108,3;-104,5;-111,0;-102,2;-104,5;-119,8;-108,0;-132,0;-115,7;-107,0;-104,6;-119,8;-115,1;-113,1;-110,4;-108,7;-102,1;-103,5;-106,1;-103,5;-105,6;-101,5;-106,4;-118,9;-104,2;-103,2;-106,7;-118,5;-106,7;-106,1;-115,5;-110,5;-108,5;-105,5;-116,3;-113,7;-110,4;-109,8;-108,0;-106,4;-104,3;-115,7;-115,8;-106,7;-100,7;-100,2;-102,9;-113,1;-105,1;-105,0;-109,6;-108,1;-103,2;-102,4;-107,8;-106,8;-100,6;-103,5;-109,6;-107,8;-99,7;-103,3;-107,3;-109,4;-114,1;-117,7;-105,1;-103,2;-102,2;-103,1;-107,9;-102,6;-106,1;-105,1;-105,1;-109,8;-108,4;-100,9;-104,2;-102,6;-103,9;-110,5;-108,6;-115,7;-112,1;-111,2;-114,9;-108,0;-106,2;-110,9;-108,8;-115,1;-106,8;-101,8;-106,0;-111,7;-106,2;-119,4;-102,9;-104,9;-101,5;-103,9;-108,7;-102,2;-104,2;-120,4;-111,4;-110,9;-109,1;-109,2;-104,4;-99,0;-100,2;-111,0;-118,4;-111,8;-113,3;-105,3;-107,4;-117,8;-113,5;-112,5;-114,4;-110,3;-121,8;-108,2;-107,7;-113,9;-105,2;-104,8;-107,2;-102,5;-100,8;-107,8;-113,8;-105,7;-104,7;-103,8;-107,2;-106,0;-111,1;-123,0;-115,6;-116,1;-113,5;-105,0;-105,7;-114,4;-109,0;-108,4;-101,3;-101,2;-118,7;-107,7;-107,8;-101,5;-106,1;-111,5;-113,8;-105,9;-104,6;-111,4;-101,5;-105,3;-106,8;-101,4;-99,3;-102,4;-112,8;-108,1;-103,8;-106,8;-105,7;-112,0;-103,9;-99,7;-103,8;-115,1;-109,3;-105,7;-104,3;-117,8;-110,0;-105,8;-102,8;-105,6;-110,6;-108,8;-109,3;-108,2;-110,0;-107,8;-107,4;-113,8;-114,8;-112,3;-111,3;-107,9;-108,1;-107,6;-105,7;-111,9;-111,7;-109,7;-103,6;-104,6;-110,1;-106,0;-106,8;-109,6;-108,4;-102,0;-102,7;-109,1;-105,5;-110,1;-108,8;-110,2;-117,2;-110,9;-105,9;-107,4;-103,4;-103,3;-114,8;-114,0;-109,8;-121,2;-114,5;-113,6;-104,8;-104,0;-110,8;-104,7;-110,8;-103,3;-102,4;-106,2;-103,2;-100,5;-107,6;-115,5;-109,8;-99,5;-97,1;-104,3;-104,3;-107,6;-106,9;-105,8;-117,2;-116,8;-107,8;-105,4;-108,0;-106,8;-107,0;-101,0;-111,7;-104,9;-112,6;-113,6;-107,8;-106,3;-109,3;-109,0;-110,4;-109,6;-103,7;-101,6;-105,9;-115,0;-110,3;-118,0;-108,7;-105,8;-113,8;-108,3;-113,0;-101,3;-101,8;-107,8;-109,8;-111,2;-106,9;-100,5;-106,2;-104,2;-112,3;-107,5;-104,8;-106,5;-109,4;-112,2;-102,4;-102,5;-109,9;-106,8;-105,9;-103,4;-103,0;-107,6;-107,6;-103,8;-104,0;-111,0;-116,2;-124,9;-105,0;-110,4;-109,3;-109,8;-129,4;-107,1;-124,2;-104,3;-106,5;-124,4;-108,0;-106,4;-101,2;-105,8;-120,4;-110,3;-108,0;-107,1;-103,2;-107,6;-114,7;-112,0;-103,9;-105,0;-107,0;-104,6;-107,0;-115,9;-106,9;-104,2;-111,6;-113,3;-112,7;-125,3;-120,8;-108,4;-103,0;-103,2;-110,5;-107,7;-108,2;-113,0;-112,4;-105,1;-111,5;-115,7;-107,5;-100,5;-104,2;-108,8;-107,1;-111,2;-112,7;-112,1;-107,2;-102,6;-106,8;-116,2;-109,6;-101,1;-102,1;-114,2;-103,9;-105,2;-107,4;-104,4;-112,2;-117,8;-108,4;-107,2;-116,8;-116,4;-104,1;-101,3;-101,8;-106,6;-107,5;-106,4;-106,5;-103,9;-112,2;-112,0;-108,9;-109,8;-108,3;-109,5;-107,2;-104,4;-105,8;-115,1;-116,2;-112,3;-101,5;-102,5;-110,0;-105,9;-104,5;-109,9;-114,3;-114,9;-109,2;-103,3;-108,4;-115,8;-118,2;-111,6;-105,9;-105,8;-109,6;-106,3;-110,7;-120,5;-110,6;-109,7;-118,0;-111,2;-109,9;-116,3;-109,8;-107,2;-103,5;-107,8;-122,8;-107,7;-102,5;-105,9;-112,9;-108,4;-112,2;-111,7;-109,6;-122,0;-119,5;-123,3;-108,3;-106,4;-117,1;-103,8;-105,3;-114,6;-116,1;-113,5;-116,0;-111,9;-113,5;-113,9;-111,7;-110,3;-106,8;-120,1;-107,2;-112,8;-109,2;-103,6;-105,1;-111,2;-115,7;-113,6;-107,0;-110,2;-112,6;-112,6;-111,9;-114,9;-105,2;-101,0;-101,2;-99,8;-100,7;-107,4;-111,6;-104,2;-102,0;-102,1;-105,7;-105,6;-107,4;-112,6;-106,0;-110,1;-110,3;-102,3;-104,2;-103,9;-104,5;-111,2;-105,9;-106,5;-105,7;-110,1;-113,2;-108,5;-113,0;-114,6;-106,3;-106,3;-105,8;-108,0;-112,7;-115,1;-114,2;-103,9;-103,9;-116,2;-110,1;-105,8;-103,0;-114,4;-103,5;-111,3;-118,1;-115,6;-117,1;-114,1;-106,6;-108,8;-114,6;-112,6;-110,7;-108,1;-113,3;-104,1;-102,9;-106,3;-110,5;-123,1;-110,0;-110,5;-107,6;-111,1;-110,3;-103,5;-101,3;-109,4;-111,6;-111,5;-113,1;-137,9;-110,1;-107,5;-109,0;-106,0;-105,0;-109,4;-115,3;-109,3;-101,8;-101,9;-104,5;-111,2;-118,5;-106,4;-104,6;-108,0;-100,5;-100,5;-104,3;-104,9;-102,0;-109,2;-107,8;-101,6;-103,7;-109,6;-117,8;-109,5;-109,4;-114,3;-108,5;-106,5;-104,3;-102,6;-103,9;-106,7;-107,3;-107,1;-110,2;-102,0;-101,2;-104,9;-112,3;-106,0;-109,0;-110,3;-108,7;-112,1;-107,8;-102,2;-105,7;-116,3;-106,4;-109,1;-104,9;-106,9;-106,7;-108,4;-123,3;-111,6;-104,8;-107,2;-109,7;-116,0;-107,8;-106,8;-108,5;-106,5;-101,0;-102,6;-124,3;-108,3;-122,1;-113,7;-108,2;-107,9;-104,3;-106,8;-110,7;-108,6;-114,0;-115,5;-114,3;-115,8;-116,8;-113,7;-105,4;-107,2;-107,9;-108,1;-110,9;-114,9;-109,6;-100,5;-100,8;-104,4;-112,6;-107,8;-109,3;-114,7;-101,9;-103,2;-111,7;-121,1;-104,5;-108,2;-111,6;-110,8;-106,8;-107,1;-108,6;-108,2;-108,4;-102,4;-102,1;-111,6;-111,6;-111,3;-114,9;-116,4;-106,1;-103,4;-104,7;-104,1;-110,1;-115,9;-114,6;-107,8;-107,0;-113,4;-109,7;-105,4;-103,9;-105,6;-108,8;-103,2;-103,0;-104,9;-109,2;-109,7;-110,8;-109,2;-115,1;-105,9;-102,8;-105,5;-106,4;-108,2;-108,8;-111,7;-106,6;-109,1;-110,4;-105,9;-109,2;-107,3;-106,0;-106,0;-109,0;-104,3;-102,7;-103,6;-103,1;-107,7;-118,2;-119,1;-110,9;-103,6;-107,7;-110,7;-115,4;-111,2;-109,0;-106,5;-107,9;-107,0;-104,1;-103,5;-104,1;-102,9;-108,6;-120,5;-126,3;-114,4;-108,3;-105,2;-108,3;-109,9;-106,1;-114,3;-103,1;-102,0;-102,6;-102,9;-104,6;-104,9;-109,0;-102,2;-106,2;-109,3;-113,6;-121,8;-111,4;-107,3;-109,8;-110,7;-107,3;-106,5;-113,1;-120,4;-109,9;-111,6;-110,4;-113,0;-108,1;-110,0;-104,6;-105,8;-122,3;-105,6;-105,2;-110,8;-111,5;-113,3;-105,8;-107,3;-107,3;-112,8;-104,9;-101,2;-105,3;-117,7;-112,6;-111,4;-109,5;-107,4;-107,8;-112,5;-110,1;-110,0;-111,7;-105,2;-105,7;-102,2;-105,1;-112,7;-110,1;-107,2;-107,7;-109,4;-103,3;-105,9;-109,5;-108,7;-110,8;-107,8;-110,4;-107,2;-113,7;-106,6;-111,5;-109,8;-107,0;-106,1;-109,7;-110,8;-113,5;-108,7;-111,4;-115,4;-111,9;-114,2;-109,4;-108,8;-120,0;-106,8;-106,4;-115,5;-107,1;-109,9;-109,7;-108,7;-108,7;-106,8;-106,2;-108,2;-104,5;-108,6;-108,1;-113,8;-111,4;-114,7;-128,0;-111,9;-112,6;-109,0;-108,2;-113,5;-110,4;-111,2;-111,3;-113,2;-108,9;-112,1;-107,7;-103,1;-104,5;-113,7;-113,1;-109,1;-107,4;-101,9;-104,3;-108,9;-110,4;-111,8;-118,1;-109,5;-127,0;-108,7;-105,1;-105,3;-105,9;-106,4;-104,6;-107,2;-112,0;-111,4;-122,6;-108,9;-116,5;-117,2;-127,0;-145,1;-120,5;-116,6;-118,5;-114,3;-106,1;-108,9;-118,0;-105,2;-108,1;-117,7;-121,1;-115,0;-109,3;-106,8;-112,6;-111,9;-107,7;-111,4;-120,9;-111,5;-105,9;-114,3;-110,4;-111,4;-120,4;-112,1;-106,7;-109,2;-114,8;-106,9;-111,1;-118,4;-114,6;-109,8;-109,4;-128,2;-107,1;-103,5;-106,0;-124,6;-113,1;-111,0;-116,3;-119,6;-112,2;-107,5;-115,8;-117,6;-119,0;-110,0;-111,3;-108,1;-114,3;-120,1;-116,5;-117,8;-120,2;-111,1;-113,9;-114,6;-110,8;-118,5;-114,8;-112,8;-115,3;-123,9;-116,5;-115,9;-123,3;-116,9;-114,4;-115,4;-120,8;-119,3;-116,1;-113,8;-111,2;-121,4;-120,0;-111,9;-108,5;-108,3;-112,9;-125,8;-114,6;-114,0;-135,9;-116,0;-116,4;-107,8;-107,8;-109,5;-120,5;-114,4;-109,9;-114,4;-116,3;-115,7;-118,5;-114,1;-118,2;-112,2;-114,8;-115,7;-109,5;-112,3;-118,7;-120,7;-110,9;-108,0;-116,5;-138,5;-114,8;-112,2;-112,4;-131,7;-113,6;-116,4;-122,9;-117,6;-116,7;-115,7;-118,2;-125,9;-119,0;-122,3;-107,9;-110,8;"
comp_text, key = HuffmanCompress(input_str)
comp_b64 = b64e(comp_text)
print("Сжатая строка base64:", comp_b64, key)
print("Длина исходной строки:", len(input_str))
print("Длина сжатой строки:", len(comp_text))
print("Длина сжатой base64 строки:", len(comp_b64))
print("Длина ключа:", len(str(key)))
dec = HuffmanDecode(comp_text, key)
if dec == input_str:
print("После распаковки строки одинаковые")
else:
print("Ошибка! После распаковки строки разные!!!")
Test()