mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 07:16:17 -04:00
Tidied Cetacean ciphers
This commit is contained in:
parent
6b16f11d3b
commit
4200ed4eb9
4 changed files with 34 additions and 29 deletions
|
@ -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("");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue