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

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("");
}
}