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