gchq/CyberChef · error · OperationError
Value ${Utils.bin(n, 4)} is not in the encoding scheme
Error message
Value ${Utils.bin(n, 4)} is not in the encoding scheme What it means
Thrown by From BCD when a parsed nibble value is not present in the selected encoding scheme's lookup array (encoding.indexOf(n) < 0). Each BCD scheme (8 4 2 1, Excess-3, etc.) only accepts certain 4-bit patterns; a nibble outside that set is invalid for the scheme. The offending 4-bit value is shown in binary for diagnostics.
Source
Thrown at src/core/operations/FromBCD.mjs:114
// Discard each high nibble
for (let i = 0; i < nibbles.length; i++) {
nibbles.splice(i, 1); // lgtm [js/loop-iteration-skipped-due-to-shifting]
}
}
if (signed) {
const sign = nibbles.pop();
if (sign === 13 ||
sign === 11) {
// Negative
output += "-";
}
}
nibbles.forEach(n => {
if (isNaN(n)) throw new OperationError("Invalid input");
const val = encoding.indexOf(n);
if (val < 0) throw new OperationError(`Value ${Utils.bin(n, 4)} is not in the encoding scheme`);
output += val.toString();
});
return new BigNumber(output);
}
}
export default FromBCD;
View on GitHub (pinned to 4290ea7539)
Solutions
- Identify the correct BCD encoding scheme used by the source system and select it.
- If the data may contain hex digits, verify it is actually BCD and not plain hex.
- Try alternate schemes (8 4 2 1, 4 2 2 1, 5 4 2 1, Excess-3) to find the matching one.
Example fix
// before: wrong scheme for the data fromBcd.run(input, ['8 4 2 1', true, false, 'Raw']) // nibble 0xA not in 8421 // after: use a scheme that accepts the pattern, or confirm data is BCD fromBcd.run(input, ['Excess-3', true, false, 'Raw'])
Defensive patterns
Strategy: validation
Validate before calling
// Check each nibble's 4-bit value is valid for the chosen scheme before decoding
const validSet = ENCODING_LOOKUP[scheme];
// after splitting into nibbles, ensure encoding.includes(n) for each
if (!nibbles.every(n => validSet.includes(n))) {
// pick a different scheme or reject the data
} Type guard
function nibbleInScheme(n, scheme) {
return ENCODING_LOOKUP[scheme].includes(n);
} Try / catch
try {
fromBcd.run(input, args);
} catch (e) {
if (e.type === 'OperationError' && /is not in the encoding scheme/.test(e.message)) {
// wrong scheme; try alternate schemes (8421, 4221, 5421, Excess-3)
} else throw e;
} Prevention
- Identify the source system's BCD variant before selecting the scheme.
- If unsure, try the common schemes in turn to find the matching one.
- Reject nibbles 0xA-0xF for plain 8 4 2 1 BCD.
When it happens
Trigger: Selecting the wrong BCD scheme for the data (e.g. feeding Excess-3 data as 8 4 2 1); data containing nibble values like 0xA-0xF which are invalid in plain BCD; unsigned data interpreted under a scheme that excludes the encountered patterns.
Common situations: Not knowing which BCD variant the source used; legacy mainframe/EBCDIC data with a different scheme; mixing packed/unpacked assumptions.
Related errors
- Invalid input
- Invalid value
- Human-Readable Part (HRP) cannot be empty.
- HRP contains invalid character at position ${i}. Only printa
- Encoded string exceeds maximum length of 90 characters (got
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/d542c8a20d3d8269.
Report an issue: GitHub.