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

View File

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

View File

@ -20,7 +20,7 @@ class CetaceanCipherDecode extends Operation {
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>";
this.infoURL = "";
this.infoURL = "https://hitchhikers.fandom.com/wiki/Dolphins";
this.inputType = "string";
this.outputType = "string";
@ -30,7 +30,7 @@ class CetaceanCipherDecode extends Operation {
flags: "",
args: []
}
]
];
}
/**
@ -40,24 +40,23 @@ class CetaceanCipherDecode extends Operation {
*/
run(input, args) {
const binaryArray = [];
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 ]);
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]);
} else {
binaryArray.push( char === 'e' ? 1 : 0 );
binaryArray.push(char === "e" ? 1 : 0);
}
}
const byteArray = [];
for ( let i = 0; i < binaryArray.length; i += 16 ) {
byteArray.push(binaryArray.slice(i, i + 16).join(''))
for (let i = 0; i < binaryArray.length; i += 16) {
byteArray.push(binaryArray.slice(i, i + 16).join(""));
}
return byteArray.map( byte =>
String.fromCharCode(parseInt( byte , 2 )
)
).join('');
return byteArray.map(byte =>
String.fromCharCode(parseInt(byte, 2))
).join("");
}
}

View File

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