Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/addresses.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"


def encodeBase58(num, alphabet=ALPHABET):
def encodeBase58(num):
"""Encode a number in Base X

Args:
Expand All @@ -23,30 +23,30 @@ def encodeBase58(num, alphabet=ALPHABET):
if num < 0:
return None
if num == 0:
return alphabet[0]
return ALPHABET[0]
arr = []
base = len(alphabet)
base = len(ALPHABET)
while num:
num, rem = divmod(num, base)
arr.append(alphabet[rem])
arr.append(ALPHABET[rem])
arr.reverse()
return ''.join(arr)


def decodeBase58(string, alphabet=ALPHABET):
def decodeBase58(string):
"""Decode a Base X encoded string into the number

Args:
string: The encoded string
alphabet: The alphabet to use for encoding
"""
base = len(alphabet)
base = len(ALPHABET)
num = 0

try:
for char in string:
num *= base
num += alphabet.index(char)
num += ALPHABET.index(char)
except ValueError:
# character not found (like a space character or a 0)
return 0
Expand Down