gchq/CyberChef · error · OperationError

The key must consist only of letters in the English alphabet

Error message

The key must consist only of letters in the English alphabet

What it means

The Bifid cipher builds a 5x5 Polybius square from a keyword (with J merged into I). After uppercasing and the J->I replacement, the keyword string must consist only of A-Z letters. This OperationError fires when non-alphabetic characters survive that preprocessing and at least one unique letter remains, because non-letter glyphs cannot be placed in the Polybius grid.

Source

Thrown at src/core/operations/BifidCipherEncode.mjs:57

     * @param {Object[]} args
     * @returns {string}
     *
     * @throws {OperationError} if key is invalid
     */
    run(input, args) {
        const keywordStr = args[0].toUpperCase().replace("J", "I"),
            keyword = keywordStr.split("").unique(),
            alpha = "ABCDEFGHIKLMNOPQRSTUVWXYZ",
            xCo = [],
            yCo = [],
            structure = [];

        let output = "",
            count = 0;


        if (!/^[A-Z]+$/.test(keywordStr) && keyword.length > 0)
            throw new OperationError("The key must consist only of letters in the English alphabet");

        const polybius = genPolybiusSquare(keywordStr);

        input.replace("J", "I").split("").forEach(letter => {
            const alpInd = alpha.split("").indexOf(letter.toLocaleUpperCase()) >= 0;
            let polInd;

            if (alpInd) {
                for (let i = 0; i < 5; i++) {
                    polInd = polybius[i].indexOf(letter.toLocaleUpperCase());
                    if (polInd >= 0) {
                        xCo.push(polInd);
                        yCo.push(i);
                    }
                }

                if (alpha.split("").indexOf(letter) >= 0) {
                    structure.push(true);

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Sanitize the key before invoking the operation: strip everything except A-Z/a-z (key.replace(/[^A-Za-z]/g, '')).
  2. Leave the key empty if you want the default alphabet square (the check only fires when unique-letter count > 0).
  3. Validate the key in your UI/config layer with /^[A-Za-z]+$/ before passing it as args[0].

Example fix

// before
const args = ['my secret 123'];
// after
const args = ['mysecret'];
Defensive patterns

Strategy: validation

Validate before calling

const key = (args[0] || '').toUpperCase().replace(/J/g, 'I');
if (key.length > 0 && !/^[A-Z]+$/.test(key)) {
  throw new Error('Bifid key must be A-Z only');
}

Type guard

function isBifidKey(k) {
  const s = String(k).toUpperCase().replace(/J/g, 'I');
  return s.length === 0 || /^[A-Z]+$/.test(s);
}

Try / catch

try { bifidEncode.run(input, [key]); }
catch (e) { if (/letters in the English alphabet/.test(e.message)) { /* sanitize key */ } else throw e; }

Prevention

When it happens

Trigger: Calling BifidCipherEncode.run with an args[0] key that contains digits, punctuation, whitespace, or accented/non-Latin characters while also containing at least one letter (so keyword.length > 0 and /^[A-Z]+$/ fails).

Common situations: User pastes a passphrase containing spaces, numbers, or symbols; an IME or autocorrect inserts non-ASCII characters; a config/UI forwards an unvalidated key string.

Related errors


AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13). Data as JSON: /api/errors/e6c4b10a5af130fd. Report an issue: GitHub.