Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ROT13/47 Brute Force #1264

Merged
merged 1 commit into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/core/config/Categories.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@
"RC4",
"RC4 Drop",
"ROT13",
"ROT13 Brute Force",
"ROT47",
"ROT47 Brute Force",
"XOR",
"XOR Brute Force",
"Vigenère Encode",
Expand Down
102 changes: 102 additions & 0 deletions src/core/operations/ROT13BruteForce.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/**
* @author MikeCAT
* @license Apache-2.0
*/

import Operation from "../Operation.mjs";
import Utils from "../Utils.mjs";

/**
* ROT13 Brute Force operation.
*/
class ROT13BruteForce extends Operation {

/**
* ROT13BruteForce constructor
*/
constructor() {
super();

this.name = "ROT13 Brute Force";
this.module = "Default";
this.description = "Try all meaningful amounts for ROT13.<br><br>Optionally you can enter your known plaintext (crib) to filter the result.";
this.infoURL = "https://wikipedia.org/wiki/ROT13";
this.inputType = "byteArray";
this.outputType = "string";
this.args = [
{
name: "Rotate lower case chars",
type: "boolean",
value: true
},
{
name: "Rotate upper case chars",
type: "boolean",
value: true
},
{
name: "Rotate numbers",
type: "boolean",
value: false
},
{
"name": "Sample length",
"type": "number",
"value": 100
},
{
"name": "Sample offset",
"type": "number",
"value": 0
},
{
"name": "Print amount",
"type": "boolean",
"value": true
},
{
"name": "Crib (known plaintext string)",
"type": "string",
"value": ""
}
];
}

/**
* @param {byteArray} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const [rotateLower, rotateUpper, rotateNum, sampleLength, sampleOffset, printAmount, crib] = args;
const sample = input.slice(sampleOffset, sampleOffset + sampleLength);
const cribLower = crib.toLowerCase();
const lowerStart = "a".charCodeAt(0), upperStart = "A".charCodeAt(0), numStart = "0".charCodeAt(0);
const result = [];
for (let amount = 1; amount < 26; amount++) {
const rotated = sample.slice();
for (let i = 0; i < rotated.length; i++) {
if (rotateLower && lowerStart <= rotated[i] && rotated[i] < lowerStart + 26) {
rotated[i] = (rotated[i] - lowerStart + amount) % 26 + lowerStart;
} else if (rotateUpper && upperStart <= rotated[i] && rotated[i] < upperStart + 26) {
rotated[i] = (rotated[i] - upperStart + amount) % 26 + upperStart;
} else if (rotateNum && numStart <= rotated[i] && rotated[i] < numStart + 10) {
rotated[i] = (rotated[i] - numStart + amount) % 10 + numStart;
}
}
const rotatedString = Utils.byteArrayToUtf8(rotated);
if (rotatedString.toLowerCase().indexOf(cribLower) >= 0) {
const rotatedStringPrintable = Utils.printable(rotatedString, false);
if (printAmount) {
const amountStr = "Amount = " + (" " + amount).slice(-2) + ": ";
result.push(amountStr + rotatedStringPrintable);
} else {
result.push(rotatedStringPrintable);
}
}
}
return result.join("\n");
}
}

export default ROT13BruteForce;
82 changes: 82 additions & 0 deletions src/core/operations/ROT47BruteForce.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* @author MikeCAT
* @license Apache-2.0
*/

import Operation from "../Operation.mjs";
import Utils from "../Utils.mjs";

/**
* ROT47 Brute Force operation.
*/
class ROT47BruteForce extends Operation {

/**
* ROT47BruteForce constructor
*/
constructor() {
super();

this.name = "ROT47 Brute Force";
this.module = "Default";
this.description = "Try all meaningful amounts for ROT47.<br><br>Optionally you can enter your known plaintext (crib) to filter the result.";
this.infoURL = "https://wikipedia.org/wiki/ROT13#Variants";
this.inputType = "byteArray";
this.outputType = "string";
this.args = [
{
"name": "Sample length",
"type": "number",
"value": 100
},
{
"name": "Sample offset",
"type": "number",
"value": 0
},
{
"name": "Print amount",
"type": "boolean",
"value": true
},
{
"name": "Crib (known plaintext string)",
"type": "string",
"value": ""
}
];
}

/**
* @param {byteArray} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const [sampleLength, sampleOffset, printAmount, crib] = args;
const sample = input.slice(sampleOffset, sampleOffset + sampleLength);
const cribLower = crib.toLowerCase();
const result = [];
for (let amount = 1; amount < 94; amount++) {
const rotated = sample.slice();
for (let i = 0; i < rotated.length; i++) {
if (33 <= rotated[i] && rotated[i] <= 126) {
rotated[i] = (rotated[i] - 33 + amount) % 94 + 33;
}
}
const rotatedString = Utils.byteArrayToUtf8(rotated);
if (rotatedString.toLowerCase().indexOf(cribLower) >= 0) {
const rotatedStringPrintable = Utils.printable(rotatedString, false);
if (printAmount) {
const amountStr = "Amount = " + (" " + amount).slice(-2) + ": ";
result.push(amountStr + rotatedStringPrintable);
} else {
result.push(rotatedStringPrintable);
}
}
}
return result.join("\n");
}
}

export default ROT47BruteForce;