Started working on custom codec noVow7

This commit is contained in:
zoeyande2
2026-03-14 20:20:18 -04:00
parent 60d372469c
commit 0fa64e0241
6 changed files with 23563 additions and 2 deletions

41
text_codecs/noVow7.py Normal file
View File

@@ -0,0 +1,41 @@
import string
import codecs
from text_codecs.register import register_codec
from easybits import Bits
vowels = 'aeiouyAEIOUY'
allowed_chars = string.ascii_letters + string.digits
def encode(text):
ascii_chars = []
last_character_was_space = False
for char in text:
if char in allowed_chars:
ascii_chars.append(char)
last_character_was_space = False
elif char in string.whitespace and not last_character_was_space:
ascii_chars.append(' ')
last_character_was_space = True
ascii_text = ''.join(ascii_chars)
no_vowels = []
for ch in ascii_text:
if ch not in vowels:
no_vowels.append(ch)
return Bits(no_vowels, encoding = 'ascii7')
def decode(data):
bits = Bits(bytes(data))
text = ""
for i in range(0, len(bits), 7):
byte = Bits('0').concat(bits[i:i+7])
text += Bits(byte).ascii
return text
register_codec(encode, decode, "noVow7")