mirror of
https://github.com/gchq/CyberChef.git
synced 2026-03-18 04:41:40 -07:00
feat(operations): add ToFullwidth operation for ASCII to fullwidth conversion
This commit is contained in:
parent
d195a51e2e
commit
e0498f4b32
2 changed files with 59 additions and 1 deletions
|
|
@ -49,6 +49,7 @@
|
|||
"Escape Unicode Characters",
|
||||
"Unescape Unicode Characters",
|
||||
"Normalise Unicode",
|
||||
"To Fullwidth",
|
||||
"To Quoted Printable",
|
||||
"From Quoted Printable",
|
||||
"To Punycode",
|
||||
|
|
@ -591,4 +592,4 @@
|
|||
"Comment"
|
||||
]
|
||||
}
|
||||
]
|
||||
]
|
||||
57
src/core/operations/ToFullwidth.mjs
Normal file
57
src/core/operations/ToFullwidth.mjs
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
/**
|
||||
* @author jyeu [chen@jyeu.xyz]
|
||||
* @copyright Crown Copyright 2026
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
|
||||
/**
|
||||
* To Fullwidth operation
|
||||
*/
|
||||
class ToFullwidth extends Operation {
|
||||
/**
|
||||
* ToFullwidth constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "To Fullwidth";
|
||||
this.module = "Encodings";
|
||||
this.description =
|
||||
"Converts ASCII (halfwidth) characters to their fullwidth Unicode equivalents (U+FF01–U+FF5E). Commonly used in security testing to bypass WAF keyword filters, evade regex-based blocklists, and exploit Unicode normalization (NFKC/NFKD) vulnerabilities in web applications and path parsers. For example, <code>/admin</code> may bypass a WAF rule matching <code>/admin</code> if the backend normalises Unicode before routing.";
|
||||
this.infoURL =
|
||||
"https://wikipedia.org/wiki/Halfwidth_and_fullwidth_forms_(Unicode_block)";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {never} _args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, _args) {
|
||||
let output = "";
|
||||
|
||||
for (const char of input) {
|
||||
const code = char.codePointAt(0);
|
||||
|
||||
if (code === 0x20) {
|
||||
// Regular space -> Ideographic space (U+3000)
|
||||
output += "\u3000";
|
||||
} else if (code >= 0x21 && code <= 0x7e) {
|
||||
// Visible ASCII characters -> Fullwidth equivalents (U+FF01–U+FF5E)
|
||||
output += String.fromCodePoint(code + 0xfee0);
|
||||
} else {
|
||||
// Non-ASCII characters (CJK, newlines, etc.) are passed through unchanged
|
||||
output += char;
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
export default ToFullwidth;
|
||||
Loading…
Add table
Add a link
Reference in a new issue