2022-01-17 23:37:24 +13:00
|
|
|
/**
|
|
|
|
* @author dolphinOnKeys [robin@weird.io]
|
|
|
|
* @copyright Crown Copyright 2022
|
|
|
|
* @license Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
import Operation from "../Operation.mjs";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cetacean Cipher Decode operation
|
|
|
|
*/
|
|
|
|
class CetaceanCipherDecode extends Operation {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CetaceanCipherDecode constructor
|
|
|
|
*/
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.name = "Cetacean Cipher Decode";
|
|
|
|
this.module = "Ciphers";
|
|
|
|
this.description = "Decode Cetacean Cipher input. <br/><br/>e.g. <code>EEEEEEEEEeeEeEEEEEEEEEEEEeeEeEEe</code> becomes <code>hi</code>";
|
2022-07-08 17:16:35 +01:00
|
|
|
this.infoURL = "https://hitchhikers.fandom.com/wiki/Dolphins";
|
2022-01-17 23:37:24 +13:00
|
|
|
this.inputType = "string";
|
|
|
|
this.outputType = "string";
|
|
|
|
|
|
|
|
this.checks = [
|
|
|
|
{
|
|
|
|
pattern: "^(?:[eE]{16,})(?: [eE]{16,})*$",
|
|
|
|
flags: "",
|
|
|
|
args: []
|
|
|
|
}
|
2022-07-08 17:16:35 +01:00
|
|
|
];
|
2022-01-17 23:37:24 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} input
|
|
|
|
* @param {Object[]} args
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
run(input, args) {
|
|
|
|
const binaryArray = [];
|
2022-07-08 17:16:35 +01:00
|
|
|
for (const char of input) {
|
|
|
|
if (char === " ") {
|
|
|
|
binaryArray.push(...[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]);
|
2022-01-17 23:37:24 +13:00
|
|
|
} else {
|
2022-07-08 17:16:35 +01:00
|
|
|
binaryArray.push(char === "e" ? 1 : 0);
|
2022-01-17 23:37:24 +13:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const byteArray = [];
|
|
|
|
|
2022-07-08 17:16:35 +01:00
|
|
|
for (let i = 0; i < binaryArray.length; i += 16) {
|
|
|
|
byteArray.push(binaryArray.slice(i, i + 16).join(""));
|
2022-01-17 23:37:24 +13:00
|
|
|
}
|
|
|
|
|
2022-07-08 17:16:35 +01:00
|
|
|
return byteArray.map(byte =>
|
|
|
|
String.fromCharCode(parseInt(byte, 2))
|
|
|
|
).join("");
|
2022-01-17 23:37:24 +13:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default CetaceanCipherDecode;
|