mirror of
https://github.com/gchq/CyberChef
synced 2025-12-14 23:33:25 +00:00
Tidied Cetacean ciphers
This commit is contained in:
@@ -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("");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user