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

View File

@@ -1,7 +1,8 @@
import string
import codecs
from custom_codecs.register import register_codec
#from text_codecs.register import register_codec
from easybits import Bits
from register import register_codec
allowed_characters = string.ascii_letters + string.digits

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")

View File

@@ -1,5 +1,6 @@
from custom_codecs.register import register_codec
#from text_codecs.register import register_codec
from easybits import Bits
from register import register_codec
def encode(text):
"""An encoder which only handles ASCII: non-ASCII characters

View File

@@ -5,6 +5,7 @@ import requests
from tabulate import tabulate
import sys
import shutil
from register import register_codec
codecs_dir = "text_codecs"