-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathexample.py
27 lines (20 loc) · 1.16 KB
/
example.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
import pyae
# Example for encoding a simple text message using the PyAE module.
# This example only returns the floating-point value that encodes the message.
# Check the example_binary.py to return the binary code of the floating-point value.
frequency_table = {"a": 2,
"b": 7,
"c": 1}
AE = pyae.ArithmeticEncoding(frequency_table=frequency_table,
save_stages=True)
original_msg = "abc"
print("Original Message: {msg}".format(msg=original_msg))
encoded_msg, encoder , interval_min_value, interval_max_value = AE.encode(msg=original_msg,
probability_table=AE.probability_table)
print("Encoded Message: {msg}".format(msg=encoded_msg))
decoded_msg, decoder = AE.decode(encoded_msg=encoded_msg,
msg_length=len(original_msg),
probability_table=AE.probability_table)
print("Decoded Message: {msg}".format(msg=decoded_msg))
decoded_msg = "".join(decoded_msg)
print("Message Decoded Successfully? {result}".format(result=original_msg == decoded_msg))