cyberchef/src/core/operations/RC6Decrypt.mjs
Medjedtxm d8f06b24bb feat: add RC6 block cipher
Add RC6 block cipher encrypt/decrypt operations.

RC6 is a symmetric block cipher designed by Ron Rivest et al.
It was an AES finalist and supports 128/192/256-bit keys.

Features:
- ECB, CBC, CFB, OFB, CTR modes
- Multiple padding options (PKCS7, Zero, None)
- 128-bit block size, 20 rounds

Includes official test vectors from IETF draft.
2026-02-01 10:48:37 -05:00

95 lines
3.1 KiB
JavaScript

/**
* @author Medjedtxm
* @copyright Crown Copyright 2026
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import Utils from "../Utils.mjs";
import OperationError from "../errors/OperationError.mjs";
import { toHex } from "../lib/Hex.mjs";
import { decryptRC6 } from "../lib/RC6.mjs";
/**
* RC6 Decrypt operation
*/
class RC6Decrypt extends Operation {
/**
* RC6Decrypt constructor
*/
constructor() {
super();
this.name = "RC6 Decrypt";
this.module = "Ciphers";
this.description = "RC6 is a symmetric key block cipher derived from RC5. It was designed by Ron Rivest, Matt Robshaw, Ray Sidney, and Yiqun Lisa Yin to meet the requirements of the AES competition, and was one of the five finalists. RC6 operates on 128-bit blocks and supports key sizes of 128, 192, or 256 bits with 20 rounds.<br><br>When using CBC or ECB mode, the PKCS#7 padding scheme is used.";
this.infoURL = "https://wikipedia.org/wiki/RC6";
this.inputType = "string";
this.outputType = "string";
this.args = [
{
"name": "Key",
"type": "toggleString",
"value": "",
"toggleValues": ["Hex", "UTF8", "Latin1", "Base64"]
},
{
"name": "IV",
"type": "toggleString",
"value": "",
"toggleValues": ["Hex", "UTF8", "Latin1", "Base64"]
},
{
"name": "Mode",
"type": "option",
"value": ["CBC", "CFB", "OFB", "CTR", "ECB"]
},
{
"name": "Input",
"type": "option",
"value": ["Hex", "Raw"]
},
{
"name": "Output",
"type": "option",
"value": ["Raw", "Hex"]
},
{
"name": "Padding",
"type": "option",
"value": ["PKCS5", "NO", "ZERO", "RANDOM", "BIT"]
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const key = Utils.convertToByteArray(args[0].string, args[0].option),
iv = Utils.convertToByteArray(args[1].string, args[1].option),
[,, mode, inputType, outputType, padding] = args;
if (key.length !== 16 && key.length !== 24 && key.length !== 32)
throw new OperationError(`Invalid key length: ${key.length} bytes
RC6 uses a key length of 16 bytes (128 bits), 24 bytes (192 bits), or 32 bytes (256 bits).`);
if (iv.length !== 16 && mode !== "ECB")
throw new OperationError(`Invalid IV length: ${iv.length} bytes
RC6 uses an IV length of 16 bytes (128 bits).
Make sure you have specified the type correctly (e.g. Hex vs UTF8).`);
input = Utils.convertToByteArray(input, inputType);
const output = decryptRC6(input, key, iv, mode, padding);
return outputType === "Hex" ? toHex(output, "") : Utils.byteArrayToUtf8(output);
}
}
export default RC6Decrypt;