-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
25 lines (18 loc) · 677 Bytes
/
Copy pathexample.py
File metadata and controls
25 lines (18 loc) · 677 Bytes
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
from huffman.huffmancoding import HuffmanCoding
from huffman.huffmandecoding import HuffmanDecoding
def main() -> None:
sample_text = "Hello World!"
# Initialize encoder
encoder = HuffmanCoding()
encoded_bits = encoder.encode(sample_text)
# Initialize decoder
decoder = HuffmanDecoding()
decoded_text = decoder.decode(encoded_bits, encoder.get_tree())
# Display results
print("Original text: ", sample_text)
print("Encoded bits: ", encoded_bits)
print("Decoded text: ", decoded_text)
print("Code table: ", encoder.get_table())
print("Summary: ", encoder.get_summary())
if __name__ == "__main__":
main()