mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-24 16:56:15 -04:00
feat(Modhex): Introduce basic Modhex conversion
Signed-off-by: İlteriş Yağıztegin Eroğlu <ilteris@asenkron.com.tr>
This commit is contained in:
parent
4c5577ddeb
commit
edd22372d8
6 changed files with 458 additions and 1 deletions
84
src/core/operations/FromModhex.mjs
Normal file
84
src/core/operations/FromModhex.mjs
Normal file
|
@ -0,0 +1,84 @@
|
|||
/**
|
||||
* @author linuxgemini [ilteris@asenkron.com.tr]
|
||||
* @copyright Crown Copyright 2024
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import { FROM_MODHEX_DELIM_OPTIONS, fromModhex } from "../lib/Modhex.mjs";
|
||||
|
||||
/**
|
||||
* From Modhex operation
|
||||
*/
|
||||
class FromModhex extends Operation {
|
||||
|
||||
/**
|
||||
* FromModhex constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "From Modhex";
|
||||
this.module = "Default";
|
||||
this.description = "Converts a modhex byte string back into its raw value.";
|
||||
this.infoURL = "https://en.wikipedia.org/wiki/YubiKey#ModHex";
|
||||
this.inputType = "string";
|
||||
this.outputType = "byteArray";
|
||||
this.args = [
|
||||
{
|
||||
name: "Delimiter",
|
||||
type: "option",
|
||||
value: FROM_MODHEX_DELIM_OPTIONS
|
||||
}
|
||||
];
|
||||
this.checks = [
|
||||
{
|
||||
pattern: "^(?:[cbdefghijklnrtuv]{2})+$",
|
||||
flags: "i",
|
||||
args: ["None"]
|
||||
},
|
||||
{
|
||||
pattern: "^[cbdefghijklnrtuv]{2}(?: [cbdefghijklnrtuv]{2})*$",
|
||||
flags: "i",
|
||||
args: ["Space"]
|
||||
},
|
||||
{
|
||||
pattern: "^[cbdefghijklnrtuv]{2}(?:,[cbdefghijklnrtuv]{2})*$",
|
||||
flags: "i",
|
||||
args: ["Comma"]
|
||||
},
|
||||
{
|
||||
pattern: "^[cbdefghijklnrtuv]{2}(?:;[cbdefghijklnrtuv]{2})*$",
|
||||
flags: "i",
|
||||
args: ["Semi-colon"]
|
||||
},
|
||||
{
|
||||
pattern: "^[cbdefghijklnrtuv]{2}(?::[cbdefghijklnrtuv]{2})*$",
|
||||
flags: "i",
|
||||
args: ["Colon"]
|
||||
},
|
||||
{
|
||||
pattern: "^[cbdefghijklnrtuv]{2}(?:\\n[cbdefghijklnrtuv]{2})*$",
|
||||
flags: "i",
|
||||
args: ["Line feed"]
|
||||
},
|
||||
{
|
||||
pattern: "^[cbdefghijklnrtuv]{2}(?:\\r\\n[cbdefghijklnrtuv]{2})*$",
|
||||
flags: "i",
|
||||
args: ["CRLF"]
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {byteArray}
|
||||
*/
|
||||
run(input, args) {
|
||||
const delim = args[0] || "Auto";
|
||||
return fromModhex(input, delim, 2);
|
||||
}
|
||||
}
|
||||
|
||||
export default FromModhex;
|
55
src/core/operations/ToModhex.mjs
Normal file
55
src/core/operations/ToModhex.mjs
Normal file
|
@ -0,0 +1,55 @@
|
|||
/**
|
||||
* @author linuxgemini [ilteris@asenkron.com.tr]
|
||||
* @copyright Crown Copyright 2024
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import { TO_MODHEX_DELIM_OPTIONS, toModhex } from "../lib/Modhex.mjs";
|
||||
import Utils from "../Utils.mjs";
|
||||
|
||||
/**
|
||||
* To Modhex operation
|
||||
*/
|
||||
class ToModhex extends Operation {
|
||||
|
||||
/**
|
||||
* ToModhex constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "To Modhex";
|
||||
this.module = "Default";
|
||||
this.description = "Converts the input string to modhex bytes separated by the specified delimiter.";
|
||||
this.infoURL = "https://en.wikipedia.org/wiki/YubiKey#ModHex";
|
||||
this.inputType = "ArrayBuffer";
|
||||
this.outputType = "string";
|
||||
this.args = [
|
||||
{
|
||||
name: "Delimiter",
|
||||
type: "option",
|
||||
value: TO_MODHEX_DELIM_OPTIONS
|
||||
},
|
||||
{
|
||||
name: "Bytes per line",
|
||||
type: "number",
|
||||
value: 0
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ArrayBuffer} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
const delim = Utils.charRep(args[0]);
|
||||
const lineSize = args[1];
|
||||
|
||||
return toModhex(new Uint8Array(input), delim, 2, "", lineSize);
|
||||
}
|
||||
}
|
||||
|
||||
export default ToModhex;
|
Loading…
Add table
Add a link
Reference in a new issue