-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/valdelaseras/CyberChef
- Loading branch information
Showing
6 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* @author dolphinOnKeys [robin@weird.io] | ||
* @copyright Crown Copyright 2022 | ||
* @license Apache-2.0 | ||
*/ | ||
|
||
import Operation from "../Operation.mjs"; | ||
|
||
/** | ||
* Cetacean Cipher Decode operation | ||
*/ | ||
class CetaceanCipherDecode extends Operation { | ||
|
||
/** | ||
* CetaceanCipherDecode constructor | ||
*/ | ||
constructor() { | ||
super(); | ||
|
||
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.inputType = "string"; | ||
this.outputType = "string"; | ||
|
||
this.checks = [ | ||
{ | ||
pattern: "^(?:[eE]{16,})(?: [eE]{16,})*$", | ||
flags: "", | ||
args: [] | ||
} | ||
] | ||
} | ||
|
||
/** | ||
* @param {string} input | ||
* @param {Object[]} args | ||
* @returns {string} | ||
*/ | ||
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 ]); | ||
} else { | ||
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('')) | ||
} | ||
|
||
return byteArray.map( byte => | ||
String.fromCharCode(parseInt( byte , 2 ) | ||
) | ||
).join(''); | ||
} | ||
} | ||
|
||
export default CetaceanCipherDecode; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* CetaceanCipher Encode tests | ||
* | ||
* @author dolphinOnKeys | ||
* @copyright Crown Copyright 2022 | ||
* @licence Apache-2.0 | ||
*/ | ||
import TestRegister from "../../lib/TestRegister.mjs"; | ||
|
||
TestRegister.addTests([ | ||
{ | ||
name: "Cetacean Cipher Decode", | ||
input: "EEEEEEEEEeeEEEEe EEEEEEEEEeeEEEeE EEEEEEEEEeeEEEee EEeeEEEEEeeEEeee", | ||
expectedOutput: "a b c で", | ||
recipeConfig: [ | ||
{ | ||
op: "Cetacean Cipher Decode", | ||
args: [] | ||
}, | ||
], | ||
} | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* CetaceanCipher Encode tests | ||
* | ||
* @author dolphinOnKeys | ||
* @copyright Crown Copyright 2022 | ||
* @licence Apache-2.0 | ||
*/ | ||
import TestRegister from "../../lib/TestRegister.mjs"; | ||
|
||
TestRegister.addTests([ | ||
{ | ||
name: "Cetacean Cipher Encode", | ||
input: "a b c で", | ||
expectedOutput: "EEEEEEEEEeeEEEEe EEEEEEEEEeeEEEeE EEEEEEEEEeeEEEee EEeeEEEEEeeEEeee", | ||
recipeConfig: [ | ||
{ | ||
op: "Cetacean Cipher Encode", | ||
args: [] | ||
}, | ||
], | ||
} | ||
]); |