1+ #PyZeroWidth | Encoding Functions
2+
3+
4+
5+
6+
7+
8+ #Global Variables
9+ ZWCharacterSelections = [
10+ ['utf8' ,'utf-8' ,'u8' ,'utf' , 'cp65001' ],
11+ ['ascii' ,'us-ascii' ,'646' ],
12+ ['latin' , 'latin1' , 'latin_1' , 'iso-8859-1' , 'iso8859-1' , '8859' , 'cp819' ]
13+ ]
14+
15+ ZWCharacters = [
16+ ['\u200c ' ,'\u200d ' ,'\u2060 ' ,'\ufeff ' ],
17+ ['\x00 ' , '\x07 ' , '\x08 ' , '\x09 ' ],
18+ ['\x80 ' , '\x81 ' , '\x82 ' , '\x83 ' ]
19+ ]
20+
21+
22+
23+
24+
25+
26+ #Private Functions
27+ def __convertBase (number : int , base : int ) -> str :
28+ if number == 0 : return '0'
29+ digits = []
30+ while number :
31+ digits .append (int (number % base ))
32+ number //= base
33+ return '' .join ([str (i ) for i in digits [::- 1 ]])
34+
35+
36+
37+ def __qua (number : int ) -> str :
38+ return __convertBase (number , 4 )
39+
40+
41+
42+ def __tri (number : int ) -> str :
43+ return __convertBase (number , 3 )
44+
45+
46+
47+ def __encodeBase (text : str , secret : str , base : str , encoding : str , fillAmount : int ):
48+ global ZWCharacters
49+
50+ if not any ([encoding .lower () in alis for alis in ZWCharacterSelections ]): return None
51+ localZWCharacters = ZWCharacters [[encoding .lower () in alis for alis in ZWCharacterSelections ].index (True )]
52+
53+ match base :
54+ case 'bin' : secret = '' .join ([bin (ord (i ))[2 :].zfill (fillAmount ) for i in secret ])
55+ case 'tri' : secret = '' .join ([__tri (ord (i )).zfill (fillAmount ) for i in secret ])
56+ case 'qua' : secret = '' .join ([__qua (ord (i )).zfill (fillAmount ) for i in secret ])
57+
58+ secret = '' .join ([localZWCharacters [int (i )] for i in secret ])
59+
60+ splitLength = max (int (round (len (secret ) / len (text ))), 1 )
61+ secret = [secret [i :i + splitLength ] for i in range (0 , len (secret ), splitLength )]
62+
63+ text = list (text ) + ['' for i in range (max (0 , len (secret ) - len (text )))]
64+ secret += ['' for i in range (max (0 , len (text ) - len (secret )))]
65+
66+ return '' .join ([text [i ] + secret [i ] for i in range (len (text ))])
67+
68+
69+
70+ def __binaryFill (text : str , secret : str , encoding : str , fillAmount : int ) -> str :
71+ return __encodeBase (text , secret , 'bin' , encoding , fillAmount )
72+
73+
74+
75+ def __trinaryFill (text : str , secret : str , encoding : str , fillAmount : int ) -> str :
76+ return __encodeBase (text , secret , 'tri' , encoding , fillAmount )
77+
78+
79+
80+ def __quaternaryFill (text : str , secret : str , encoding : str , fillAmount : int ) -> str :
81+ return __encodeBase (text , secret , 'qua' , encoding , fillAmount )
82+
83+
84+
85+
86+
87+
88+ #Public Functions
89+ def binary8 (text : str , secret : str , encoding : str = 'utf' ) -> str :
90+ return __binaryFill (text , secret , encoding , 8 )
91+
92+
93+
94+ def binary16 (text : str , secret : str , encoding : str = 'utf' ) -> str :
95+ return __binaryFill (text , secret , encoding , 16 )
96+
97+
98+
99+ def binary24 (text : str , secret : str , encoding : str = 'utf' ) -> str :
100+ return __binaryFill (text , secret , encoding , 24 )
101+
102+
103+
104+ def trinary6 (text : str , secret : str , encoding : str = 'utf' ) -> str :
105+ return __trinaryFill (text , secret , encoding , 6 )
106+
107+
108+
109+ def trinary11 (text : str , secret : str , encoding : str = 'utf' ) -> str :
110+ return __trinaryFill (text , secret , encoding , 11 )
111+
112+
113+
114+ def trinary16 (text : str , secret : str , encoding : str = 'utf' ) -> str :
115+ return __trinaryFill (text , secret , encoding , 16 )
116+
117+
118+
119+ def quaternary4 (text : str , secret : str , encoding : str = 'utf' ) -> str :
120+ return __quaternaryFill (text , secret , encoding , 4 )
121+
122+
123+
124+ def quaternary8 (text : str , secret : str , encoding : str = 'utf' ) -> str :
125+ return __quaternaryFill (text , secret , encoding , 8 )
126+
127+
128+
129+ def quaternary12 (text : str , secret : str , encoding : str = 'utf' ) -> str :
130+ return __quaternaryFill (text , secret , encoding , 12 )
0 commit comments