{"record":{"id":"5530436c62e2dde0","repo":"gchq/CyberChef","slug":"alphabet-must-be-of-length-85","errorCode":null,"errorMessage":"Alphabet must be of length 85","messagePattern":"Alphabet must be of length 85","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/FromBase85.mjs","lineNumber":91,"sourceCode":"                args: [\"0-9A-Za-z!#$%&()*+\\\\-;<=>?@^_`{|}~\"],\n            },\n        ];\n    }\n\n    /**\n     * @param {string} input\n     * @param {Object[]} args\n     * @returns {byteArray}\n     */\n    run(input, args) {\n        const alphabet = Utils.expandAlphRange(args[0]).join(\"\"),\n            removeNonAlphChars = args[1],\n            allZeroGroupChar = typeof args[2] === \"string\" ? args[2].slice(0, 1) : \"\",\n            result = [];\n\n        if (alphabet.length !== 85 ||\n            [].unique.call(alphabet).length !== 85) {\n            throw new OperationError(\"Alphabet must be of length 85\");\n        }\n\n        if (allZeroGroupChar && alphabet.includes(allZeroGroupChar)) {\n            throw new OperationError(\"The all-zero group char cannot appear in the alphabet\");\n        }\n\n        // Remove delimiters if present\n        const matches = input.match(/^<~(.+?)~>$/);\n        if (matches !== null) input = matches[1];\n\n        // Remove non-alphabet characters\n        if (removeNonAlphChars) {\n            const re = new RegExp(\"[^~\" + allZeroGroupChar +alphabet.replace(/[[\\]\\\\\\-^$]/g, \"\\\\$&\") + \"]\", \"g\");\n            input = input.replace(re, \"\");\n            // Remove delimiters again if present (incase of non-alphabet characters in front/behind delimiters)\n            const matches = input.match(/^<~(.+?)~>$/);\n            if (matches !== null) input = matches[1];\n        }","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/FromBase85.mjs#L73-L109","documentation":"Thrown by From Base85 when the supplied alphabet, after expandAlphRange expansion, does not have exactly 85 unique characters. Ascii85/Base85 requires an 85-symbol alphabet; both length and uniqueness are verified. This is a configuration error on the Alphabet argument.","triggerScenarios":"Providing a custom alphabet shorter/longer than 85; an alphabet with duplicate characters; a range like A-Z that expands to fewer than expected; mixing presets.","commonSituations":"User edits the alphabet field and loses characters; confusion between the standard !-u range and the IPv6/z85 alphabets; copy-paste truncation.","solutions":["Use a built-in preset (!-u, the IPv6 variant, z85) rather than a hand-typed alphabet.","If custom, verify exactly 85 unique characters.","Check expandAlphRange output if using A-Z style ranges."],"exampleFix":"// before: 84-char alphabet\nfromBase85.run(input, ['!-t']) // expands to 84\n// after: standard Ascii85 range (85)\nfromBase85.run(input, ['!-u'])","handlingStrategy":"validation","validationCode":"const alphabet = Utils.expandAlphRange(args[0]).join('');\nconst unique = new Set(alphabet.split(''));\nif (alphabet.length !== 85 || unique.size !== 85) {\n  // use a built-in preset (!-u, z85, IPv6); do not call fromBase85.run()\n}","typeGuard":"function isValidBase85Alphabet(a) {\n  return a.length === 85 && new Set(a).size === 85;\n}","tryCatchPattern":"try {\n  fromBase85.run(input, args);\n} catch (e) {\n  if (e.type === 'OperationError' && /Alphabet must be of length 85/.test(e.message)) {\n    // reset alphabet to a built-in preset\n  } else throw e;\n}","preventionTips":["Use built-in alphabet presets (!-u, z85) rather than custom alphabets.","Verify exactly 85 unique characters before invoking.","Check expandAlphRange output when using ranges."],"tags":["base85","ascii85","alphabet","argument-validation","config"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}