Created a new file ascii6.py that follows similar style to ascii7.py encode(text), decode(text) register_codec and uses Bits. the docstrict also includes compression rate with is about .72 or 72%.

This commit is contained in:
erbrown2
2026-05-18 10:33:57 -04:00
parent cd2e687824
commit 56b52460a9
6 changed files with 708 additions and 2 deletions

29
text_codecs/ascii6.py Normal file
View File

@@ -0,0 +1,29 @@
from easybits import Bits
from register import register_codec
CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,?!"
def encode(text):
result = Bits()
text = text.upper()
for char in text:
if char in CHARACTERS:
index = CHARACTERS.index(char)
b = Bits(index, length=6)
result = result.concat(b)
return result.bytes
def decode(data):
bits = Bits(bytes(data))
text = ""
for i in range(0, len(bits), 6):
b = bits[i:i+6]
if len(b)<6:
break
index = b.int
if index < len(CHARACTERS):
text+= CHARACTERS[index]
return text
register_codec(encode, decode, "ascii6")