stupid dumb url shortener

This commit is contained in:
2026-12-04 21:43:17 -05:00
parent 2554ba35de
commit a7539f731c
4 changed files with 1095 additions and 0 deletions
+31
View File
@@ -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();
}