Утилита декордирования
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
# Таблица Base64-подобного варианта
|
# Таблица Base64-подобного варианта
|
||||||
VariantBase64Table: str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
|
VariantBase64Table: str = (
|
||||||
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
|
||||||
|
)
|
||||||
VariantBase64Dict: Dict[int, str] = {
|
VariantBase64Dict: Dict[int, str] = {
|
||||||
i: VariantBase64Table[i] for i in range(len(VariantBase64Table))
|
i: VariantBase64Table[i] for i in range(len(VariantBase64Table))
|
||||||
}
|
}
|
||||||
@@ -28,7 +30,8 @@ def variant_base64_encode(bs: bytes) -> bytes:
|
|||||||
b: bytes = bs[3*i:3*i+3]
|
b: bytes = bs[3*i:3*i+3]
|
||||||
coding_int: int = int.from_bytes(b, "little")
|
coding_int: int = int.from_bytes(b, "little")
|
||||||
block: str = "".join(
|
block: str = "".join(
|
||||||
VariantBase64Dict[(coding_int >> shift) & 0x3F] for shift in (0, 6, 12, 18)
|
VariantBase64Dict[(coding_int >> shift) & 0x3F]
|
||||||
|
for shift in (0, 6, 12, 18)
|
||||||
)
|
)
|
||||||
result.extend(block.encode("ascii"))
|
result.extend(block.encode("ascii"))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user