FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
ArithmeticEncodingPython/example_binary.py at main · ahmedfgad/ArithmeticEncodingPython · GitHub
ahmedfgad
/
ArithmeticEncodingPython
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
17
Star
82
Code
Issues
1
Pull requests
1
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
ArithmeticEncodingPython
/
example_binary.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
33 lines (25 loc) · 1.44 KB
Breadcrumbs
ArithmeticEncodingPython
/
example_binary.py
Copy path
File metadata and controls
33 lines (25 loc) · 1.44 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
pyae
# Example for encoding a simple text message using the PyAE module.
# This example returns the floating-point value in addition to its binary code that encodes the message.
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
))
# Encode the message
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
))
# Get the binary code out of the floating-point value
binary_code
,
encoder_binary
=
AE
.
encode_binary
(
float_interval_min
=
interval_min_value
,
float_interval_max
=
interval_max_value
)
print
(
"The binary code is: {binary_code}"
.
format
(
binary_code
=
binary_code
))
# Decode the message
decoded_msg
,
decoder
=
AE
.
decode
(
encoded_msg
=
encoded_msg
,
msg_length
=
len
(
original_msg
),
probability_table
=
AE
.
probability_table
)
decoded_msg
=
""
.
join
(
decoded_msg
)
print
(
"Decoded Message: {msg}"
.
format
(
msg
=
decoded_msg
))
print
(
"Message Decoded Successfully? {result}"
.
format
(
result
=
original_msg
==
decoded_msg
))
Back
|
FazBrowse Home
|
New Git URL