{"record":{"id":"6e4e9bcf90b22d2a","repo":"gchq/CyberChef","slug":"error-alphabet-must-be-of-length-85","errorCode":null,"errorMessage":"Error: Alphabet must be of length 85","messagePattern":"Error: Alphabet must be of length 85","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/ToBase85.mjs","lineNumber":57,"sourceCode":"            }\n        ];\n    }\n\n    /**\n     * @param {ArrayBuffer} input\n     * @param {Object[]} args\n     * @returns {string}\n    */\n    run(input, args) {\n        input = new Uint8Array(input);\n        const alphabet = Utils.expandAlphRange(args[0]).join(\"\"),\n            encoding = alphabetName(alphabet),\n            includeDelim = args[1];\n        let result = \"\";\n\n        if (alphabet.length !== 85 ||\n            [].unique.call(alphabet).length !== 85) {\n            throw new OperationError(\"Error: Alphabet must be of length 85\");\n        }\n\n        if (input.length === 0) return \"\";\n\n        let block;\n        for (let i = 0; i < input.length; i += 4) {\n            block = (\n                ((input[i])          << 24) +\n                ((input[i + 1] || 0) << 16) +\n                ((input[i + 2] || 0) << 8)  +\n                ((input[i + 3] || 0))\n            ) >>> 0;\n\n            if (encoding !== \"Standard\" || block > 0) {\n                let digits = [];\n                for (let j = 0; j < 5; j++) {\n                    digits.push(block % 85);\n                    block = Math.floor(block / 85);","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/ToBase85.mjs#L39-L75","documentation":"To Base85 requires an alphabet of exactly 85 unique characters (ASCII85/Z85 variants). The guard enforces both length === 85 and a unique count of 85 before encoding, since Base85 packs 4 bytes into 5 symbols and needs all 85 symbols available.","triggerScenarios":"Changing the alphabet argument to fewer/more than 85 characters, or including duplicates, so either the length or uniqueness check fails.","commonSituations":"Swapping between ASCII85 and Z85 alphabets and mistyping one; pasting an alphabet with a stray space or missing character; using an expanded range that does not yield 85 unique symbols.","solutions":["Use the standard ASCII85 alphabet (0-9, A-Z, a-z, plus !-u) or the Z85 set as appropriate.","Verify the alphabet has exactly 85 distinct characters.","Remove any duplicate or whitespace characters."],"exampleFix":"// before: alphabet = \"0-9A-Za-z!-u\" mis-typed, <85 unique -> throws\n// after:  alphabet = a valid 85-character ASCII85 set            -> passes","handlingStrategy":"validation","validationCode":"const set = new Set([...alphabet]);\nif (alphabet.length !== 85 || set.size !== 85) {\n  throw new Error(\"Base85 alphabet must have 85 unique chars\");\n}","typeGuard":"const isValidBase85Alphabet = a => a.length === 85 && new Set(a).size === 85;","tryCatchPattern":"try { toBase85(input, [alphabet, includeDelim]); }\ncatch (e) { if (/length 85/.test(e.message)) { alphabet = DEFAULT_BASE85; } else throw e; }","preventionTips":["Pick a documented Base85 variant (ASCII85 or Z85) and use its exact alphabet.","Validate length and uniqueness before encoding.","Avoid whitespace inside the alphabet string."],"tags":["base85","alphabet","validation","argument"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}