Added code

This commit is contained in:
BarsTiger
2022-08-27 15:45:03 +03:00
commit 51f1d6d831
30 changed files with 1822 additions and 0 deletions

0
modules/__init__.py Normal file
View File

View File

@@ -0,0 +1 @@
from .config import charset

11
modules/config/config.py Normal file
View File

@@ -0,0 +1,11 @@
import json
try:
config = json.load(open('config.json', encoding='utf-8'))
except:
config = {
"charset": "abcdefghijklmnopqrstuvwxyz"
}
json.dump(config, open('config.json', 'w', encoding='utf-8'), indent=4)
charset = ''.join(sorted(list(set(' ' + config['charset']))))

View File

@@ -0,0 +1 @@
from .pages import Page, Index

View File

@@ -0,0 +1,42 @@
from modules.config import charset
from ezzthread import threaded
def encode(n):
try:
return charset[n]
except IndexError:
raise Exception(f"Cannot encode {n}")
def decode(s):
try:
return charset.index(s)
except ValueError:
raise Exception(f"Cannot decode {s}")
def dec_to_base(dec=0, base=16):
if dec < base:
return encode(dec)
else:
return dec_to_base(dec // base, base) + encode(dec % base)
def base_to_dec(s, base=16, rec_pow=0):
if s == str():
return 0
else:
return decode(s[-1]) * (base ** rec_pow) + base_to_dec(s[0:-1], base, rec_pow + 1)
class Page:
@staticmethod
def from_index(index: int) -> str:
return dec_to_base(index, len(charset))
class Index:
@staticmethod
def from_page(page: str) -> int:
return base_to_dec(page, len(charset))