This commit is contained in:
Saee Biwalkar 2024-10-01 09:17:27 +05:30
parent 0a40a97a67
commit a35b10cdb9
6 changed files with 2 additions and 700 deletions

View file

@ -1,149 +0,0 @@
/**
* @author n1474335
* @copyright Crown Copyright 2016
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import Utils from "../Utils.mjs";
import forge from "node-forge";
/**
* RC5 Decrypt operation
*/
class RC5Decrypt extends Operation {
/**
* RC5Decrypt constructor
*/
constructor() {
super();
this.name = "RC5 Decrypt";
this.module = "Ciphers";
this.description = "RC5 is a fast block cipher designed by Ron Rivest in 1994. This operation decrypts data encrypted with RC5 using the specified key and IV.<br><br><b>Key:</b> RC5 uses a variable size key.<br><br><b>IV:</b> To run the cipher in CBC mode, the Initialization Vector should be 8 bytes long. If the IV is left blank, the cipher will run in ECB mode.<br><br><b>Padding:</b> In both CBC and ECB mode, PKCS#7 padding will be used.";
this.infoURL = "https://en.wikipedia.org/wiki/RC5";
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": "Input",
"type": "option",
"value": ["Raw", "Hex"]
},
{
"name": "Output",
"type": "option",
"value": ["Hex", "Raw"]
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const key = Utils.convertToByteString(args[0].string, args[0].option),
iv = Utils.convertToByteString(args[1].string, args[1].option),
[,, inputType, outputType] = args,
decipher = forge.rc5.createDecryptionCipher(key);
input = Utils.convertToByteString(input, inputType);
decipher.start(iv || null);
decipher.update(forge.util.createBuffer(input));
decipher.finish();
return outputType === "Hex" ? decipher.output.toHex() : decipher.output.getBytes();
}
}
export default RC5Decrypt;

View file

@ -1,151 +0,0 @@
/**
* @author
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import Utils from "../Utils.mjs";
import forge from "node-forge";
/**
* RC5 Encrypt operation
*/
class RC5Encrypt extends Operation {
/**
* RC5Encrypt constructor
*/
constructor() {
super();
this.name = "RC5 Encrypt";
this.module = "Ciphers";
this.description = "RC5 is a symmetric-key block cipher designed by Ron Rivest in 1994. 'RC' stands for 'Rivest Cipher'.<br><br><b>Key:</b> RC5 uses a variable size key.<br><br>You can generate a password-based key using one of the KDF operations.<br><br><b>IV:</b> To run the cipher in CBC mode, the Initialization Vector should be 8 bytes long. If the IV is left blank, the cipher will run in ECB mode.<br><br><b>Padding:</b> In both CBC and ECB mode, PKCS#7 padding will be used.";
this.infoURL = "https://en.wikipedia.org/wiki/RC5";
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": "Input",
"type": "option",
"value": ["Raw", "Hex"]
},
{
"name": "Output",
"type": "option",
"value": ["Hex", "Raw"]
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const key = Utils.convertToByteString(args[0].string, args[0].option),
iv = Utils.convertToByteString(args[1].string, args[1].option),
[,, inputType, outputType] = args,
cipher = forge.rc5.createEncryptionCipher(key, 12); // Default 12 rounds
input = Utils.convertToByteString(input, inputType);
cipher.start(iv || null);
cipher.update(forge.util.createBuffer(input));
cipher.finish();
return outputType === "Hex" ? cipher.output.toHex() : cipher.output.getBytes();
}
}
export default RC5Encrypt;

View file

