gchq/CyberChef · error · OperationError

Char '${c}' at position ${charIndex} not in alphabet

Error message

Char '${c}' at position ${charIndex} not in alphabet

What it means

Thrown by From Base58 when a character in the input is not in the alphabet and 'Remove non-alphabet chars' is disabled. The offending character and its position are reported. With removal enabled (default), such characters are silently skipped instead.

Source

Thrown at src/core/operations/FromBase58.mjs:86

            [].unique.call(alphabet).length !== 58) {
            throw new OperationError("Alphabet must be of length 58");
        }

        if (input.length === 0) return [];

        let zeroPrefix = 0;
        for (let i = 0; i < input.length && input[i] === alphabet[0]; i++) {
            zeroPrefix++;
        }

        [].forEach.call(input, function(c, charIndex) {
            const index = alphabet.indexOf(c);

            if (index === -1) {
                if (removeNonAlphaChars) {
                    return;
                } else {
                    throw new OperationError(`Char '${c}' at position ${charIndex} not in alphabet`);
                }
            }

            let carry = index;

            for (let i = 0; i < result.length; i++) {
                carry += result[i] * 58;
                result[i] = carry & 0xFF;
                carry = carry >> 8;
            }

            while (carry > 0) {
                result.push(carry & 0xFF);
                carry = carry >> 8;
            }
        });

        while (zeroPrefix--) {

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Keep 'Remove non-alphabet chars' enabled (default) to skip invalid characters.
  2. Pre-trim whitespace and newlines from the input.
  3. Confirm the input is genuinely Base58-encoded and uses the same alphabet variant as configured.

Example fix

// before: removal off, dirty input
fromBase58.run(' 1BvBMSE...\n', [BITCOIN, false]) // space/newline not in alphabet
// after: enable removal
fromBase58.run(' 1BvBMSE...\n', [BITCOIN, true])
Defensive patterns

Strategy: validation

Validate before calling

// Pre-clean input: strip characters not in the configured alphabet when removal is off
const alphabet = Utils.expandAlphRange(args[0]).join('');
if (!args[1]) {
  input = input.split('').filter(c => alphabet.includes(c)).join('');
}

Type guard

function charInAlphabet(c, alphabet) {
  return alphabet.includes(c);
}

Try / catch

try {
  fromBase58.run(input, args);
} catch (e) {
  if (e.type === 'OperationError' && /not in alphabet/.test(e.message)) {
    // enable removal or strip whitespace/non-alphabet chars
  } else throw e;
}

Prevention

When it happens

Trigger: Disabling non-alphabet removal and feeding input with characters outside the 58-char alphabet (whitespace, 0, O, I, l which Base58 deliberately excludes); pasted text with newlines; mixed-case confusion.

Common situations: Pasting a Bitcoin address with surrounding whitespace/newlines when removal is off; data containing the visually-ambiguous chars (0/O, l/I) that Base58 omits; concatenation artifacts.

Related errors


AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13). Data as JSON: /api/errors/357b21bd8a7e5265. Report an issue: GitHub.