mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 14:56:19 -04:00
add cetacean cipher encoder and decoder operations, tests. Update .gitignore to exclude idea generated files
This commit is contained in:
parent
ae1b12c120
commit
578a61d331
7 changed files with 169 additions and 0 deletions
54
src/core/operations/CetaceanCipherEncode.mjs
Normal file
54
src/core/operations/CetaceanCipherEncode.mjs
Normal file
|
@ -0,0 +1,54 @@
|
|||
/**
|
||||
* @author dolphinOnKeys [robin@weird.io]
|
||||
* @copyright Crown Copyright 2022
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
|
||||
/**
|
||||
* Cetacean Cipher Encode operation
|
||||
*/
|
||||
class CetaceanCipherEncode extends Operation {
|
||||
|
||||
/**
|
||||
* CetaceanCipherEncode constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
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.inputType = "string";
|
||||
this.outputType = "string";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
let result = [];
|
||||
let charArray = input.split('');
|
||||
|
||||
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(''));
|
||||
}
|
||||
});
|
||||
|
||||
return result.join('');
|
||||
}
|
||||
|
||||
encodeToBinary( char, padding = 16 ) {
|
||||
return char.charCodeAt(0).toString(2).padStart( padding, '0');
|
||||
}
|
||||
}
|
||||
|
||||
export default CetaceanCipherEncode;
|
Loading…
Add table
Add a link
Reference in a new issue