{"record":{"id":"357b21bd8a7e5265","repo":"gchq/CyberChef","slug":"char-c-at-position-charindex-not-in-alphab","errorCode":null,"errorMessage":"Char '${c}' at position ${charIndex} not in alphabet","messagePattern":"Char '(.+?)' at position (.+?) not in alphabet","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/FromBase58.mjs","lineNumber":86,"sourceCode":"            [].unique.call(alphabet).length !== 58) {\n            throw new OperationError(\"Alphabet must be of length 58\");\n        }\n\n        if (input.length === 0) return [];\n\n        let zeroPrefix = 0;\n        for (let i = 0; i < input.length && input[i] === alphabet[0]; i++) {\n            zeroPrefix++;\n        }\n\n        [].forEach.call(input, function(c, charIndex) {\n            const index = alphabet.indexOf(c);\n\n            if (index === -1) {\n                if (removeNonAlphaChars) {\n                    return;\n                } else {\n                    throw new OperationError(`Char '${c}' at position ${charIndex} not in alphabet`);\n                }\n            }\n\n            let carry = index;\n\n            for (let i = 0; i < result.length; i++) {\n                carry += result[i] * 58;\n                result[i] = carry & 0xFF;\n                carry = carry >> 8;\n            }\n\n            while (carry > 0) {\n                result.push(carry & 0xFF);\n                carry = carry >> 8;\n            }\n        });\n\n        while (zeroPrefix--) {","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/FromBase58.mjs#L68-L104","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Keep 'Remove non-alphabet chars' enabled (default) to skip invalid characters.","Pre-trim whitespace and newlines from the input.","Confirm the input is genuinely Base58-encoded and uses the same alphabet variant as configured."],"exampleFix":"// before: removal off, dirty input\nfromBase58.run(' 1BvBMSE...\\n', [BITCOIN, false]) // space/newline not in alphabet\n// after: enable removal\nfromBase58.run(' 1BvBMSE...\\n', [BITCOIN, true])","handlingStrategy":"validation","validationCode":"// Pre-clean input: strip characters not in the configured alphabet when removal is off\nconst alphabet = Utils.expandAlphRange(args[0]).join('');\nif (!args[1]) {\n  input = input.split('').filter(c => alphabet.includes(c)).join('');\n}","typeGuard":"function charInAlphabet(c, alphabet) {\n  return alphabet.includes(c);\n}","tryCatchPattern":"try {\n  fromBase58.run(input, args);\n} catch (e) {\n  if (e.type === 'OperationError' && /not in alphabet/.test(e.message)) {\n    // enable removal or strip whitespace/non-alphabet chars\n  } else throw e;\n}","preventionTips":["Keep 'Remove non-alphabet chars' enabled for pasted/uncertain input.","Trim whitespace and newlines before decoding.","Remember Base58 excludes 0, O, I, l by design."],"tags":["base58","alphabet","input-validation","parsing"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}