mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-26 01:36:17 -04:00
Tidied up the Manchester files
This commit is contained in:
parent
b2e0b8613c
commit
ef177a7ba0
2 changed files with 21 additions and 20 deletions
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import Operation from "../Operation.mjs";
|
import Operation from "../Operation.mjs";
|
||||||
|
import OperationError from "../errors/OperationError.mjs";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manchester decoding operation
|
* Manchester decoding operation
|
||||||
|
@ -19,10 +20,10 @@ class ManchesterDecode extends Operation {
|
||||||
|
|
||||||
this.name = "Manchester Decode";
|
this.name = "Manchester Decode";
|
||||||
this.module = "Encodings";
|
this.module = "Encodings";
|
||||||
this.description = "";
|
this.description = "Decodes data that has been encoded using the Manchester Encoding (also known as phase encoding). A <code>01</code> is converted to <code>1</code> and a <code>10</code> is converted to <code>0</code>. <br><br>As every bit is encoded into two bits when using this encoding, inputs must be a multiple of 2 long.";
|
||||||
this.infoURL = "";
|
this.infoURL = "https://en.wikipedia.org/wiki/Manchester_code";
|
||||||
this.inputType = "binaryArray";
|
this.inputType = "string";
|
||||||
this.outputType = "binaryArray";
|
this.outputType = "string";
|
||||||
this.args = [];
|
this.args = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +33,7 @@ class ManchesterDecode extends Operation {
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
const result = [];
|
const decoding = [];
|
||||||
|
|
||||||
if (input.length % 2 != 0){
|
if (input.length % 2 != 0){
|
||||||
throw new OperationError(`Length of an input should be a multiple of 2, the input is ${input.length} long.`);
|
throw new OperationError(`Length of an input should be a multiple of 2, the input is ${input.length} long.`);
|
||||||
|
@ -43,16 +44,16 @@ class ManchesterDecode extends Operation {
|
||||||
const bit2 = input[i+1];
|
const bit2 = input[i+1];
|
||||||
|
|
||||||
if (bit1 == 1 && bit2 == 0){
|
if (bit1 == 1 && bit2 == 0){
|
||||||
result.push(0);
|
decoding.push(0);
|
||||||
} else if (bit1 == 0 && bit2 == 1){
|
} else if (bit1 == 0 && bit2 == 1){
|
||||||
result.push(1);
|
decoding.push(1);
|
||||||
} else {
|
} else {
|
||||||
throw new OperationError(`Invalid input.`);
|
throw new OperationError(`Invalid input.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
const output = decoding.join("");
|
||||||
return result;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,10 +19,10 @@ class ManchesterEncode extends Operation {
|
||||||
|
|
||||||
this.name = "Manchester Encode";
|
this.name = "Manchester Encode";
|
||||||
this.module = "Encodings";
|
this.module = "Encodings";
|
||||||
this.description = "";
|
this.description = "Performs the Manchester encoding on the data (also known as phase encoding). A <code>1</code> is converted to <code>01</code> and a <code>0</code> is converted to <code>10</code>. ";
|
||||||
this.infoURL = "";
|
this.infoURL = "https://en.wikipedia.org/wiki/Manchester_code";
|
||||||
this.inputType = "binaryArray";
|
this.inputType = "string";
|
||||||
this.outputType = "binaryArray";
|
this.outputType = "string";
|
||||||
this.args = [];
|
this.args = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,22 +32,22 @@ class ManchesterEncode extends Operation {
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
const result = [];
|
const encoding = [];
|
||||||
|
|
||||||
for (let i = 0; i < input.length; i ++){
|
for (let i = 0; i < input.length; i ++){
|
||||||
const bit = input[i];
|
const bit = input[i];
|
||||||
|
|
||||||
if (bit == 0){
|
if (bit == 0){
|
||||||
result.push(1);
|
encoding.push(1);
|
||||||
result.push(0);
|
encoding.push(0);
|
||||||
} else {
|
} else {
|
||||||
result.push(0);
|
encoding.push(0);
|
||||||
result.push(1);
|
encoding.push(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
const output = encoding.join("");
|
||||||
return result;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue