I'm looking for a JS script that will convert a base-36 number like:
23SQJ1LNEFSL00H18IVWABMP
to a base-62 number like:
1rZmfPo0xtnf8CLTfWRJh
I'm trying to translate this python code to do that.
converter.pyBASE62 = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
def encode(num, alphabet=BASE62):
"""Encode a positive number in Base X
Arguments:
- `num`: The number to encode
- `alphabet`: The alphabet to use for encoding
"""
if num == 0:
return alphabet[0]
arr = []
base = len(alphabet)
while num:
num, rem = divmod(num, base)
arr.append(alphabet[rem])
arr.reverse()
return ''.join(arr)
How can I accomplish this?