Base58 인코더 / 디코더
Base58로 텍스트를 인코딩하거나 Base58 문자열을 디코딩합니다. 비트코인 주소 및 IPFS CID에 사용됩니다.
자주 묻는 질문
코드 구현
import base58 # pip install base58
# Encode text to Base58
text = "Hello, World!"
encoded = base58.b58encode(text.encode()).decode()
print(encoded) # JxF12TrwUP45BMd
# Decode Base58 back to text
decoded = base58.b58decode(encoded).decode()
print(decoded) # Hello, World!
# Manual implementation without library
ALPHABET = b"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
def encode(data: bytes) -> str:
num = int.from_bytes(data, "big")
result = b""
while num > 0:
num, rem = divmod(num, 58)
result = bytes([ALPHABET[rem]]) + result
pad = len(data) - len(data.lstrip(b"\x00"))
return (b"1" * pad + result).decode()Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.