{"record":{"id":"7cebe837967e7175","repo":"gchq/CyberChef","slug":"invalid-ita2-character-errltr-7cebe8","errorCode":null,"errorMessage":"Invalid ITA2 character : ${errltr}","messagePattern":"Invalid ITA2 character : (.+?)","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/Lorenz.mjs","lineNumber":515,"sourceCode":"    }\n\n    /**\n     * Convert input plaintext to ITA2\n     */\n    convertToITA2(input, intype, mode) {\n        let result = \"\";\n        let figShifted = false;\n\n        for (const character of input) {\n            const letter = character.toUpperCase();\n\n            // Convert input text to ITA2 (including figure/letter shifts)\n            if (intype === \"ITA2\" || mode === \"Receive\") {\n                if (validITA2.indexOf(letter) === -1) {\n                    let errltr = letter;\n                    if (errltr===\"\\n\") errltr = \"Carriage Return\";\n                    if (errltr===\" \") errltr = \"Space\";\n                    throw new OperationError(\"Invalid ITA2 character : \"+errltr);\n                }\n                result += letter;\n            } else {\n                if (validChars.indexOf(letter) === -1) throw new OperationError(\"Invalid Plaintext character : \"+letter);\n\n                if (!figShifted && figShiftedChars.indexOf(letter) !== -1) {\n                    // in letters mode and next char needs to be figure shifted\n                    figShifted = true;\n                    result += \"55\" + figShiftArr[letter];\n                } else if (figShifted) {\n                    // in figures mode and next char needs to be letter shifted\n                    if (letter===\"\\n\") {\n                        result += \"34\";\n                    } else if (letter===\"\\r\") {\n                        result += \"4\";\n                    } else if (figShiftedChars.indexOf(letter) === -1) {\n                        figShifted = false;\n                        result += \"88\" + letter;","sourceCodeStart":497,"sourceCodeEnd":533,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/Lorenz.mjs#L497-L533","documentation":"Thrown by the Lorenz SZ operation when, in ITA2 input mode, an input character does not map to a valid ITA2 code. The operation supports two input paths: when intype==='ITA2' or mode==='Receive' (Lorenz.mjs:515), each character is looked up against validITA2; if it is not found the character is rejected. Newlines and spaces are renamed to 'Carriage Return' and 'Space' in the message for clarity. This enforces the 5-bit ITA2 alphabet used by the real teleprinter.","triggerScenarios":"Setting 'Input Type' to 'ITA2' (or 'Mode' to 'Receive') and feeding input containing characters outside the ITA2 set — e.g. lowercase letters (only after toUpperCase most are valid, but punctuation not in ITA2 is not), digits as digits rather than their figure-shift codes, or extended Unicode. Triggered at Lorenz.mjs:515 inside the per-character loop.","commonSituations":"Pasting arbitrary UTF-8 text into an ITA2 field; expecting digits '0'-'9' to be accepted directly (ITA2 encodes them via figure shift, not as literal digits); feeding a Space or newline where the receiver is configured for strict ITA2; mixing Receive mode with plaintext content.","solutions":["Provide only characters that exist in the ITA2 alphabet (the operation upper-cases input, so use the ITA2 letter/figure-shift characters).","If your data is plaintext, set 'Input Type' to 'Plaintext' (and 'Mode' to 'Send') so it is encoded into ITA2 for you.","For digits and punctuation, supply them as plaintext in Send mode so figure/letter shifts are inserted automatically.","Strip or replace unsupported characters (e.g. tabs, Unicode) before feeding the ITA2 path."],"exampleFix":"// before — digits/unicode fed directly to ITA2 path\n// intype='ITA2', input='HELLO 123 ✓'\n\n// after — send as Plaintext so the op encodes to ITA2\n// intype='Plaintext', input='HELLO 123'","handlingStrategy":"validation","validationCode":"// Mirror the operation's own alphabet: ITA2-valid characters.\n// Build the set from the same source the op uses, or maintain an explicit allow-list.\nconst VALID_ITA2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890/+-%\"#&\\\\'():,=!.?';\\nfunction onlyITA2(str) {\n  return [...str.toUpperCase()].every(c => VALID_ITA2.includes(c) || c === '\\n' || c === ' ');\n}\nif ((intype === 'ITA2' || mode === 'Receive') && !onlyITA2(input)) {\n  throw new Error('Input contains non-ITA2 characters');\n}","typeGuard":"function isITA2String(v: unknown): v is string {\n  if (typeof v !== 'string') return false;\n  const allowed = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890/+-%\"#&\\'():,=!.?';\n  return [...v.toUpperCase()].every(c => allowed.includes(c) || c === '\\n' || c === ' ');\n}","tryCatchPattern":null,"preventionTips":["When data is plaintext, use Input Type 'Plaintext' / Mode 'Send' so the op encodes ITA2 for you.","Filter or transliterate non-ITA2 characters before the ITA2 path.","Treat digits/punctuation as plaintext, not literal ITA2 input."],"tags":["lorenz","cipher","validation","ita2","character-encoding"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}