mirror of
https://github.com/gchq/CyberChef.git
synced 2025-07-03 19:32:22 -04:00
Merge branch 'master' of github.com:gchq/CyberChef into simplify-recipe
This commit is contained in:
commit
a49d97f898
46 changed files with 9132 additions and 4884 deletions
|
@ -38,8 +38,14 @@ class Chef {
|
|||
* @returns {number} response.error - The error object thrown by a failed operation (false if no error)
|
||||
*/
|
||||
async bake(input, recipeConfig, options) {
|
||||
<<<<<<< HEAD
|
||||
const startTime = new Date().getTime(),
|
||||
recipe = await Recipe.buildRecipe(recipeConfig),
|
||||
=======
|
||||
log.debug("Chef baking");
|
||||
const startTime = Date.now(),
|
||||
recipe = new Recipe(recipeConfig),
|
||||
>>>>>>> 26b19350f2dffacfb1bce8ded689a09aa42355db
|
||||
containsFc = recipe.containsFlowControl(),
|
||||
notUTF8 = options && "treatAsUtf8" in options && !options.treatAsUtf8;
|
||||
let error = false,
|
||||
|
@ -83,7 +89,7 @@ class Chef {
|
|||
result: await this.dish.get(returnType, notUTF8),
|
||||
type: Dish.enumLookup(this.dish.type),
|
||||
progress: progress,
|
||||
duration: new Date().getTime() - startTime,
|
||||
duration: Date.now() - startTime,
|
||||
error: error
|
||||
};
|
||||
}
|
||||
|
@ -109,16 +115,16 @@ class Chef {
|
|||
async silentBake(recipeConfig) {
|
||||
log.debug("Running silent bake");
|
||||
|
||||
const startTime = new Date().getTime(),
|
||||
recipe = await Recipe.buildRecipe(recipeConfig),
|
||||
dish = new Dish();
|
||||
const startTime = new Date().now();
|
||||
const recipe = await Recipe.buildRecipe(recipeConfig);
|
||||
const dish = new Dish();
|
||||
|
||||
try {
|
||||
recipe.execute(dish);
|
||||
} catch (err) {
|
||||
// Suppress all errors
|
||||
}
|
||||
return new Date().getTime() - startTime;
|
||||
return Date.now() - startTime;
|
||||
}
|
||||
|
||||
|
||||
|
@ -145,7 +151,12 @@ class Chef {
|
|||
const func = direction === "forward" ? highlights[i].f : highlights[i].b;
|
||||
|
||||
if (typeof func == "function") {
|
||||
pos = func(pos, highlights[i].args);
|
||||
try {
|
||||
pos = func(pos, highlights[i].args);
|
||||
} catch (err) {
|
||||
// Throw away highlighting errors
|
||||
pos = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1335,7 +1335,7 @@ export function sendStatusMessage(msg) {
|
|||
self.sendStatusMessage(msg);
|
||||
else if (isWebEnvironment())
|
||||
app.alert(msg, 10000);
|
||||
else if (isNodeEnvironment())
|
||||
else if (isNodeEnvironment() && !global.TESTING)
|
||||
// eslint-disable-next-line no-console
|
||||
console.debug(msg);
|
||||
}
|
||||
|
|
|
@ -98,6 +98,8 @@
|
|||
"Rail Fence Cipher Encode",
|
||||
"Rail Fence Cipher Decode",
|
||||
"Atbash Cipher",
|
||||
"CipherSaber2 Encrypt",
|
||||
"CipherSaber2 Decrypt",
|
||||
"Substitute",
|
||||
"Derive PBKDF2 key",
|
||||
"Derive EVP key",
|
||||
|
@ -113,7 +115,8 @@
|
|||
"Bombe",
|
||||
"Multiple Bombe",
|
||||
"Typex",
|
||||
"Lorenz"
|
||||
"Lorenz",
|
||||
"Colossus"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -198,7 +201,8 @@
|
|||
"Encode text",
|
||||
"Decode text",
|
||||
"Remove Diacritics",
|
||||
"Unescape Unicode Characters"
|
||||
"Unescape Unicode Characters",
|
||||
"Convert to NATO alphabet"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -332,6 +336,7 @@
|
|||
"Fletcher-32 Checksum",
|
||||
"Fletcher-64 Checksum",
|
||||
"Adler-32 Checksum",
|
||||
"Luhn Checksum",
|
||||
"CRC-8 Checksum",
|
||||
"CRC-16 Checksum",
|
||||
"CRC-32 Checksum",
|
||||
|
@ -391,6 +396,7 @@
|
|||
"ops": [
|
||||
"Render Image",
|
||||
"Play Media",
|
||||
"Generate Image",
|
||||
"Optical Character Recognition",
|
||||
"Remove EXIF",
|
||||
"Extract EXIF",
|
||||
|
|
34
src/core/lib/CipherSaber2.mjs
Normal file
34
src/core/lib/CipherSaber2.mjs
Normal file
|
@ -0,0 +1,34 @@
|
|||
/**
|
||||
* @author n1073645 [n1073645@gmail.com]
|
||||
* @copyright Crown Copyright 2020
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
export function encode(tempIVP, key, rounds, input) {
|
||||
const ivp = new Uint8Array(key.concat(tempIVP));
|
||||
const state = new Array(256).fill(0);
|
||||
let j = 0, i = 0;
|
||||
const result = [];
|
||||
|
||||
// Mixing states based off of IV.
|
||||
for (let i = 0; i < 256; i++)
|
||||
state[i] = i;
|
||||
const ivpLength = ivp.length;
|
||||
for (let r = 0; r < rounds; r ++) {
|
||||
for (let k = 0; k < 256; k++) {
|
||||
j = (j + state[k] + ivp[k % ivpLength]) % 256;
|
||||
[state[k], state[j]] = [state[j], state[k]];
|
||||
}
|
||||
}
|
||||
j = 0;
|
||||
i = 0;
|
||||
|
||||
// XOR cipher with key.
|
||||
for (let x = 0; x < input.length; x++) {
|
||||
i = (++i) % 256;
|
||||
j = (j + state[i]) % 256;
|
||||
[state[i], state[j]] = [state[j], state[i]];
|
||||
const n = (state[i] + state[j]) % 256;
|
||||
result.push(state[n] ^ input[x]);
|
||||
}
|
||||
return result;
|
||||
}
|
417
src/core/lib/Colossus.mjs
Normal file
417
src/core/lib/Colossus.mjs
Normal file
|
@ -0,0 +1,417 @@
|
|||
/**
|
||||
* Colossus - an emulation of the world's first electronic computer
|
||||
*
|
||||
* @author VirtualColossus [martin@virtualcolossus.co.uk]
|
||||
* @copyright Crown Copyright 2019
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import {INIT_PATTERNS, ITA2_TABLE, ROTOR_SIZES} from "../lib/Lorenz.mjs";
|
||||
|
||||
/**
|
||||
* Colossus simulator class.
|
||||
*/
|
||||
export class ColossusComputer {
|
||||
/**
|
||||
* Construct a Colossus.
|
||||
*
|
||||
* @param {string} ciphertext
|
||||
* @param {string} pattern - named pattern of Chi, Mu and Psi wheels
|
||||
* @param {Object} qbusin - which data inputs are being sent to q bus - each can be null, plain or delta
|
||||
* @param {Object[]} qbusswitches - Q bus calculation switches, multiple rows
|
||||
* @param {Object} control - control switches which specify stepping modes
|
||||
* @param {Object} starts - rotor start positions
|
||||
*/
|
||||
constructor(ciphertext, pattern, qbusin, qbusswitches, control, starts, settotal, limit) {
|
||||
this.ITAlookup = ITA2_TABLE;
|
||||
this.ReverseITAlookup = {};
|
||||
for (const letter in this.ITAlookup) {
|
||||
const code = this.ITAlookup[letter];
|
||||
this.ReverseITAlookup[code] = letter;
|
||||
}
|
||||
|
||||
this.initThyratrons(pattern);
|
||||
|
||||
this.ciphertext = ciphertext;
|
||||
this.qbusin = qbusin;
|
||||
this.qbusswitches = qbusswitches;
|
||||
this.control = control;
|
||||
this.starts = starts;
|
||||
this.settotal = settotal;
|
||||
this.limitations = limit;
|
||||
|
||||
|
||||
this.allCounters = [0, 0, 0, 0, 0];
|
||||
|
||||
this.Zbits = [0, 0, 0, 0, 0]; // Z input is the cipher tape
|
||||
this.ZbitsOneBack = [0, 0, 0, 0, 0]; // for delta
|
||||
this.Qbits = [0, 0, 0, 0, 0]; // input generated for placing onto the Q-bus (the logic processor)
|
||||
|
||||
this.Xbits = [0, 0, 0, 0, 0]; // X is the Chi wheel bits
|
||||
this.Xptr = [0, 0, 0, 0, 0]; // pointers to the current X bits (Chi wheels)
|
||||
this.XbitsOneBack = [0, 0, 0, 0, 0]; // the X bits one back (for delta)
|
||||
|
||||
this.Sbits = [0, 0, 0, 0, 0]; // S is the Psi wheel bits
|
||||
this.Sptr = [0, 0, 0, 0, 0]; // pointers to the current S bits (Psi wheels)
|
||||
this.SbitsOneBack = [0, 0, 0, 0, 0]; // the S bits one back (for delta)
|
||||
|
||||
this.Mptr = [0, 0];
|
||||
|
||||
this.rotorPtrs = {};
|
||||
|
||||
this.totalmotor = 0;
|
||||
this.P5Zbit = [0, 0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Begin a run
|
||||
*
|
||||
* @returns {object}
|
||||
*/
|
||||
run() {
|
||||
const result = {
|
||||
printout: ""
|
||||
};
|
||||
|
||||
// loop until our start positions are back to the beginning
|
||||
this.rotorPtrs = {X1: this.starts.X1, X2: this.starts.X2, X3: this.starts.X3, X4: this.starts.X4, X5: this.starts.X5, M61: this.starts.M61, M37: this.starts.M37, S1: this.starts.S1, S2: this.starts.S2, S3: this.starts.S3, S4: this.starts.S4, S5: this.starts.S5};
|
||||
// this.rotorPtrs = this.starts;
|
||||
let runcount = 1;
|
||||
|
||||
const fast = this.control.fast;
|
||||
const slow = this.control.slow;
|
||||
|
||||
// Print Headers
|
||||
result.printout += fast + " " + slow + "\n";
|
||||
|
||||
do {
|
||||
this.allCounters = [0, 0, 0, 0, 0];
|
||||
this.ZbitsOneBack = [0, 0, 0, 0, 0];
|
||||
this.XbitsOneBack = [0, 0, 0, 0, 0];
|
||||
|
||||
// Run full tape loop and process counters
|
||||
this.runTape();
|
||||
|
||||
// Only print result if larger than set total
|
||||
let fastRef = "00";
|
||||
let slowRef = "00";
|
||||
if (fast !== "") fastRef = this.rotorPtrs[fast].toString().padStart(2, "0");
|
||||
if (slow !== "") slowRef = this.rotorPtrs[slow].toString().padStart(2, "0");
|
||||
let printline = "";
|
||||
for (let c=0;c<5;c++) {
|
||||
if (this.allCounters[c] > this.settotal) {
|
||||
printline += String.fromCharCode(c+97) + this.allCounters[c]+" ";
|
||||
}
|
||||
}
|
||||
if (printline !== "") {
|
||||
result.printout += fastRef + " " + slowRef + " : ";
|
||||
result.printout += printline;
|
||||
result.printout += "\n";
|
||||
}
|
||||
|
||||
// Step fast rotor if required
|
||||
if (fast !== "") {
|
||||
this.rotorPtrs[fast]++;
|
||||
if (this.rotorPtrs[fast] > ROTOR_SIZES[fast]) this.rotorPtrs[fast] = 1;
|
||||
}
|
||||
|
||||
// Step slow rotor if fast rotor has returned to initial start position
|
||||
if (slow !== "" && this.rotorPtrs[fast] === this.starts[fast]) {
|
||||
this.rotorPtrs[slow]++;
|
||||
if (this.rotorPtrs[slow] > ROTOR_SIZES[slow]) this.rotorPtrs[slow] = 1;
|
||||
}
|
||||
|
||||
runcount++;
|
||||
} while (JSON.stringify(this.rotorPtrs) !== JSON.stringify(this.starts));
|
||||
|
||||
result.counters = this.allCounters;
|
||||
result.runcount = runcount;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run tape loop
|
||||
*/
|
||||
runTape() {
|
||||
let charZin = "";
|
||||
|
||||
this.Xptr = [this.rotorPtrs.X1, this.rotorPtrs.X2, this.rotorPtrs.X3, this.rotorPtrs.X4, this.rotorPtrs.X5];
|
||||
this.Mptr = [this.rotorPtrs.M37, this.rotorPtrs.M61];
|
||||
this.Sptr = [this.rotorPtrs.S1, this.rotorPtrs.S2, this.rotorPtrs.S3, this.rotorPtrs.S4, this.rotorPtrs.S5];
|
||||
|
||||
// Run full loop of all character on the input tape (Z)
|
||||
for (let i=0; i<this.ciphertext.length; i++) {
|
||||
charZin = this.ciphertext.charAt(i);
|
||||
|
||||
// Firstly, we check what inputs are specified on the Q-bus input switches
|
||||
this.getQbusInputs(charZin);
|
||||
|
||||
/*
|
||||
* Pattern conditions on individual impulses. Matching patterns of bits on the Q bus.
|
||||
* This is the top section on Colussus K rack - the Q bus programming switches
|
||||
*/
|
||||
const tmpcnt = this.runQbusProcessingConditional();
|
||||
|
||||
/*
|
||||
* Addition of impulses.
|
||||
* This is the bottom section of Colossus K rack.
|
||||
*/
|
||||
this.runQbusProcessingAddition(tmpcnt);
|
||||
|
||||
// Store Z bit impulse 5 two back required for P5 limitation
|
||||
this.P5Zbit[1] = this.P5Zbit[0];
|
||||
this.P5Zbit[0] = this.ITAlookup[charZin].split("")[4];
|
||||
|
||||
// Step rotors
|
||||
this.stepThyratrons();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Step thyratron rings to simulate movement of Lorenz rotors
|
||||
* Chi rotors all step one per character
|
||||
* Motor M61 rotor steps one per character, M37 steps dependant on M61 setting
|
||||
* Psi rotors only step dependant on M37 setting + limitation
|
||||
*/
|
||||
stepThyratrons() {
|
||||
let X2bPtr = this.Xptr[1]-1;
|
||||
if (X2bPtr===0) X2bPtr = ROTOR_SIZES.X2;
|
||||
let S1bPtr = this.Sptr[0]-1;
|
||||
if (S1bPtr===0) S1bPtr = ROTOR_SIZES.S1;
|
||||
|
||||
// Get Chi rotor 5 two back to calculate plaintext (Z+Chi+Psi=Plain)
|
||||
let X5bPtr=this.Xptr[4]-1;
|
||||
if (X5bPtr===0) X5bPtr=ROTOR_SIZES.X5;
|
||||
X5bPtr=X5bPtr-1;
|
||||
if (X5bPtr===0) X5bPtr=ROTOR_SIZES.X5;
|
||||
// Get Psi rotor 5 two back to calculate plaintext (Z+Chi+Psi=Plain)
|
||||
let S5bPtr=this.Sptr[4]-1;
|
||||
if (S5bPtr===0) S5bPtr=ROTOR_SIZES.S5;
|
||||
S5bPtr=S5bPtr-1;
|
||||
if (S5bPtr===0) S5bPtr=ROTOR_SIZES.S5;
|
||||
|
||||
const x2sw = this.limitations.X2;
|
||||
const s1sw = this.limitations.S1;
|
||||
const p5sw = this.limitations.P5;
|
||||
|
||||
// Limitation calculations
|
||||
let lim=1;
|
||||
if (x2sw) lim = this.rings.X[2][X2bPtr-1];
|
||||
if (s1sw) lim = lim ^ this.rings.S[1][S1bPtr-1];
|
||||
|
||||
// P5
|
||||
if (p5sw) {
|
||||
let p5lim = this.P5Zbit[1];
|
||||
p5lim = p5lim ^ this.rings.X[5][X5bPtr-1];
|
||||
p5lim = p5lim ^ this.rings.S[5][S5bPtr-1];
|
||||
lim = lim ^ p5lim;
|
||||
}
|
||||
|
||||
const basicmotor = this.rings.M[2][this.Mptr[0]-1];
|
||||
this.totalmotor = basicmotor;
|
||||
|
||||
if (x2sw || s1sw) {
|
||||
if (basicmotor===0 && lim===1) {
|
||||
this.totalmotor = 0;
|
||||
} else {
|
||||
this.totalmotor = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Step Chi rotors
|
||||
for (let r=0; r<5; r++) {
|
||||
this.Xptr[r]++;
|
||||
if (this.Xptr[r] > ROTOR_SIZES["X"+(r+1)]) this.Xptr[r] = 1;
|
||||
}
|
||||
|
||||
if (this.totalmotor) {
|
||||
// Step Psi rotors
|
||||
for (let r=0; r<5; r++) {
|
||||
this.Sptr[r]++;
|
||||
if (this.Sptr[r] > ROTOR_SIZES["S"+(r+1)]) this.Sptr[r] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Move M37 rotor if M61 set
|
||||
if (this.rings.M[1][this.Mptr[1]-1]===1) this.Mptr[0]++;
|
||||
if (this.Mptr[0] > ROTOR_SIZES.M37) this.Mptr[0]=1;
|
||||
|
||||
// Always move M61 rotor
|
||||
this.Mptr[1]++;
|
||||
if (this.Mptr[1] > ROTOR_SIZES.M61) this.Mptr[1]=1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Q bus inputs
|
||||
*/
|
||||
getQbusInputs(charZin) {
|
||||
// Zbits - the bits from the current character from the cipher tape.
|
||||
this.Zbits = this.ITAlookup[charZin].split("");
|
||||
if (this.qbusin.Z === "Z") {
|
||||
// direct Z
|
||||
this.Qbits = this.Zbits;
|
||||
} else if (this.qbusin.Z === "ΔZ") {
|
||||
// delta Z, the Bitwise XOR of this character Zbits + last character Zbits
|
||||
for (let b=0;b<5;b++) {
|
||||
this.Qbits[b] = this.Zbits[b] ^ this.ZbitsOneBack[b];
|
||||
}
|
||||
}
|
||||
this.ZbitsOneBack = this.Zbits.slice(); // copy value of object, not reference
|
||||
|
||||
// Xbits - the current Chi wheel bits
|
||||
for (let b=0;b<5;b++) {
|
||||
this.Xbits[b] = this.rings.X[b+1][this.Xptr[b]-1];
|
||||
}
|
||||
if (this.qbusin.Chi !== "") {
|
||||
if (this.qbusin.Chi === "Χ") {
|
||||
// direct X added to Qbits
|
||||
for (let b=0;b<5;b++) {
|
||||
this.Qbits[b] = this.Qbits[b] ^ this.Xbits[b];
|
||||
}
|
||||
} else if (this.qbusin.Chi === "ΔΧ") {
|
||||
// delta X
|
||||
for (let b=0;b<5;b++) {
|
||||
this.Qbits[b] = this.Qbits[b] ^ this.Xbits[b];
|
||||
this.Qbits[b] = this.Qbits[b] ^ this.XbitsOneBack[b];
|
||||
}
|
||||
}
|
||||
}
|
||||
this.XbitsOneBack = this.Xbits.slice();
|
||||
|
||||
// Sbits - the current Psi wheel bits
|
||||
for (let b=0;b<5;b++) {
|
||||
this.Sbits[b] = this.rings.S[b+1][this.Sptr[b]-1];
|
||||
}
|
||||
if (this.qbusin.Psi !== "") {
|
||||
if (this.qbusin.Psi === "Ψ") {
|
||||
// direct S added to Qbits
|
||||
for (let b=0;b<5;b++) {
|
||||
this.Qbits[b] = this.Qbits[b] ^ this.Sbits[b];
|
||||
}
|
||||
} else if (this.qbusin.Psi === "ΔΨ") {
|
||||
// delta S
|
||||
for (let b=0;b<5;b++) {
|
||||
this.Qbits[b] = this.Qbits[b] ^ this.Sbits[b];
|
||||
this.Qbits[b] = this.Qbits[b] ^ this.SbitsOneBack[b];
|
||||
}
|
||||
}
|
||||
}
|
||||
this.SbitsOneBack = this.Sbits.slice();
|
||||
}
|
||||
|
||||
/**
|
||||
* Conditional impulse Q bus section
|
||||
*/
|
||||
runQbusProcessingConditional() {
|
||||
const cnt = [-1, -1, -1, -1, -1];
|
||||
const numrows = this.qbusswitches.condition.length;
|
||||
|
||||
for (let r=0;r<numrows;r++) {
|
||||
const row = this.qbusswitches.condition[r];
|
||||
if (row.Counter !== "") {
|
||||
let result = true;
|
||||
const cPnt = row.Counter-1;
|
||||
const Qswitch = this.readBusSwitches(row.Qswitches);
|
||||
// Match switches to bit pattern
|
||||
for (let s=0;s<5;s++) {
|
||||
if (Qswitch[s] >= 0 && Qswitch[s] !== parseInt(this.Qbits[s], 10)) result = false;
|
||||
}
|
||||
// Check for NOT switch
|
||||
if (row.Negate) result = !result;
|
||||
|
||||
// AND each row to get final result
|
||||
if (cnt[cPnt] === -1) {
|
||||
cnt[cPnt] = result;
|
||||
} else if (!result) {
|
||||
cnt[cPnt] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Negate the whole column, this allows A OR B by doing NOT(NOT A AND NOT B)
|
||||
for (let c=0;c<5;c++) {
|
||||
if (this.qbusswitches.condNegateAll && cnt[c] !== -1) cnt[c] = !cnt[c];
|
||||
}
|
||||
|
||||
return cnt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Addition of impulses Q bus section
|
||||
*/
|
||||
runQbusProcessingAddition(cnt) {
|
||||
const row = this.qbusswitches.addition[0];
|
||||
const Qswitch = row.Qswitches.slice();
|
||||
|
||||
// To save making the arguments of this operation any larger, limiting addition counter to first one only
|
||||
// Colossus could actually add into any of the five counters.
|
||||
if (row.C1) {
|
||||
let addition = 0;
|
||||
for (let s=0;s<5;s++) {
|
||||
// XOR addition
|
||||
if (Qswitch[s]) {
|
||||
addition = addition ^ this.Qbits[s];
|
||||
}
|
||||
}
|
||||
const equals = (row.Equals===""?-1:(row.Equals==="."?0:1));
|
||||
if (addition === equals) {
|
||||
// AND with conditional rows to get final result
|
||||
if (cnt[0] === -1) cnt[0] = true;
|
||||
} else {
|
||||
cnt[0] = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Final check, check for addition section negate
|
||||
// then, if any column set, from top to bottom of rack, add to counter.
|
||||
for (let c=0;c<5;c++) {
|
||||
if (this.qbusswitches.addNegateAll && cnt[c] !== -1) cnt[c] = !cnt[c];
|
||||
|
||||
if (this.qbusswitches.totalMotor === "" || (this.qbusswitches.totalMotor === "x" && this.totalmotor === 0) || (this.qbusswitches.totalMotor === "." && this.totalmotor === 1)) {
|
||||
if (cnt[c] === true) this.allCounters[c]++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise thyratron rings
|
||||
* These hold the pattern of 1s & 0s for each rotor on banks of thyraton GT1C valves which act as a one-bit store.
|
||||
*/
|
||||
initThyratrons(pattern) {
|
||||
this.rings = {
|
||||
X: {
|
||||
1: INIT_PATTERNS[pattern].X[1].slice().reverse(),
|
||||
2: INIT_PATTERNS[pattern].X[2].slice().reverse(),
|
||||
3: INIT_PATTERNS[pattern].X[3].slice().reverse(),
|
||||
4: INIT_PATTERNS[pattern].X[4].slice().reverse(),
|
||||
5: INIT_PATTERNS[pattern].X[5].slice().reverse()
|
||||
},
|
||||
M: {
|
||||
1: INIT_PATTERNS[pattern].M[1].slice().reverse(),
|
||||
2: INIT_PATTERNS[pattern].M[2].slice().reverse(),
|
||||
},
|
||||
S: {
|
||||
1: INIT_PATTERNS[pattern].S[1].slice().reverse(),
|
||||
2: INIT_PATTERNS[pattern].S[2].slice().reverse(),
|
||||
3: INIT_PATTERNS[pattern].S[3].slice().reverse(),
|
||||
4: INIT_PATTERNS[pattern].S[4].slice().reverse(),
|
||||
5: INIT_PATTERNS[pattern].S[5].slice().reverse()
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Read argument bus switches X & . and convert to 1 & 0
|
||||
*/
|
||||
readBusSwitches(row) {
|
||||
const output = [-1, -1, -1, -1, -1];
|
||||
for (let c=0;c<5;c++) {
|
||||
if (row[c]===".") output[c] = 0;
|
||||
if (row[c]==="x") output[c] = 1;
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
}
|
|
@ -1724,6 +1724,25 @@ export const FILE_SIGNATURES = {
|
|||
},
|
||||
extractor: null
|
||||
},
|
||||
{
|
||||
name: "Jar Archive",
|
||||
extension: "jar",
|
||||
mime: "application/java-archive",
|
||||
description: "",
|
||||
signature: {
|
||||
0: 0x50,
|
||||
1: 0x4B,
|
||||
2: 0x03,
|
||||
3: 0x04,
|
||||
4: 0x14,
|
||||
5: 0x00,
|
||||
6: 0x08,
|
||||
7: 0x00,
|
||||
8: 0x08,
|
||||
9: 0x00
|
||||
},
|
||||
extractor: extractZIP
|
||||
},
|
||||
{
|
||||
name: "lzop compressed",
|
||||
extension: "lzop,lzo",
|
||||
|
@ -1739,10 +1758,10 @@ export const FILE_SIGNATURES = {
|
|||
6: 0x0a,
|
||||
7: 0x1a
|
||||
},
|
||||
extractor: null
|
||||
extractor: extractLZOP
|
||||
},
|
||||
{
|
||||
name: "Linux deb",
|
||||
name: "Linux deb package",
|
||||
extension: "deb",
|
||||
mime: "application/vnd.debian.binary-package",
|
||||
description: "",
|
||||
|
@ -1755,7 +1774,7 @@ export const FILE_SIGNATURES = {
|
|||
5: 0x68,
|
||||
6: 0x3e
|
||||
},
|
||||
extractor: null
|
||||
extractor: extractDEB
|
||||
},
|
||||
{
|
||||
name: "Apple Disk Image",
|
||||
|
@ -2070,7 +2089,7 @@ export const FILE_SIGNATURES = {
|
|||
6: [0x4d, 0x36],
|
||||
7: [0x50, 0x34]
|
||||
},
|
||||
extractor: null
|
||||
extractor: extractDMP
|
||||
},
|
||||
{
|
||||
name: "Windows Prefetch",
|
||||
|
@ -2087,7 +2106,7 @@ export const FILE_SIGNATURES = {
|
|||
6: 0x43,
|
||||
7: 0x41
|
||||
},
|
||||
extractor: null
|
||||
extractor: extractPF
|
||||
},
|
||||
{
|
||||
name: "Windows Prefetch (Win 10)",
|
||||
|
@ -2101,7 +2120,7 @@ export const FILE_SIGNATURES = {
|
|||
3: 0x04,
|
||||
7: 0x0
|
||||
},
|
||||
extractor: null
|
||||
extractor: extractPFWin10
|
||||
},
|
||||
{
|
||||
name: "PList (XML)",
|
||||
|
@ -2374,7 +2393,7 @@ export const FILE_SIGNATURES = {
|
|||
18: 0x00,
|
||||
19: 0x46
|
||||
},
|
||||
extractor: null
|
||||
extractor: extractLNK
|
||||
},
|
||||
{
|
||||
name: "Bash",
|
||||
|
@ -3042,7 +3061,7 @@ export function extractWAV(bytes, offset) {
|
|||
stream.moveTo(4);
|
||||
|
||||
// Move to file size.
|
||||
stream.moveTo(stream.readInt(4, "le"));
|
||||
stream.moveTo(stream.readInt(4, "le") + 8);
|
||||
|
||||
return stream.carve();
|
||||
}
|
||||
|
@ -3448,6 +3467,37 @@ export function extractXZ(bytes, offset) {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* DEB extractor.
|
||||
*
|
||||
* @param {Uint8Array} bytes
|
||||
* @param {Number} offset
|
||||
*/
|
||||
export function extractDEB(bytes, offset) {
|
||||
const stream = new Stream(bytes.slice(offset));
|
||||
|
||||
// Move past !<arch>
|
||||
stream.moveForwardsBy(8);
|
||||
while (stream.hasMore()) {
|
||||
|
||||
// Move to size field.
|
||||
stream.moveForwardsBy(48);
|
||||
let fsize= "";
|
||||
|
||||
// Convert size to a usable number.
|
||||
for (const elem of stream.getBytes(10)) {
|
||||
fsize += String.fromCharCode(elem);
|
||||
}
|
||||
fsize = parseInt(fsize.trim(), 10);
|
||||
|
||||
// Move past `\n
|
||||
stream.moveForwardsBy(2);
|
||||
stream.moveForwardsBy(fsize);
|
||||
}
|
||||
return stream.carve();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* ELF extractor.
|
||||
*
|
||||
|
@ -3749,3 +3799,158 @@ export function extractEVT(bytes, offset) {
|
|||
stream.moveForwardsBy(eofSize-4);
|
||||
return stream.carve();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* DMP extractor.
|
||||
*
|
||||
* @param {Uint8Array} bytes
|
||||
* @param {Number} offset
|
||||
* @returns {Uint8Array}
|
||||
*/
|
||||
export function extractDMP(bytes, offset) {
|
||||
const stream = new Stream(bytes.slice(offset));
|
||||
|
||||
// Move to fileSize field.
|
||||
stream.moveTo(0x70);
|
||||
|
||||
// Multiply number of pages by page size. Plus 1 since the header is a page.
|
||||
stream.moveTo((stream.readInt(4, "le") + 1) * 0x1000);
|
||||
|
||||
return stream.carve();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* PF extractor.
|
||||
*
|
||||
* @param {Uint8Array} bytes
|
||||
* @param {Number} offset
|
||||
* @returns {Uint8Array}
|
||||
*/
|
||||
export function extractPF(bytes, offset) {
|
||||
const stream = new Stream(bytes.slice(offset));
|
||||
|
||||
// Move to file size.
|
||||
stream.moveTo(12);
|
||||
stream.moveTo(stream.readInt(4, "be"));
|
||||
|
||||
return stream.carve();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* PF (Win 10) extractor.
|
||||
*
|
||||
* @param {Uint8Array} bytes
|
||||
* @param {Number} offset
|
||||
* @returns {Uint8Array}
|
||||
*/
|
||||
export function extractPFWin10(bytes, offset) {
|
||||
const stream = new Stream(bytes.slice(offset));
|
||||
|
||||
// Read in file size.
|
||||
stream.moveTo(stream.readInt(4, "be"));
|
||||
|
||||
return stream.carve();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* LNK extractor.
|
||||
*
|
||||
* @param {Uint8Array} bytes
|
||||
* @param {Number} offset
|
||||
* @returns {Uint8Array}
|
||||
*/
|
||||
export function extractLNK(bytes, offset) {
|
||||
const stream = new Stream(bytes.slice(offset));
|
||||
|
||||
// Move to file size field.
|
||||
stream.moveTo(0x34);
|
||||
stream.moveTo(stream.readInt(4, "le"));
|
||||
|
||||
return stream.carve();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* LZOP extractor.
|
||||
*
|
||||
* @param {Uint8Array} bytes
|
||||
* @param {Number} offset
|
||||
* @returns {Uint8Array}
|
||||
*/
|
||||
export function extractLZOP(bytes, offset) {
|
||||
const stream = new Stream(bytes.slice(offset));
|
||||
|
||||
// Flag bits.
|
||||
const F_ADLER32_D = 0x00000001;
|
||||
const F_ADLER32_C = 0x00000002;
|
||||
const F_CRC32_D = 0x00000100;
|
||||
const F_CRC32_C = 0x00000200;
|
||||
const F_H_FILTER = 0x00000800;
|
||||
const F_H_EXTRA_FIELD = 0x00000040;
|
||||
|
||||
let numCheckSumC = 0, numCheckSumD = 0;
|
||||
|
||||
// Move over magic bytes.
|
||||
stream.moveForwardsBy(9);
|
||||
|
||||
const version = stream.readInt(2, "be");
|
||||
|
||||
// Move to flag register offset.
|
||||
stream.moveForwardsBy(6);
|
||||
const flags = stream.readInt(4, "be");
|
||||
|
||||
if (version & F_H_FILTER)
|
||||
stream.moveForwardsBy(4);
|
||||
|
||||
if (flags & F_ADLER32_C)
|
||||
numCheckSumC++;
|
||||
|
||||
if (flags & F_CRC32_C)
|
||||
numCheckSumC++;
|
||||
|
||||
if (flags & F_ADLER32_D)
|
||||
numCheckSumD++;
|
||||
|
||||
if (flags & F_CRC32_D)
|
||||
numCheckSumD++;
|
||||
|
||||
// Move over the mode, mtime_low
|
||||
stream.moveForwardsBy(8);
|
||||
|
||||
if (version >= 0x0940)
|
||||
stream.moveForwardsBy(4);
|
||||
|
||||
const fnameSize = stream.readInt(1, "be");
|
||||
|
||||
// Move forwards by size of file name and the following 4 byte checksum.
|
||||
stream.moveForwardsBy(fnameSize);
|
||||
|
||||
if (flags & F_H_EXTRA_FIELD) {
|
||||
const extraSize = stream.readInt(4, "be");
|
||||
stream.moveForwardsBy(extraSize);
|
||||
}
|
||||
|
||||
// Move past checksum.
|
||||
stream.moveForwardsBy(4);
|
||||
|
||||
while (stream.hasMore()) {
|
||||
const uncompSize = stream.readInt(4, "be");
|
||||
|
||||
// If data has no length, break.
|
||||
if (uncompSize === 0)
|
||||
break;
|
||||
|
||||
const compSize = stream.readInt(4, "be");
|
||||
|
||||
const numCheckSumSkip = (uncompSize === compSize) ? numCheckSumD : numCheckSumD + numCheckSumC;
|
||||
|
||||
// skip forwards by compressed data size and the size of the checksum(s).
|
||||
stream.moveForwardsBy(compSize + (numCheckSumSkip * 4));
|
||||
}
|
||||
return stream.carve();
|
||||
|
||||
}
|
||||
|
|
156
src/core/lib/Lorenz.mjs
Normal file
156
src/core/lib/Lorenz.mjs
Normal file
|
@ -0,0 +1,156 @@
|
|||
/**
|
||||
* Resources required by the Lorenz SZ40/42 and Colossus
|
||||
*
|
||||
* @author VirtualColossus [martin@virtualcolossus.co.uk]
|
||||
* @copyright Crown Copyright 2019
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
export const SWITCHES = [
|
||||
{name: "Up (.)", value: "."},
|
||||
{name: "Centre", value: ""},
|
||||
{name: "Down (x)", value: "x"}
|
||||
];
|
||||
|
||||
export const VALID_ITA2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ34589+-./";
|
||||
|
||||
export const ITA2_TABLE = {
|
||||
"A": "11000",
|
||||
"B": "10011",
|
||||
"C": "01110",
|
||||
"D": "10010",
|
||||
"E": "10000",
|
||||
"F": "10110",
|
||||
"G": "01011",
|
||||
"H": "00101",
|
||||
"I": "01100",
|
||||
"J": "11010",
|
||||
"K": "11110",
|
||||
"L": "01001",
|
||||
"M": "00111",
|
||||
"N": "00110",
|
||||
"O": "00011",
|
||||
"P": "01101",
|
||||
"Q": "11101",
|
||||
"R": "01010",
|
||||
"S": "10100",
|
||||
"T": "00001",
|
||||
"U": "11100",
|
||||
"V": "01111",
|
||||
"W": "11001",
|
||||
"X": "10111",
|
||||
"Y": "10101",
|
||||
"Z": "10001",
|
||||
"3": "00010",
|
||||
"4": "01000",
|
||||
"9": "00100",
|
||||
"/": "00000",
|
||||
" ": "00100",
|
||||
".": "00100",
|
||||
"8": "11111",
|
||||
"5": "11011",
|
||||
"-": "11111",
|
||||
"+": "11011"
|
||||
};
|
||||
|
||||
export const ROTOR_SIZES = {
|
||||
S1: 43,
|
||||
S2: 47,
|
||||
S3: 51,
|
||||
S4: 53,
|
||||
S5: 59,
|
||||
M37: 37,
|
||||
M61: 61,
|
||||
X1: 41,
|
||||
X2: 31,
|
||||
X3: 29,
|
||||
X4: 26,
|
||||
X5: 23
|
||||
};
|
||||
|
||||
/**
|
||||
* Initial rotor patterns
|
||||
*/
|
||||
export const INIT_PATTERNS = {
|
||||
"No Pattern": {
|
||||
"X": {
|
||||
1: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1],
|
||||
2: [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1]
|
||||
}
|
||||
}
|
||||
};
|
61
src/core/operations/CipherSaber2Decrypt.mjs
Normal file
61
src/core/operations/CipherSaber2Decrypt.mjs
Normal file
|
@ -0,0 +1,61 @@
|
|||
/**
|
||||
* @author n1073645 [n1073645@gmail.com]
|
||||
* @copyright Crown Copyright 2020
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import { encode } from "../lib/CipherSaber2.mjs";
|
||||
import Utils from "../Utils.mjs";
|
||||
|
||||
/**
|
||||
* CipherSaber2 Decrypt operation
|
||||
*/
|
||||
class CipherSaber2Decrypt extends Operation {
|
||||
|
||||
/**
|
||||
* CipherSaber2Decrypt constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "CipherSaber2 Decrypt";
|
||||
this.module = "Crypto";
|
||||
this.description = "CipherSaber is a simple symmetric encryption protocol based on the RC4 stream cipher. It gives reasonably strong protection of message confidentiality, yet it's designed to be simple enough that even novice programmers can memorize the algorithm and implement it from scratch.";
|
||||
this.infoURL = "https://wikipedia.org/wiki/CipherSaber";
|
||||
this.inputType = "ArrayBuffer";
|
||||
this.outputType = "ArrayBuffer";
|
||||
this.args = [
|
||||
{
|
||||
name: "Key",
|
||||
type: "toggleString",
|
||||
value: "",
|
||||
toggleValues: ["Hex", "UTF8", "Latin1", "Base64"]
|
||||
},
|
||||
{
|
||||
name: "Rounds",
|
||||
type: "number",
|
||||
value: 20
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ArrayBuffer} input
|
||||
* @param {Object[]} args
|
||||
* @returns {ArrayBuffer}
|
||||
*/
|
||||
run(input, args) {
|
||||
input = new Uint8Array(input);
|
||||
const result = [],
|
||||
key = Utils.convertToByteArray(args[0].string, args[0].option),
|
||||
rounds = args[1];
|
||||
|
||||
const tempIVP = input.slice(0, 10);
|
||||
input = input.slice(10);
|
||||
return new Uint8Array(result.concat(encode(tempIVP, key, rounds, input))).buffer;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default CipherSaber2Decrypt;
|
65
src/core/operations/CipherSaber2Encrypt.mjs
Normal file
65
src/core/operations/CipherSaber2Encrypt.mjs
Normal file
|
@ -0,0 +1,65 @@
|
|||
/**
|
||||
* @author n1073645 [n1073645@gmail.com]
|
||||
* @copyright Crown Copyright 2020
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import crypto from "crypto";
|
||||
import { encode } from "../lib/CipherSaber2.mjs";
|
||||
import Utils from "../Utils.mjs";
|
||||
|
||||
/**
|
||||
* CipherSaber2 Encrypt operation
|
||||
*/
|
||||
class CipherSaber2Encrypt extends Operation {
|
||||
|
||||
/**
|
||||
* CipherSaber2Encrypt constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "CipherSaber2 Encrypt";
|
||||
this.module = "Crypto";
|
||||
this.description = "CipherSaber is a simple symmetric encryption protocol based on the RC4 stream cipher. It gives reasonably strong protection of message confidentiality, yet it's designed to be simple enough that even novice programmers can memorize the algorithm and implement it from scratch.";
|
||||
this.infoURL = "https://wikipedia.org/wiki/CipherSaber";
|
||||
this.inputType = "ArrayBuffer";
|
||||
this.outputType = "ArrayBuffer";
|
||||
this.args = [
|
||||
{
|
||||
name: "Key",
|
||||
type: "toggleString",
|
||||
value: "",
|
||||
toggleValues: ["Hex", "UTF8", "Latin1", "Base64"]
|
||||
},
|
||||
{
|
||||
name: "Rounds",
|
||||
type: "number",
|
||||
value: 20
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ArrayBuffer} input
|
||||
* @param {Object[]} args
|
||||
* @returns {ArrayBuffer}
|
||||
*/
|
||||
run(input, args) {
|
||||
input = new Uint8Array(input);
|
||||
const result = [],
|
||||
key = Utils.convertToByteArray(args[0].string, args[0].option),
|
||||
rounds = args[1];
|
||||
|
||||
// Assign into initialisation vector based on cipher mode.
|
||||
const tempIVP = crypto.randomBytes(10);
|
||||
for (let m = 0; m < 10; m++)
|
||||
result.push(tempIVP[m]);
|
||||
|
||||
return new Uint8Array(result.concat(encode(tempIVP, key, rounds, input))).buffer;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default CipherSaber2Encrypt;
|
572
src/core/operations/Colossus.mjs
Normal file
572
src/core/operations/Colossus.mjs
Normal file
|
@ -0,0 +1,572 @@
|
|||
/**
|
||||
* Emulation of Colossus.
|
||||
*
|
||||
* @author VirtualColossus [martin@virtualcolossus.co.uk]
|
||||
* @copyright Crown Copyright 2019
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
import { ColossusComputer } from "../lib/Colossus.mjs";
|
||||
import { SWITCHES, VALID_ITA2 } from "../lib/Lorenz.mjs";
|
||||
|
||||
/**
|
||||
* Colossus operation
|
||||
*/
|
||||
class Colossus extends Operation {
|
||||
|
||||
/**
|
||||
* Colossus constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
this.name = "Colossus";
|
||||
this.module = "Bletchley";
|
||||
this.description = "Colossus is the name of the world's first electronic computer. Ten Colossi were designed by Tommy Flowers and built at the Post Office Research Labs at Dollis Hill in 1943 during World War 2. They assisted with the breaking of the German Lorenz cipher attachment, a machine created to encipher communications between Hitler and his generals on the front lines.<br><br>To learn more, Virtual Colossus, an online, browser based simulation of a Colossus computer is available at <a href='https://virtualcolossus.co.uk' target='_blank'>virtualcolossus.co.uk</a>.<br><br>A more detailed description of this operation can be found <a href='https://github.com/gchq/CyberChef/wiki/Colossus' target='_blank'>here</a>.";
|
||||
this.infoURL = "https://wikipedia.org/wiki/Colossus_computer";
|
||||
this.inputType = "string";
|
||||
this.outputType = "JSON";
|
||||
this.presentType = "html";
|
||||
this.args = [
|
||||
{
|
||||
name: "Input",
|
||||
type: "label"
|
||||
},
|
||||
{
|
||||
name: "Pattern",
|
||||
type: "option",
|
||||
value: ["KH Pattern", "ZMUG Pattern", "BREAM Pattern"]
|
||||
},
|
||||
{
|
||||
name: "QBusZ",
|
||||
type: "option",
|
||||
value: ["", "Z", "ΔZ"]
|
||||
},
|
||||
{
|
||||
name: "QBusΧ",
|
||||
type: "option",
|
||||
value: ["", "Χ", "ΔΧ"]
|
||||
},
|
||||
{
|
||||
name: "QBusΨ",
|
||||
type: "option",
|
||||
value: ["", "Ψ", "ΔΨ"]
|
||||
},
|
||||
{
|
||||
name: "Limitation",
|
||||
type: "option",
|
||||
value: ["None", "Χ2", "Χ2 + P5", "X2 + Ψ1", "X2 + Ψ1 + P5"]
|
||||
},
|
||||
{
|
||||
name: "K Rack Option",
|
||||
type: "argSelector",
|
||||
value: [
|
||||
{
|
||||
name: "Select Program",
|
||||
on: [7],
|
||||
off: [8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40]
|
||||
},
|
||||
{
|
||||
name: "Top Section - Conditional",
|
||||
on: [8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30],
|
||||
off: [7, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40]
|
||||
},
|
||||
{
|
||||
name: "Bottom Section - Addition",
|
||||
on: [31, 32, 33, 34, 35, 36, 37, 38, 39, 40],
|
||||
off: [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]
|
||||
},
|
||||
{
|
||||
name: "Advanced",
|
||||
on: [8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40],
|
||||
off: [7]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Program to run",
|
||||
type: "option",
|
||||
value: ["", "Letter Count", "1+2=. (1+2 Break In, Find X1,X2)", "4=5=/1=2 (Given X1,X2 find X4,X5)", "/,5,U (Count chars to find X3)"]
|
||||
},
|
||||
{
|
||||
name: "K Rack: Conditional",
|
||||
type: "label"
|
||||
},
|
||||
{
|
||||
name: "R1-Q1",
|
||||
type: "editableOptionShort",
|
||||
value: SWITCHES,
|
||||
defaultIndex: 1
|
||||
},
|
||||
{
|
||||
name: "R1-Q2",
|
||||
type: "editableOptionShort",
|
||||
value: SWITCHES,
|
||||
defaultIndex: 1
|
||||
},
|
||||
{
|
||||
name: "R1-Q3",
|
||||
type: "editableOptionShort",
|
||||
value: SWITCHES,
|
||||
defaultIndex: 1
|
||||
},
|
||||
{
|
||||
name: "R1-Q4",
|
||||
type: "editableOptionShort",
|
||||
value: SWITCHES,
|
||||
defaultIndex: 1
|
||||
},
|
||||
{
|
||||
name: "R1-Q5",
|
||||
type: "editableOptionShort",
|
||||
value: SWITCHES,
|
||||
defaultIndex: 1
|
||||
},
|
||||
{
|
||||
name: "R1-Negate",
|
||||
type: "boolean"
|
||||
},
|
||||
{
|
||||
name: "R1-Counter",
|
||||
type: "option",
|
||||
value: ["", "1", "2", "3", "4", "5"]
|
||||
},
|
||||
{
|
||||
name: "R2-Q1",
|
||||
type: "editableOptionShort",
|
||||
value: SWITCHES,
|
||||
defaultIndex: 1
|
||||
},
|
||||
{
|
||||
name: "R2-Q2",
|
||||
type: "editableOptionShort",
|
||||
value: SWITCHES,
|
||||
defaultIndex: 1
|
||||
},
|
||||
{
|
||||
name: "R2-Q3",
|
||||
type: "editableOptionShort",
|
||||
value: SWITCHES,
|
||||
defaultIndex: 1
|
||||
},
|
||||
{
|
||||
name: "R2-Q4",
|
||||
type: "editableOptionShort",
|
||||
value: SWITCHES,
|
||||
defaultIndex: 1
|
||||
},
|
||||
{
|
||||
name: "R2-Q5",
|
||||
type: "editableOptionShort",
|
||||
value: SWITCHES,
|
||||
defaultIndex: 1
|
||||
},
|
||||
{
|
||||
name: "R2-Negate",
|
||||
type: "boolean"
|
||||
},
|
||||
{
|
||||
name: "R2-Counter",
|
||||
type: "option",
|
||||
value: ["", "1", "2", "3", "4", "5"]
|
||||
},
|
||||
{
|
||||
name: "R3-Q1",
|
||||
type: "editableOptionShort",
|
||||
value: SWITCHES,
|
||||
defaultIndex: 1
|
||||
},
|
||||
{
|
||||
name: "R3-Q2",
|
||||
type: "editableOptionShort",
|
||||
value: SWITCHES,
|
||||
defaultIndex: 1
|
||||
},
|
||||
{
|
||||
name: "R3-Q3",
|
||||
type: "editableOptionShort",
|
||||
value: SWITCHES,
|
||||
defaultIndex: 1
|
||||
},
|
||||
{
|
||||
name: "R3-Q4",
|
||||
type: "editableOptionShort",
|
||||
value: SWITCHES,
|
||||
defaultIndex: 1
|
||||
},
|
||||
{
|
||||
name: "R3-Q5",
|
||||
type: "editableOptionShort",
|
||||
value: SWITCHES,
|
||||
defaultIndex: 1
|
||||
},
|
||||
{
|
||||
name: "R3-Negate",
|
||||
type: "boolean"
|
||||
},
|
||||
{
|
||||
name: "R3-Counter",
|
||||
type: "option",
|
||||
value: ["", "1", "2", "3", "4", "5"]
|
||||
},
|
||||
{
|
||||
name: "Negate All",
|
||||
type: "boolean"
|
||||
},
|
||||
{
|
||||
name: "K Rack: Addition",
|
||||
type: "label"
|
||||
},
|
||||
{
|
||||
name: "Add-Q1",
|
||||
type: "boolean"
|
||||
},
|
||||
{
|
||||
name: "Add-Q2",
|
||||
type: "boolean"
|
||||
},
|
||||
{
|
||||
name: "Add-Q3",
|
||||
type: "boolean"
|
||||
},
|
||||
{
|
||||
name: "Add-Q4",
|
||||
type: "boolean"
|
||||
},
|
||||
{
|
||||
name: "Add-Q5",
|
||||
type: "boolean"
|
||||
},
|
||||
{
|
||||
name: "Add-Equals",
|
||||
type: "editableOptionShort",
|
||||
value: SWITCHES,
|
||||
defaultIndex: 1
|
||||
},
|
||||
{
|
||||
name: "Add-Counter1",
|
||||
type: "boolean"
|
||||
},
|
||||
{
|
||||
name: "Add Negate All",
|
||||
type: "boolean"
|
||||
},
|
||||
{
|
||||
name: "Total Motor",
|
||||
type: "editableOptionShort",
|
||||
value: SWITCHES,
|
||||
defaultIndex: 1
|
||||
},
|
||||
{
|
||||
name: "Master Control Panel",
|
||||
type: "label"
|
||||
},
|
||||
{
|
||||
name: "Set Total",
|
||||
type: "number",
|
||||
value: 0
|
||||
},
|
||||
{
|
||||
name: "Fast Step",
|
||||
type: "option",
|
||||
value: ["", "X1", "X2", "X3", "X4", "X5", "M37", "M61", "S1", "S2", "S3", "S4", "S5"]
|
||||
},
|
||||
{
|
||||
name: "Slow Step",
|
||||
type: "option",
|
||||
value: ["", "X1", "X2", "X3", "X4", "X5", "M37", "M61", "S1", "S2", "S3", "S4", "S5"]
|
||||
},
|
||||
{
|
||||
name: "Start Χ1",
|
||||
type: "number",
|
||||
value: 1
|
||||
},
|
||||
{
|
||||
name: "Start Χ2",
|
||||
type: "number",
|
||||
value: 1
|
||||
},
|
||||
{
|
||||
name: "Start Χ3",
|
||||
type: "number",
|
||||
value: 1
|
||||
},
|
||||
{
|
||||
name: "Start Χ4",
|
||||
type: "number",
|
||||
value: 1
|
||||
},
|
||||
{
|
||||
name: "Start Χ5",
|
||||
type: "number",
|
||||
value: 1
|
||||
},
|
||||
{
|
||||
name: "Start M61",
|
||||
type: "number",
|
||||
value: 1
|
||||
},
|
||||
{
|
||||
name: "Start M37",
|
||||
type: "number",
|
||||
value: 1
|
||||
},
|
||||
{
|
||||
name: "Start Ψ1",
|
||||
type: "number",
|
||||
value: 1
|
||||
},
|
||||
{
|
||||
name: "Start Ψ2",
|
||||
type: "number",
|
||||
value: 1
|
||||
},
|
||||
{
|
||||
name: "Start Ψ3",
|
||||
type: "number",
|
||||
value: 1
|
||||
},
|
||||
{
|
||||
name: "Start Ψ4",
|
||||
type: "number",
|
||||
value: 1
|
||||
},
|
||||
{
|
||||
name: "Start Ψ5",
|
||||
type: "number",
|
||||
value: 1
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {Object}
|
||||
*/
|
||||
run(input, args) {
|
||||
input = input.toUpperCase();
|
||||
for (const character of input) {
|
||||
if (VALID_ITA2.indexOf(character) === -1) {
|
||||
let errltr = character;
|
||||
if (errltr === "\n") errltr = "Carriage Return";
|
||||
if (errltr === " ") errltr = "Space";
|
||||
throw new OperationError("Invalid ITA2 character : " + errltr);
|
||||
}
|
||||
}
|
||||
|
||||
const pattern = args[1];
|
||||
const qbusin = {
|
||||
"Z": args[2],
|
||||
"Chi": args[3],
|
||||
"Psi": args[4],
|
||||
};
|
||||
|
||||
const limitation = args[5];
|
||||
const lm = [false, false, false];
|
||||
if (limitation.includes("Χ2")) lm[0] = true;
|
||||
if (limitation.includes("Ψ1")) lm[1] = true;
|
||||
if (limitation.includes("P5")) lm[2] = true;
|
||||
const limit = {
|
||||
X2: lm[0], S1: lm[1], P5: lm[2]
|
||||
};
|
||||
|
||||
const KRackOpt = args[6];
|
||||
const setProgram = args[7];
|
||||
|
||||
if (KRackOpt === "Select Program" && setProgram !== "") {
|
||||
args = this.selectProgram(setProgram, args);
|
||||
}
|
||||
|
||||
const re = new RegExp("^$|^[.x]$");
|
||||
for (let qr=0;qr<3;qr++) {
|
||||
for (let a=0;a<5;a++) {
|
||||
if (!re.test(args[((qr*7)+(a+9))]))
|
||||
throw new OperationError("Switch R"+(qr+1)+"-Q"+(a+1)+" can only be set to blank, . or x");
|
||||
}
|
||||
}
|
||||
|
||||
if (!re.test(args[37])) throw new OperationError("Switch Add-Equals can only be set to blank, . or x");
|
||||
if (!re.test(args[40])) throw new OperationError("Switch Total Motor can only be set to blank, . or x");
|
||||
|
||||
// Q1,Q2,Q3,Q4,Q5,negate,counter1
|
||||
const qbusswitches = {
|
||||
condition: [
|
||||
{Qswitches: [args[9], args[10], args[11], args[12], args[13]], Negate: args[14], Counter: args[15]},
|
||||
{Qswitches: [args[16], args[17], args[18], args[19], args[20]], Negate: args[21], Counter: args[22]},
|
||||
{Qswitches: [args[23], args[24], args[25], args[26], args[27]], Negate: args[28], Counter: args[29]}
|
||||
],
|
||||
condNegateAll: args[30],
|
||||
addition: [
|
||||
{Qswitches: [args[32], args[33], args[34], args[35], args[36]], Equals: args[37], C1: args[38]}
|
||||
],
|
||||
addNegateAll: args[39],
|
||||
totalMotor: args[40]
|
||||
};
|
||||
|
||||
const settotal = parseInt(args[42], 10);
|
||||
if (settotal < 0 || settotal > 9999)
|
||||
throw new OperationError("Set Total must be between 0000 and 9999");
|
||||
|
||||
// null|fast|slow for each of S1-5,M1-2,X1-5
|
||||
const control = {
|
||||
fast: args[43],
|
||||
slow: args[44]
|
||||
};
|
||||
|
||||
// Start positions
|
||||
if (args[52]<1 || args[52]>43) throw new OperationError("Ψ1 start must be between 1 and 43");
|
||||
if (args[53]<1 || args[53]>47) throw new OperationError("Ψ2 start must be between 1 and 47");
|
||||
if (args[54]<1 || args[54]>51) throw new OperationError("Ψ3 start must be between 1 and 51");
|
||||
if (args[55]<1 || args[55]>53) throw new OperationError("Ψ4 start must be between 1 and 53");
|
||||
if (args[56]<1 || args[57]>59) throw new OperationError("Ψ5 start must be between 1 and 59");
|
||||
if (args[51]<1 || args[51]>37) throw new OperationError("Μ37 start must be between 1 and 37");
|
||||
if (args[50]<1 || args[50]>61) throw new OperationError("Μ61 start must be between 1 and 61");
|
||||
if (args[45]<1 || args[45]>41) throw new OperationError("Χ1 start must be between 1 and 41");
|
||||
if (args[46]<1 || args[46]>31) throw new OperationError("Χ2 start must be between 1 and 31");
|
||||
if (args[47]<1 || args[47]>29) throw new OperationError("Χ3 start must be between 1 and 29");
|
||||
if (args[48]<1 || args[48]>26) throw new OperationError("Χ4 start must be between 1 and 26");
|
||||
if (args[49]<1 || args[49]>23) throw new OperationError("Χ5 start must be between 1 and 23");
|
||||
|
||||
const starts = {
|
||||
X1: args[45], X2: args[46], X3: args[47], X4: args[48], X5: args[49],
|
||||
M61: args[50], M37: args[51],
|
||||
S1: args[52], S2: args[53], S3: args[54], S4: args[55], S5: args[56]
|
||||
};
|
||||
|
||||
const colossus = new ColossusComputer(input, pattern, qbusin, qbusswitches, control, starts, settotal, limit);
|
||||
const result = colossus.run();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Select Program
|
||||
*
|
||||
* @param {string} progname
|
||||
* @param {Object[]} args
|
||||
* @returns {Object[]}
|
||||
*/
|
||||
selectProgram(progname, args) {
|
||||
|
||||
// Basic Letter Count
|
||||
if (progname === "Letter Count") {
|
||||
// Set Conditional R1 : count every character into counter 1
|
||||
args[9] = "";
|
||||
args[10] = "";
|
||||
args[11] = "";
|
||||
args[12] = "";
|
||||
args[13] = "";
|
||||
args[14] = false;
|
||||
args[15] = "1";
|
||||
// clear Conditional R2 & R3
|
||||
args[22] = "";
|
||||
args[29] = "";
|
||||
// Clear Negate result
|
||||
args[30] = false;
|
||||
// Clear Addition row counter
|
||||
args[38] = false;
|
||||
}
|
||||
|
||||
// Bill Tutte's 1+2 Break In
|
||||
if (progname === "1+2=. (1+2 Break In, Find X1,X2)") {
|
||||
// Clear any other counters
|
||||
args[15] = ""; // Conditional R1
|
||||
args[22] = ""; // Conditional R2
|
||||
args[29] = ""; // Conditional R3
|
||||
// Set Add Q1+Q2=. into Counter 1
|
||||
args[32] = true;
|
||||
args[33] = true;
|
||||
args[34] = false;
|
||||
args[35] = false;
|
||||
args[36] = false;
|
||||
args[37] = ".";
|
||||
args[38] = true;
|
||||
}
|
||||
|
||||
// 4=3=/1=2 : Find X4 & X5 where X1 & X2 are known
|
||||
if (progname === "4=5=/1=2 (Given X1,X2 find X4,X5)") {
|
||||
// Set Conditional R1 : Match NOT ..?.. into counter 1
|
||||
args[9] = ".";
|
||||
args[10] = ".";
|
||||
args[11] = "";
|
||||
args[12] = ".";
|
||||
args[13] = ".";
|
||||
args[14] = true;
|
||||
args[15] = "1";
|
||||
// Set Conditional R2 : AND Match NOT xx?xx into counter 1
|
||||
args[16] = "x";
|
||||
args[17] = "x";
|
||||
args[18] = "";
|
||||
args[19] = "x";
|
||||
args[20] = "x";
|
||||
args[21] = true;
|
||||
args[22] = "1";
|
||||
// clear Conditional R3
|
||||
args[29] = "";
|
||||
// Negate result, giving NOT(NOT Q1 AND NOT Q2) which is equivalent to Q1 OR Q2
|
||||
args[30] = true;
|
||||
// Clear Addition row counter
|
||||
args[38] = false;
|
||||
}
|
||||
|
||||
// /,5,U : Count number of matches of /, 5 & U to find X3
|
||||
if (progname === "/,5,U (Count chars to find X3)") {
|
||||
// Set Conditional R1 : Match / char, ITA2 = ..... into counter 1
|
||||
args[9] = ".";
|
||||
args[10] = ".";
|
||||
args[11] = ".";
|
||||
args[12] = ".";
|
||||
args[13] = ".";
|
||||
args[14] = false;
|
||||
args[15] = "1";
|
||||
// Set Conditional R2 : Match 5 char, ITA2 = xx.xx into counter 2
|
||||
args[16] = "x";
|
||||
args[17] = "x";
|
||||
args[18] = ".";
|
||||
args[19] = "x";
|
||||
args[20] = "x";
|
||||
args[21] = false;
|
||||
args[22] = "2";
|
||||
// Set Conditional R3 : Match U char, ITA2 = xxx.. into counter 3
|
||||
args[23] = "x";
|
||||
args[24] = "x";
|
||||
args[25] = "x";
|
||||
args[26] = ".";
|
||||
args[27] = ".";
|
||||
args[28] = false;
|
||||
args[29] = "3";
|
||||
// Clear Negate result
|
||||
args[30] = false;
|
||||
// Clear Addition row counter
|
||||
args[38] = false;
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays Colossus results in an HTML table
|
||||
*
|
||||
* @param {Object} output
|
||||
* @param {Object[]} output.counters
|
||||
* @returns {html}
|
||||
*/
|
||||
present(output) {
|
||||
let html = "Colossus Printer\n\n";
|
||||
html += output.printout + "\n\n";
|
||||
html += "Colossus Counters\n\n";
|
||||
html += "<table class='table table-hover table-sm table-bordered table-nonfluid'><tr><th>C1</th> <th>C2</th> <th>C3</th> <th>C4</th> <th>C5</th></tr>\n";
|
||||
html += "<tr>";
|
||||
for (const ct of output.counters) {
|
||||
html += `<td>${ct}</td>\n`;
|
||||
}
|
||||
html += "</tr>";
|
||||
html += "</table>";
|
||||
return html;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default Colossus;
|
82
src/core/operations/ConvertToNATOAlphabet.mjs
Normal file
82
src/core/operations/ConvertToNATOAlphabet.mjs
Normal file
|
@ -0,0 +1,82 @@
|
|||
/**
|
||||
* @author MarvinJWendt [git@marvinjwendt.com]
|
||||
* @copyright Crown Copyright 2019
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
|
||||
/**
|
||||
* Convert to NATO alphabet operation
|
||||
*/
|
||||
class ConvertToNATOAlphabet extends Operation {
|
||||
/**
|
||||
* ConvertToNATOAlphabet constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Convert to NATO alphabet";
|
||||
this.module = "Default";
|
||||
this.description = "Converts characters to their representation in the NATO phonetic alphabet.";
|
||||
this.infoURL = "https://wikipedia.org/wiki/NATO_phonetic_alphabet";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
return input.replace(/[a-z0-9,/.]/ig, letter => {
|
||||
return lookup[letter.toUpperCase()];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const lookup = {
|
||||
"A": "Alfa ",
|
||||
"B": "Bravo ",
|
||||
"C": "Charlie ",
|
||||
"D": "Delta ",
|
||||
"E": "Echo ",
|
||||
"F": "Foxtrot ",
|
||||
"G": "Golf ",
|
||||
"H": "Hotel ",
|
||||
"I": "India ",
|
||||
"J": "Juliett ",
|
||||
"K": "Kilo ",
|
||||
"L": "Lima ",
|
||||
"M": "Mike ",
|
||||
"N": "November ",
|
||||
"O": "Oscar ",
|
||||
"P": "Papa ",
|
||||
"Q": "Quebec ",
|
||||
"R": "Romeo ",
|
||||
"S": "Sierra ",
|
||||
"T": "Tango ",
|
||||
"U": "Uniform ",
|
||||
"V": "Victor ",
|
||||
"W": "Whiskey ",
|
||||
"X": "X-ray ",
|
||||
"Y": "Yankee ",
|
||||
"Z": "Zulu ",
|
||||
"0": "Zero ",
|
||||
"1": "One ",
|
||||
"2": "Two ",
|
||||
"3": "Three ",
|
||||
"4": "Four ",
|
||||
"5": "Five ",
|
||||
"6": "Six ",
|
||||
"7": "Seven ",
|
||||
"8": "Eight ",
|
||||
"9": "Nine ",
|
||||
",": "Comma ",
|
||||
"/": "Fraction bar ",
|
||||
".": "Full stop ",
|
||||
};
|
||||
|
||||
export default ConvertToNATOAlphabet;
|
184
src/core/operations/GenerateImage.mjs
Normal file
184
src/core/operations/GenerateImage.mjs
Normal file
|
@ -0,0 +1,184 @@
|
|||
/**
|
||||
* @author pointhi [thomas.pointhuber@gmx.at]
|
||||
* @copyright Crown Copyright 2019
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
import Utils from "../Utils.mjs";
|
||||
import {isImage} from "../lib/FileType";
|
||||
import {toBase64} from "../lib/Base64";
|
||||
import jimp from "jimp";
|
||||
import {isWorkerEnvironment} from "../Utils";
|
||||
|
||||
/**
|
||||
* Generate Image operation
|
||||
*/
|
||||
class GenerateImage extends Operation {
|
||||
|
||||
/**
|
||||
* GenerateImage constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Generate Image";
|
||||
this.module = "Image";
|
||||
this.description = "Generates an image using the input as pixel values.";
|
||||
this.infoURL = "";
|
||||
this.inputType = "ArrayBuffer";
|
||||
this.outputType = "ArrayBuffer";
|
||||
this.presentType = "html";
|
||||
this.args = [
|
||||
{
|
||||
"name": "Mode",
|
||||
"type": "option",
|
||||
"value": ["Greyscale", "RG", "RGB", "RGBA", "Bits"]
|
||||
},
|
||||
{
|
||||
"name": "Pixel Scale Factor",
|
||||
"type": "number",
|
||||
"value": 8,
|
||||
},
|
||||
{
|
||||
"name": "Pixels per row",
|
||||
"type": "number",
|
||||
"value": 64,
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {byteArray} input
|
||||
* @param {Object[]} args
|
||||
* @returns {ArrayBuffer}
|
||||
*/
|
||||
async run(input, args) {
|
||||
const [mode, scale, width] = args;
|
||||
input = new Uint8Array(input);
|
||||
|
||||
if (scale <= 0) {
|
||||
throw new OperationError("Pixel Scale Factor needs to be > 0");
|
||||
}
|
||||
|
||||
if (width <= 0) {
|
||||
throw new OperationError("Pixels per Row needs to be > 0");
|
||||
}
|
||||
|
||||
const bytePerPixelMap = {
|
||||
"Greyscale": 1,
|
||||
"RG": 2,
|
||||
"RGB": 3,
|
||||
"RGBA": 4,
|
||||
"Bits": 1/8,
|
||||
};
|
||||
|
||||
const bytesPerPixel = bytePerPixelMap[mode];
|
||||
|
||||
if (bytesPerPixel > 0 && input.length % bytesPerPixel !== 0) {
|
||||
throw new OperationError(`Number of bytes is not a divisor of ${bytesPerPixel}`);
|
||||
}
|
||||
|
||||
const height = Math.ceil(input.length / bytesPerPixel / width);
|
||||
const image = await new jimp(width, height, (err, image) => {});
|
||||
|
||||
if (isWorkerEnvironment())
|
||||
self.sendStatusMessage("Generating image from data...");
|
||||
|
||||
if (mode === "Bits") {
|
||||
let index = 0;
|
||||
for (let j = 0; j < input.length; j++) {
|
||||
const curByte = Utils.bin(input[j]);
|
||||
for (let k = 0; k < 8; k++, index++) {
|
||||
const x = index % width;
|
||||
const y = Math.floor(index / width);
|
||||
|
||||
const value = curByte[k] === "0" ? 0xFF : 0x00;
|
||||
const pixel = jimp.rgbaToInt(value, value, value, 0xFF);
|
||||
image.setPixelColor(pixel, x, y);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let i = 0;
|
||||
while (i < input.length) {
|
||||
const index = i / bytesPerPixel;
|
||||
const x = index % width;
|
||||
const y = Math.floor(index / width);
|
||||
|
||||
let red = 0x00;
|
||||
let green = 0x00;
|
||||
let blue = 0x00;
|
||||
let alpha = 0xFF;
|
||||
|
||||
switch (mode) {
|
||||
case "Greyscale":
|
||||
red = green = blue = input[i++];
|
||||
break;
|
||||
|
||||
case "RG":
|
||||
red = input[i++];
|
||||
green = input[i++];
|
||||
break;
|
||||
|
||||
case "RGB":
|
||||
red = input[i++];
|
||||
green = input[i++];
|
||||
blue = input[i++];
|
||||
break;
|
||||
|
||||
case "RGBA":
|
||||
red = input[i++];
|
||||
green = input[i++];
|
||||
blue = input[i++];
|
||||
alpha = input[i++];
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new OperationError(`Unsupported Mode: (${mode})`);
|
||||
}
|
||||
|
||||
try {
|
||||
const pixel = jimp.rgbaToInt(red, green, blue, alpha);
|
||||
image.setPixelColor(pixel, x, y);
|
||||
} catch (err) {
|
||||
throw new OperationError(`Error while generating image from pixel values. (${err})`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (scale !== 1) {
|
||||
if (isWorkerEnvironment())
|
||||
self.sendStatusMessage("Scaling image...");
|
||||
|
||||
image.scaleToFit(width*scale, height*scale, jimp.RESIZE_NEAREST_NEIGHBOR);
|
||||
}
|
||||
|
||||
try {
|
||||
const imageBuffer = await image.getBufferAsync(jimp.MIME_PNG);
|
||||
return imageBuffer.buffer;
|
||||
} catch (err) {
|
||||
throw new OperationError(`Error generating image. (${err})`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the generated image using HTML for web apps
|
||||
* @param {ArrayBuffer} data
|
||||
* @returns {html}
|
||||
*/
|
||||
present(data) {
|
||||
if (!data.byteLength) return "";
|
||||
const dataArray = new Uint8Array(data);
|
||||
|
||||
const type = isImage(dataArray);
|
||||
if (!type) {
|
||||
throw new OperationError("Invalid file type.");
|
||||
}
|
||||
|
||||
return `<img src="data:${type};base64,${toBase64(dataArray)}">`;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default GenerateImage;
|
|
@ -22,7 +22,7 @@ class Lorenz extends Operation {
|
|||
|
||||
this.name = "Lorenz";
|
||||
this.module = "Bletchley";
|
||||
this.description = "The Lorenz SZ40/42 cipher attachment was a WW2 German rotor cipher machine with twelve rotors which attached in-line between remote teleprinters.<br><br>It used the Vernam cipher with two groups of five rotors (named the psi(ψ) wheels and chi(χ) wheels at Bletchley Park) to create two pseudorandom streams of five bits, encoded in ITA2, which were XOR added to the plaintext. Two other rotors, dubbed the mu(μ) or motor wheels, could hold up the stepping of the psi wheels meaning they stepped intermittently.<br><br>Each rotor has a different number of cams/lugs around their circumference which could be set active or inactive changing the key stream.<br><br>Three models of the Lorenz are emulated, SZ40, SZ42a and SZ42b and three example wheel patterns (the lug settings) are included (KH, ZMUG & BREAM) with the option to set a custom set using the letter 'x' for active or '.' for an inactive lug.<br><br>The input can either be plaintext or ITA2 when sending and ITA2 when receiving.<br><br>To learn more, Virtual Lorenz, an online, browser based simulation of the Lorenz SZ40/42 is available at <a href='https://lorenz.virtualcolossus.co.uk' target='_blank'>https://lorenz.virtualcolossus.co.uk</a>.<br><br>A more detailed description of this operation can be found <a href='https://github.com/gchq/CyberChef/wiki/Lorenz-SZ' target='_blank'>here</a>.";
|
||||
this.description = "The Lorenz SZ40/42 cipher attachment was a WW2 German rotor cipher machine with twelve rotors which attached in-line between remote teleprinters.<br><br>It used the Vernam cipher with two groups of five rotors (named the psi(ψ) wheels and chi(χ) wheels at Bletchley Park) to create two pseudorandom streams of five bits, encoded in ITA2, which were XOR added to the plaintext. Two other rotors, dubbed the mu(μ) or motor wheels, could hold up the stepping of the psi wheels meaning they stepped intermittently.<br><br>Each rotor has a different number of cams/lugs around their circumference which could be set active or inactive changing the key stream.<br><br>Three models of the Lorenz are emulated, SZ40, SZ42a and SZ42b and three example wheel patterns (the lug settings) are included (KH, ZMUG & BREAM) with the option to set a custom set using the letter 'x' for active or '.' for an inactive lug.<br><br>The input can either be plaintext or ITA2 when sending and ITA2 when receiving.<br><br>To learn more, Virtual Lorenz, an online, browser based simulation of the Lorenz SZ40/42 is available at <a href='https://lorenz.virtualcolossus.co.uk' target='_blank'>lorenz.virtualcolossus.co.uk</a>.<br><br>A more detailed description of this operation can be found <a href='https://github.com/gchq/CyberChef/wiki/Lorenz-SZ' target='_blank'>here</a>.";
|
||||
this.infoURL = "https://wikipedia.org/wiki/Lorenz_cipher";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
|
@ -293,8 +293,8 @@ class Lorenz extends Operation {
|
|||
chosenSetting.S[3] = this.readLugs(lugs3);
|
||||
chosenSetting.S[4] = this.readLugs(lugs4);
|
||||
chosenSetting.S[5] = this.readLugs(lugs5);
|
||||
chosenSetting.M[1] = this.readLugs(lugm37);
|
||||
chosenSetting.M[2] = this.readLugs(lugm61);
|
||||
chosenSetting.M[1] = this.readLugs(lugm61);
|
||||
chosenSetting.M[2] = this.readLugs(lugm37);
|
||||
chosenSetting.X[1] = this.readLugs(lugx1);
|
||||
chosenSetting.X[2] = this.readLugs(lugx2);
|
||||
chosenSetting.X[3] = this.readLugs(lugx3);
|
||||
|
|
77
src/core/operations/LuhnChecksum.mjs
Normal file
77
src/core/operations/LuhnChecksum.mjs
Normal file
|
@ -0,0 +1,77 @@
|
|||
/**
|
||||
* @author n1073645 [n1073645@gmail.com]
|
||||
* @copyright Crown Copyright 2020
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
|
||||
/**
|
||||
* Luhn Checksum operation
|
||||
*/
|
||||
class LuhnChecksum extends Operation {
|
||||
|
||||
/**
|
||||
* LuhnChecksum constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Luhn Checksum";
|
||||
this.module = "Default";
|
||||
this.description = "The Luhn algorithm, also known as the modulus 10 or mod 10 algorithm, is a simple checksum formula used to validate a variety of identification numbers, such as credit card numbers, IMEI numbers and Canadian Social Insurance Numbers.";
|
||||
this.infoURL = "https://wikipedia.org/wiki/Luhn_algorithm";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the Luhn Checksum from the input.
|
||||
*
|
||||
* @param {string} inputStr
|
||||
* @returns {number}
|
||||
*/
|
||||
checksum(inputStr) {
|
||||
let even = false;
|
||||
return inputStr.split("").reverse().reduce((acc, elem) => {
|
||||
// Convert element to integer.
|
||||
let temp = parseInt(elem, 10);
|
||||
|
||||
// If element is not an integer.
|
||||
if (isNaN(temp))
|
||||
throw new OperationError("Character: " + elem + " is not a digit.");
|
||||
|
||||
// If element is in an even position
|
||||
if (even) {
|
||||
// Double the element and add the quotient and remainder together.
|
||||
temp = 2 * elem;
|
||||
temp = Math.floor(temp/10) + (temp % 10);
|
||||
}
|
||||
|
||||
even = !even;
|
||||
return acc + temp;
|
||||
}, 0) % 10;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
if (!input) return "";
|
||||
|
||||
const checkSum = this.checksum(input);
|
||||
let checkDigit = this.checksum(input + "0");
|
||||
checkDigit = checkDigit === 0 ? 0 : (10-checkDigit);
|
||||
|
||||
return `Checksum: ${checkSum}
|
||||
Checkdigit: ${checkDigit}
|
||||
Luhn Validated String: ${input + "" + checkDigit}`;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default LuhnChecksum;
|
|
@ -144,7 +144,7 @@ class MultipleBombe extends Operation {
|
|||
* @param {number} progress - Progress (as a float in the range 0..1)
|
||||
*/
|
||||
updateStatus(nLoops, nStops, progress, start) {
|
||||
const elapsed = new Date().getTime() - start;
|
||||
const elapsed = Date.now() - start;
|
||||
const remaining = (elapsed / progress) * (1 - progress) / 1000;
|
||||
const hours = Math.floor(remaining / 3600);
|
||||
const minutes = `0${Math.floor((remaining % 3600) / 60)}`.slice(-2);
|
||||
|
@ -237,7 +237,7 @@ class MultipleBombe extends Operation {
|
|||
const totalRuns = choose(rotors.length, 3) * 6 * fourthRotors.length * reflectors.length;
|
||||
let nRuns = 0;
|
||||
let nStops = 0;
|
||||
const start = new Date().getTime();
|
||||
const start = Date.now();
|
||||
for (const rotor1 of rotors) {
|
||||
for (const rotor2 of rotors) {
|
||||
if (rotor2 === rotor1) {
|
||||
|
|
|
@ -45,7 +45,7 @@ class RegularExpression extends Operation {
|
|||
},
|
||||
{
|
||||
name: "Email address",
|
||||
value: "\\b(\\w[-.\\w]*)@([-\\w]+(?:\\.[-\\w]+)*)\\.([A-Za-z]{2,4})\\b"
|
||||
value: "(?:[\u00A0-\uD7FF\uE000-\uFFFF-a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[\u00A0-\uD7FF\uE000-\uFFFF-a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*\")@(?:(?:[\u00A0-\uD7FF\uE000-\uFFFF-a-z0-9](?:[\u00A0-\uD7FF\uE000-\uFFFF-a-z0-9-]*[\u00A0-\uD7FF\uE000-\uFFFF-a-z0-9])?\\.)+[\u00A0-\uD7FF\uE000-\uFFFF-a-z0-9](?:[\u00A0-\uD7FF\uE000-\uFFFF-a-z0-9-]*[\u00A0-\uD7FF\uE000-\uFFFF-a-z0-9])?|\\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\\])"
|
||||
},
|
||||
{
|
||||
name: "URL",
|
||||
|
|
4
src/core/vendor/gost/gostRandom.mjs
vendored
4
src/core/vendor/gost/gostRandom.mjs
vendored
|
@ -70,7 +70,7 @@ if (typeof document !== 'undefined') {
|
|||
try {
|
||||
// Mouse move event to fill random array
|
||||
document.addEventListener('mousemove', function (e) {
|
||||
randomRing.set((new Date().getTime() & 255) ^
|
||||
randomRing.set((Date.now() & 255) ^
|
||||
((e.clientX || e.pageX) & 255) ^
|
||||
((e.clientY || e.pageY) & 255));
|
||||
}, false);
|
||||
|
@ -80,7 +80,7 @@ if (typeof document !== 'undefined') {
|
|||
try {
|
||||
// Keypress event to fill random array
|
||||
document.addEventListener('keydown', function (e) {
|
||||
randomRing.set((new Date().getTime() & 255) ^
|
||||
randomRing.set((Date.now() & 255) ^
|
||||
(e.keyCode & 255));
|
||||
}, false);
|
||||
} catch (e) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue