Skip to content

Commit

Permalink
Tidied Cetacean ciphers
Browse files Browse the repository at this point in the history
  • Loading branch information
n1474335 committed Jul 8, 2022
1 parent 6b16f11 commit 4200ed4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 29 deletions.
11 changes: 10 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/core/config/Categories.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@
"Blowfish Decrypt",
"DES Encrypt",
"DES Decrypt",
"Cetacean Cipher Encode",
"Cetacean Cipher Decode",
"Triple DES Encrypt",
"Triple DES Decrypt",
"LS47 Encrypt",
Expand Down Expand Up @@ -114,6 +112,8 @@
"Atbash Cipher",
"CipherSaber2 Encrypt",
"CipherSaber2 Decrypt",
"Cetacean Cipher Encode",
"Cetacean Cipher Decode",
"Substitute",
"Derive PBKDF2 key",
"Derive EVP key",
Expand Down
23 changes: 11 additions & 12 deletions src/core/operations/CetaceanCipherDecode.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -30,7 +30,7 @@ class CetaceanCipherDecode extends Operation {
flags: "",
args: []
}
]
];
}

/**
Expand All @@ -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("");
}
}

Expand Down
25 changes: 11 additions & 14 deletions src/core/operations/CetaceanCipherEncode.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import Operation from "../Operation.mjs";
import {toBinary} from "../lib/Binary.mjs";

/**
* Cetacean Cipher Encode operation
Expand All @@ -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";
}
Expand All @@ -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("");
}
}

Expand Down

0 comments on commit 4200ed4

Please sign in to comment.