@ -1,189 +0,0 @@
/**
* @author n1474335 [n1474335@gmail.com]
* @copyright Crown Copyright 2024
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import Utils from "../Utils.mjs";
import forge from "node-forge";
/**
* 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, designed by Ron Rivest and others. It provides security for various applications.<br><br><b>Key:</b> RC6 uses a variable size key.<br><br><b>IV:</b> To run the cipher in CBC mode, the Initialization Vector should be 16 bytes long. If the IV is left blank, the cipher will run in ECB mode.<br><br><b>Padding:</b> In both CBC and ECB mode, PKCS#7 padding will be used.";
this.infoURL = "https://en.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": "Input",
"type": "option",
"value": ["Raw", "Hex"]
},
{
"name": "Output",
"type": "option",
"value": ["Hex", "Raw"]
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const key = Utils.convertToByteString(args[0].string, args[0].option),
iv = Utils.convertToByteString(args[1].string, args[1].option),
[,, inputType, outputType] = args;
// Create the key schedule
const S = this.rc6KeySchedule(key);
// Convert input based on input type
input = Utils.convertToByteString(input, inputType);
// Initialize the cipher for decryption
const cipher = forge.rc6.createDecryptionCipher(S);
cipher.start(iv || null);
cipher.update(forge.util.createBuffer(input));
cipher.finish();
// Return the output in the specified format
return outputType === "Hex" ? cipher.output.toHex() : cipher.output.getBytes();
}
/**
* RC6 Key Schedule function (simplified version)
* @param {string} key - The encryption key
* @returns {Array} - The key schedule
*/
rc6KeySchedule(key) {
// Implementation of the RC6 key schedule goes here
// For simplicity, this part is omitted; it should return the key schedule (array S)
return [];
}
}
export default RC6Decrypt;

View file

@ -1,209 +0,0 @@
/**
* @author
* @copyright
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import Utils from "../Utils.mjs";
import forge from "node-forge";
/**
* RC6 Encrypt operation
*/
class RC6Encrypt extends Operation {
/**
* RC6Encrypt constructor
*/
constructor() {
super();
this.name = "RC6 Encrypt";
this.module = "Ciphers";
this.description = "RC6 is a symmetric key block cipher derived from RC5. It was designed for high performance and security.<br><br><b>Key:</b> RC6 uses variable-length keys typically 128, 192, or 256 bits.<br><br><b>IV:</b> To run the cipher in CBC mode, the Initialization Vector should be 16 bytes long. If the IV is left blank, the cipher will run in ECB mode.<br><br><b>Padding:</b> In both CBC and ECB mode, PKCS#7 padding will be used.";
this.infoURL = "https://en.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": "Input",
"type": "option",
"value": ["Raw", "Hex"]
},
{
"name": "Output",
"type": "option",
"value": ["Hex", "Raw"]
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const key = Utils.convertToByteString(args[0].string, args[0].option),
iv = Utils.convertToByteString(args[1].string, args[1].option),
[,, inputType, outputType] = args;
input = Utils.convertToByteString(input, inputType);
// RC6 encryption implementation (you will need to manually implement RC6 or use a library)
const cipher = new RC6Cipher(key); // Replace with RC6 implementation
cipher.start(iv || null); // Use IV for CBC mode or null for ECB mode
cipher.update(forge.util.createBuffer(input)); // Encrypt the input
cipher.finish(); // Complete encryption process
return outputType === "Hex" ? cipher.output.toHex() : cipher.output.getBytes(); // Return encrypted output in desired format
}
}
// Example RC6 cipher class (you will need to provide actual RC6 implementation)
class RC6Cipher {
constructor(key) {
this.key = key;
// Initialize key schedule and other RC6 parameters
}
start(iv) {
// Initialize IV and prepare for encryption
}
update(buffer) {
// Perform RC6 encryption on the buffer
}
finish() {
// Finalize encryption
}
get output() {
// Return the encrypted data
return {
toHex: () => { /* return encrypted data in hex */ },
getBytes: () => { /* return encrypted data as bytes */ }
};
}
}
export default RC6Encrypt;

View file

@ -98,4 +98,4 @@ class VigenèreDecode extends Operation {
}
}
export default VigenèreDecode;
export default VigenèreDecode;

View file

@ -97,4 +97,4 @@ class VigenèreEncode extends Operation {
}
}
export default VigenèreEncode;
export default VigenèreEncode;