gchq/CyberChef · error · OperationError
Error: alphabet must be of length 58
Error message
Error: alphabet must be of length 58
What it means
To Base58 requires an alphabet of exactly 58 characters, and all 58 must be distinct. The guard checks both length === 58 and unique count === 58, because Base58's whole purpose is a 58-symbol alphabet (Bitcoin-style excludes ambiguous 0/O/I/l).
Source
Thrown at src/core/operations/ToBase58.mjs:52
}
];
}
/**
* @param {ArrayBuffer} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
input = new Uint8Array(input);
let alphabet = args[0] || ALPHABET_OPTIONS[0].value,
result = [];
alphabet = Utils.expandAlphRange(alphabet).join("");
if (alphabet.length !== 58 ||
[].unique.call(alphabet).length !== 58) {
throw new OperationError("Error: alphabet must be of length 58");
}
if (input.length === 0) return "";
let zeroPrefix = 0;
for (let i = 0; i < input.length && input[i] === 0; i++) {
zeroPrefix++;
}
input.forEach(function(b) {
let carry = b;
for (let i = 0; i < result.length; i++) {
carry += result[i] << 8;
result[i] = carry % 58;
carry = (carry / 58) | 0;
}
View on GitHub (pinned to 4290ea7539)
Solutions
- Use the default Bitcoin alphabet: 123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz.
- Count the alphabet characters and ensure exactly 58 unique ones.
- Use an alphabetic range expansion (e.g. 'A-Z') only if it expands to 58 unique characters.
Example fix
// before: alphabet = "12345..." (truncated, <58 chars) -> throws // after: alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" -> 58 unique, passes
Defensive patterns
Strategy: validation
Validate before calling
const set = new Set([...alphabet]);
if (alphabet.length !== 58 || set.size !== 58) {
throw new Error("Base58 alphabet must have 58 unique chars");
} Type guard
const isValidBase58Alphabet = a => a.length === 58 && new Set(a).size === 58;
Try / catch
try { toBase58(input, [alphabet]); }
catch (e) { if (/length 58/.test(e.message)) { alphabet = DEFAULT_BASE58; } else throw e; } Prevention
- Use the canonical 58-character Bitcoin alphabet unless you have a specific variant.
- Validate length and uniqueness before encoding.
- Avoid hand-typing alphabets; copy from a trusted source.
When it happens
Trigger: Editing the alphabet argument so it no longer has 58 unique characters: fewer/more characters, duplicate characters, or an expanded alphabetic range (e.g. A-Z) that does not total 58.
Common situations: Customising the alphabet for a non-standard Base58 variant; accidental truncation when pasting; typing an alphabet with a repeated symbol.
Related errors
- Error: Alphabet must be of length 85
- Invalid Base64 alphabet length (${alphabet.length}): ${alpha
- Error: Base64 alphabet should be 64 characters long, or 65 w
- Byte length must be a positive integer
- Letter ${letter} is not included in LS47
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/0d605661e5929ea8.
Report an issue: GitHub.