Tidied Cetacean ciphers

This commit is contained in:
n1474335 2022-07-08 17:16:35 +01:00
parent 6b16f11d3b
commit 4200ed4eb9
4 changed files with 34 additions and 29 deletions

11
package-lock.json generated
View File

@ -56,6 +56,7 @@
"lodash": "^4.17.21", "lodash": "^4.17.21",
"loglevel": "^1.8.0", "loglevel": "^1.8.0",
"loglevel-message-prefix": "^3.0.0", "loglevel-message-prefix": "^3.0.0",
"lz-string": "^1.4.4",
"markdown-it": "^13.0.1", "markdown-it": "^13.0.1",
"moment": "^2.29.3", "moment": "^2.29.3",
"moment-timezone": "^0.5.34", "moment-timezone": "^0.5.34",
@ -10120,6 +10121,14 @@
"node": ">=10" "node": ">=10"
} }
}, },
"node_modules/lz-string": {
"version": "1.4.4",
"resolved": "https://registry.npmjs.org/lz-string/-/lz-string-1.4.4.tgz",
"integrity": "sha512-0ckx7ZHRPqb0oUm8zNr+90mtf9DQB60H1wMCjBtfi62Kl3a7JbHob6gA2bC+xRvZoOL+1hzUK8jeuEIQE8svEQ==",
"bin": {
"lz-string": "bin/bin.js"
}
},
"node_modules/make-dir": { "node_modules/make-dir": {
"version": "3.1.0", "version": "3.1.0",
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz",
@ -23564,7 +23573,7 @@
"lz-string": { "lz-string": {
"version": "1.4.4", "version": "1.4.4",
"resolved": "https://registry.npmjs.org/lz-string/-/lz-string-1.4.4.tgz", "resolved": "https://registry.npmjs.org/lz-string/-/lz-string-1.4.4.tgz",
"integrity": "sha1-wNjq82BZ9wV5bh40SBHPTEmNOiY=" "integrity": "sha512-0ckx7ZHRPqb0oUm8zNr+90mtf9DQB60H1wMCjBtfi62Kl3a7JbHob6gA2bC+xRvZoOL+1hzUK8jeuEIQE8svEQ=="
}, },
"make-dir": { "make-dir": {
"version": "3.1.0", "version": "3.1.0",

View File

@ -77,8 +77,6 @@
"Blowfish Decrypt", "Blowfish Decrypt",
"DES Encrypt", "DES Encrypt",
"DES Decrypt", "DES Decrypt",
"Cetacean Cipher Encode",
"Cetacean Cipher Decode",
"Triple DES Encrypt", "Triple DES Encrypt",
"Triple DES Decrypt", "Triple DES Decrypt",
"LS47 Encrypt", "LS47 Encrypt",
@ -114,6 +112,8 @@
"Atbash Cipher", "Atbash Cipher",
"CipherSaber2 Encrypt", "CipherSaber2 Encrypt",
"CipherSaber2 Decrypt", "CipherSaber2 Decrypt",
"Cetacean Cipher Encode",
"Cetacean Cipher Decode",
"Substitute", "Substitute",
"Derive PBKDF2 key", "Derive PBKDF2 key",
"Derive EVP key", "Derive EVP key",

View File

@ -20,7 +20,7 @@ class CetaceanCipherDecode extends Operation {
this.name = "Cetacean Cipher Decode"; this.name = "Cetacean Cipher Decode";
this.module = "Ciphers"; this.module = "Ciphers";
this.description = "Decode Cetacean Cipher input. <br/><br/>e.g. <code>EEEEEEEEEeeEeEEEEEEEEEEEEeeEeEEe</code> becomes <code>hi</code>"; this.description = "Decode Cetacean Cipher input. <br/><br/>e.g. <code>EEEEEEEEEeeEeEEEEEEEEEEEEeeEeEEe</code> becomes <code>hi</code>";
this.infoURL = ""; this.infoURL = "https://hitchhikers.fandom.com/wiki/Dolphins";
this.inputType = "string"; this.inputType = "string";
this.outputType = "string"; this.outputType = "string";
@ -30,7 +30,7 @@ class CetaceanCipherDecode extends Operation {
flags: "", flags: "",
args: [] args: []
} }
] ];
} }
/** /**
@ -40,24 +40,23 @@ class CetaceanCipherDecode extends Operation {
*/ */
run(input, args) { run(input, args) {
const binaryArray = []; const binaryArray = [];
for ( const char of input ) { for (const char of input) {
if ( char === ' ' ) { if (char === " ") {
binaryArray.push(...[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 ]); binaryArray.push(...[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]);
} else { } else {
binaryArray.push( char === 'e' ? 1 : 0 ); binaryArray.push(char === "e" ? 1 : 0);
} }
} }
const byteArray = []; const byteArray = [];
for ( let i = 0; i < binaryArray.length; i += 16 ) { for (let i = 0; i < binaryArray.length; i += 16) {
byteArray.push(binaryArray.slice(i, i + 16).join('')) byteArray.push(binaryArray.slice(i, i + 16).join(""));
} }
return byteArray.map( byte => return byteArray.map(byte =>
String.fromCharCode(parseInt( byte , 2 ) String.fromCharCode(parseInt(byte, 2))
) ).join("");
).join('');
} }
} }

View File

@ -5,6 +5,7 @@
*/ */
import Operation from "../Operation.mjs"; import Operation from "../Operation.mjs";
import {toBinary} from "../lib/Binary.mjs";
/** /**
* Cetacean Cipher Encode operation * Cetacean Cipher Encode operation
@ -19,8 +20,8 @@ class CetaceanCipherEncode extends Operation {
this.name = "Cetacean Cipher Encode"; this.name = "Cetacean Cipher Encode";
this.module = "Ciphers"; this.module = "Ciphers";
this.description = "Converts any input into Cetacean Cipher. <br/><br/>e.g. <code>hi</code> becomes <code>EEEEEEEEEeeEeEEEEEEEEEEEEeeEeEEe</code>\""; this.description = "Converts any input into Cetacean Cipher. <br/><br/>e.g. <code>hi</code> becomes <code>EEEEEEEEEeeEeEEEEEEEEEEEEeeEeEEe</code>";
this.infoURL = ""; this.infoURL = "https://hitchhikers.fandom.com/wiki/Dolphins";
this.inputType = "string"; this.inputType = "string";
this.outputType = "string"; this.outputType = "string";
} }
@ -31,23 +32,19 @@ class CetaceanCipherEncode extends Operation {
* @returns {string} * @returns {string}
*/ */
run(input, args) { run(input, args) {
let result = []; const result = [];
let charArray = input.split(''); const charArray = input.split("");
charArray.map( ( character ) => { charArray.map(character => {
if ( character === ' ' ) { if (character === " ") {
result.push( character ); result.push(character);
} else { } else {
const binaryArray = this.encodeToBinary( character ).split(''); const binaryArray = toBinary(character.charCodeAt(0), "None", 16).split("");
result.push( binaryArray.map(( str ) => str === '1' ? 'e' : 'E' ).join('')); result.push(binaryArray.map(str => str === "1" ? "e" : "E").join(""));
} }
}); });
return result.join(''); return result.join("");
}
encodeToBinary( char, padding = 16 ) {
return char.charCodeAt(0).toString(2).padStart( padding, '0');
} }
} }