{"record":{"id":"baa3952c9baaac7e","repo":"gchq/CyberChef","slug":"invalid-number-of-rounds-rounds-rounds-must-b-baa395","errorCode":null,"errorMessage":"Invalid number of rounds: ${rounds}\n\nRounds must be an integer between 1 and 255. Standard XTEA uses 32 rounds.","messagePattern":"Invalid number of rounds: (.+?)\n\nRounds must be an integer between 1 and 255\\. Standard XTEA uses 32 rounds\\.","errorType":"validation","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/XTEADecrypt.mjs","lineNumber":96,"sourceCode":"    run(input, args) {\n        const key = Utils.convertToByteArray(args[0].string, args[0].option),\n            iv = Utils.convertToByteArray(args[1].string, args[1].option),\n            [,, mode, inputType, outputType, padding, rounds] = args;\n\n        if (key.length !== 16)\n            throw new OperationError(`Invalid key length: ${key.length} bytes\n\nXTEA requires a key length of 16 bytes (128 bits).\nMake sure you have specified the type correctly (e.g. Hex vs UTF8).`);\n\n        if (iv.length !== TEA_BLOCK_SIZE && iv.length !== 0 && mode !== \"ECB\")\n            throw new OperationError(`Invalid IV length: ${iv.length} bytes\n\nXTEA uses an IV length of ${TEA_BLOCK_SIZE} bytes (${TEA_BLOCK_SIZE * 8} bits).\nMake sure you have specified the type correctly (e.g. Hex vs UTF8).`);\n\n        if (!Number.isInteger(rounds) || rounds < 1 || rounds > 255)\n            throw new OperationError(`Invalid number of rounds: ${rounds}\n\nRounds must be an integer between 1 and 255. Standard XTEA uses 32 rounds.`);\n\n        // Default IV to null bytes if empty (like AES)\n        const actualIv = iv.length === 0 ? new Array(TEA_BLOCK_SIZE).fill(0) : iv;\n\n        input = Utils.convertToByteArray(input, inputType);\n        const output = decryptXTEA(input, key, actualIv, mode, padding, rounds);\n        return outputType === \"Hex\" ? toHex(output, \"\") : Utils.byteArrayToUtf8(output);\n    }\n\n}\n\nexport default XTEADecrypt;\n","sourceCodeStart":78,"sourceCodeEnd":111,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/XTEADecrypt.mjs#L78-L111","documentation":"Thrown by XTEADecrypt.run when args[6] (rounds) is not an integer or falls outside 1–255. Standard XTEA uses 32 rounds; the bounds let you vary it while staying in a single byte, but the count must match what was used for encryption or decryption yields garbage rather than an error.","triggerScenarios":"rounds is a fractional number, NaN, <1, >255, or supplied as a JSON string (fails Number.isInteger). Note: a wrong-but-valid integer (e.g. 33 instead of 32) does NOT throw — it silently decrypts incorrectly.","commonSituations":"Mismatched round counts between encrypt and decrypt operations; recipe config serialised with rounds as a string; manual override to a non-standard count.","solutions":["Use the same rounds value that was used to encrypt (commonly 32).","Ensure rounds is passed as a number, not a string, and is an integer within 1–255.","If unsure of the original count, try 32 (the XTEA standard) first."],"exampleFix":"// before\nargs:[key, iv, \"CBC\", \"Hex\", \"Hex\", \"PKCS5\", \"33\"]; // string -> not integer\n// after\nargs:[key, iv, \"CBC\", \"Hex\", \"Hex\", \"PKCS5\", 32];","handlingStrategy":"validation","validationCode":"function xteaRoundsArg(rounds) {\n  if (!Number.isInteger(rounds) || rounds < 1 || rounds > 255) throw new Error(\"rounds must be an integer 1..255\");\n  return rounds;\n}","typeGuard":"const isValidXteaRounds = (r) => Number.isInteger(r) && r >= 1 && r <= 255;","tryCatchPattern":"try { chef.bake(data, recipe); } catch (e) { if (/Invalid number of rounds/.test(e.message)) { /* set rounds=32 */ } else throw e; }","preventionTips":["Standardise on 32 rounds and reuse the same value to decrypt.","Pass rounds as a number, not a string.","Validate integer range before building the recipe."],"tags":["xtea","crypto","rounds","operation-args"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}