SHA256
stupid dumb url shortener
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
const ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
||||
|
||||
function base10ToBase58(value) {
|
||||
let num = BigInt(value);
|
||||
let result = "";
|
||||
|
||||
if (num < 0n) throw new Error("Negative number");
|
||||
|
||||
do {
|
||||
result = ALPHABET[Number(num % 58n)] + result;
|
||||
num /= 58n;
|
||||
} while (num > 0n);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function base58ToBase10(str) {
|
||||
let num = 0n;
|
||||
|
||||
for (const ch of str) {
|
||||
const digit = ALPHABET.indexOf(ch);
|
||||
|
||||
if (digit === -1) {
|
||||
throw new Error(`Invalid Base58 character: ${ch}`);
|
||||
}
|
||||
|
||||
num = num * 58n + BigInt(digit);
|
||||
}
|
||||
|
||||
return num.toString();
|
||||
}
|
||||
Reference in New Issue
Block a user