diff --git a/src/core/operations/BaconCipherDecode.mjs b/src/core/operations/BaconCipherDecode.mjs index 1ed86b4a..98582eed 100644 --- a/src/core/operations/BaconCipherDecode.mjs +++ b/src/core/operations/BaconCipherDecode.mjs @@ -1,136 +1,132 @@ /** - * @author kassi [kassi@noreply.com] - * @copyright KS 2018 - * @license Apache-2.0 - */ +* @author kassi [kassi@noreply.com] +* @copyright KS 2018 +* @license Apache-2.0 +*/ -import Operation from '../Operation'; -import OperationError from "../errors/OperationError"; +import Operation from "../Operation"; /** - * BaconCipherDecode operation - */ +* BaconCipherDecode operation +*/ class BaconCipherDecode extends Operation { - /** - * BaconCipherDecode constructor - */ + /** + * BaconCipherDecode constructor + */ + constructor() { + super(); - constructor() { - super(); - - this.name = 'Bacon Cipher Decode'; - this.module = 'Default'; - this.description = 'Bacon\'s cipher or the Baconian cipher is a method of steganography(a method of hiding a secret message as opposed to just a cipher) devised by Francis Bacon in 1605.[1][2][3] A message is concealed in the presentation of text, rather than its content.'; - this.infoURL = 'https://en.wikipedia.org/wiki/Bacon%27s_cipher'; - this.inputType = 'string'; - this.outputType = 'string'; - this.args = [ - { - 'name': 'Alphabet', - 'type': 'option', - 'value': ['ABCDEFGHIKLMNOPQRSTUWXYZ', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'] - }, - { - 'name': 'Translation', - 'type': 'option', - 'value': ['0/1', 'A/B', 'Case', 'A-M/N-Z'] - }, - { - 'name': 'Invert Translation', - 'type': 'boolean', - 'value': false - } - ]; - } - - /** - * @param {String} input - * @param {Object[]} args - * @returns {String} - */ - run(input, args) { - const [alphabet, translation, invert] = args; - const regexAM = /[A-M]/; - const regexNZ = /[N-Z]/; - // split text into groups of 5 characters - var groups = []; - var group = ""; - - for (let index = 0; index < input.length; index++) { - const char = input[index]; - console.log(char); - - if (char.toLowerCase() != char.toUpperCase()) { - switch (translation) { - case "0/1": - group = group + char; - break; - case "A/B": - if (char == "A") { - group = group + "1"; - } else if (char == "B") { - group = group + "0"; + this.name = "Bacon Cipher Decode"; + this.module = "Default"; + this.description = "Bacon's cipher or the Baconian cipher is a method of steganography(a method of hiding a secret message as opposed to just a cipher) devised by Francis Bacon in 1605.[1][2][3] A message is concealed in the presentation of text, rather than its content."; + this.infoURL = "https://en.wikipedia.org/wiki/Bacon%27s_cipher"; + this.inputType = "string"; + this.outputType = "string"; + this.args = [ + { + "name": "Alphabet", + "type": "option", + "value": ["ABCDEFGHIKLMNOPQRSTUWXYZ", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"] + }, + { + "name": "Translation", + "type": "option", + "value": ["0/1", "A/B", "Case", "A-M/N-Z"] + }, + { + "name": "Invert Translation", + "type": "boolean", + "value": false } - break; - case "Case": - if (char == char.toUpperCase()) { - group = group + "1"; + ]; + } + + /** + * @param {String} input + * @param {Object[]} args + * @returns {String} + */ + run(input, args) { + const [alphabet, translation, invert] = args; + const regexAM = /[A-M]/; + const regexNZ = /[N-Z]/; + // split text into groups of 5 characters + const groups = []; + let group = ""; + + for (let index = 0; index < input.length; index++) { + const char = input[index]; + + if (char.toLowerCase() !== char.toUpperCase()) { + switch (translation) { + case "0/1": + group = group + char; + break; + case "A/B": + if (char === "A") { + group = group + "1"; + } else if (char === "B") { + group = group + "0"; + } + break; + case "Case": + if (char === char.toUpperCase()) { + group = group + "1"; + } else { + group = group + "0"; + } + break; + case "A-M/N-Z": + if (char.match(regexAM)) { + group = group + "1"; + } else if (char.match(regexNZ)) { + group = group + "0"; + } + break; + default: + break; + } + + if (group.length === 5) { + groups.push(group); + group = ""; + } + } + } + + // Padding + if (group.length > 0) { + group = (group + "0000").substr(0, 5); + groups.push(group); + } + + let output = ""; + const byteLen = 5; + for (let index = 0; index < groups.length; index++) { + let group = groups[index]; + if (invert) { + group = group.replace(/[01]/g, function (m) { + return { + "0": "1", + "1": "0" + }[m]; + }); + } + // calculate binary value + let number; + for (let i = 0; i < group.length; i += byteLen) { + number = parseInt(group.substr(i, byteLen), 2); + } + let char; + if (number < alphabet.length) { + char = alphabet[number]; } else { - group = group + "0"; + char = "?"; } - break; - case "A-M/N-Z": - if (char.match(regexAM)) { - group = group + "1"; - } - else if (char.match(regexNZ)) { - group = group + "0" - } - break; - default: - break; + output += char; } - - if (group.length == 5) { - groups.push(group); - group = ""; - } - } + return output; } - - // Padding - if (group.length > 0) { - group = (group + "0000").substr(0, 5); - groups.push(group); - } - - let output = ""; - const byteLen = 5; - for (let index = 0; index < groups.length; index++) { - var group = groups[index]; - if (invert) { - group = group.replace(/[01]/g, function (m) { - return { - '0': '1', - '1': '0' - }[m]; - }); - } - // calculate binary value - var number; - for (let i = 0; i < group.length; i += byteLen) { - number = parseInt(group.substr(i, byteLen), 2); - } - var char; - if (number < alphabet.length) { - char = alphabet[number]; - } else { - char = "?" - } - output += char; - } - return output; - } } export default BaconCipherDecode; diff --git a/src/core/operations/Brainfuck.mjs b/src/core/operations/Brainfuck.mjs index cf701ab2..93f5ae8e 100644 --- a/src/core/operations/Brainfuck.mjs +++ b/src/core/operations/Brainfuck.mjs @@ -1,48 +1,47 @@ /** - * @author kassi [kassi@noreply.com] - * @copyright KS 2018 - * @license Apache-2.0 - */ +* @author kassi [kassi@noreply.com] +* @copyright KS 2018 +* @license Apache-2.0 +*/ -import Operation from '../Operation'; +import Operation from "../Operation"; /** - * Brainfuck operation - */ +* Brainfuck operation +*/ class Brainfuck extends Operation { /** - * Brainfuck constructor - */ + * Brainfuck constructor + */ + constructor () { + super(); - constructor () { - super(); - - this.name = 'Brainfuck'; - this.module = 'Default'; - this.description = 'Brainfuck is the most famous esoteric programming language, and has inspired the creation of a host of other languages. Due to the fact that the last half of its name is often considered one of the most offensive words in the English language, it is sometimes referred to as brainf***, brainf*ck, brainfsck, b****fuck, brainf**k, branflakes, or BF. This can make it a bit difficult to search for information regarding brainfuck on the web, as the proper name might not be used at all in some articles.'; - this.infoURL = 'http://esolangs.org/wiki/Brainfuck'; - this.inputType = 'string'; - this.outputType = 'string'; - this.args = [ - { - 'name': 'User Input', - 'type': 'text', - 'value': '' - } - ]; - } + this.name = "Brainfuck"; + this.module = "Default"; + this.description = "Brainfuck is the most famous esoteric programming language, and has inspired the creation of a host of other languages. Due to the fact that the last half of its name is often considered one of the most offensive words in the English language, it is sometimes referred to as brainf***, brainf*ck, brainfsck, b****fuck, brainf**k, branflakes, or BF. This can make it a bit difficult to search for information regarding brainfuck on the web, as the proper name might not be used at all in some articles."; + this.infoURL = "http://esolangs.org/wiki/Brainfuck"; + this.inputType = "string"; + this.outputType = "string"; + this.args = [ + { + "name": "User Input", + "type": "text", + "value": "" + } + ]; + } /** - * @param {String} input - * @param {Object[]} args - * @returns {String} - */ - run (input, args) { - const [userInput] = args; - var brainfuck = require('brainfuck-javascript'); - let output = brainfuck.text(input, userInput); - return output; - } + * @param {String} input + * @param {Object[]} args + * @returns {String} + */ + run (input, args) { + const [userInput] = args; + const brainfuck = require("brainfuck-javascript"); + const output = brainfuck.text(input, userInput); + return output; + } } export default Brainfuck; diff --git a/src/core/operations/FernetDecrypt.mjs b/src/core/operations/FernetDecrypt.mjs index f720b6c4..a8ead840 100644 --- a/src/core/operations/FernetDecrypt.mjs +++ b/src/core/operations/FernetDecrypt.mjs @@ -1,58 +1,57 @@ /** - * @author kassi [kassi@noreply.com] - * @copyright KS 2018 - * @license Apache-2.0 - */ +* @author kassi [kassi@noreply.com] +* @copyright KS 2018 +* @license Apache-2.0 +*/ -import Operation from '../Operation'; +import Operation from "../Operation"; /** - * FernetDecrypt operation - */ +* FernetDecrypt operation +*/ class FernetDecrypt extends Operation { - /** - * FernetDecrypt constructor - */ + /** + * FernetDecrypt constructor + */ + constructor() { + super(); - constructor() { - super(); - - this.name = 'Fernet Decrypt'; - this.module = 'Default'; - this.description = 'Fernet is a symmetric encryption method which makes sure that the message encrypted cannot be manipulated/read without the key. It uses URL safe encoding for the keys. Fernet uses 128-bit AES in CBC mode and PKCS7 padding, with HMAC using SHA256 for authentication. The IV is created from os.random().'; - this.infoURL = 'https://asecuritysite.com/encryption/fer'; - this.inputType = 'string'; - this.outputType = 'string'; - this.args = [ - { - 'name': 'Secret', - 'type': 'string', - 'value': "" - }, - ]; - this.patterns = [ - { - match: "^[A-Z\\d\\-_=]{20,}$", - flags: "i", - args: [] - }, - ]; - } - /** - * @param {String} input - * @param {Object[]} args - * @returns {String} - */ - run(input, args) { - const [secretInput] = args; - var fernet = require('fernet'); - var secret = new fernet.Secret(secretInput); - var token = new fernet.Token({ - secret: secret, - token: input - }) - return token.decode(); - } + this.name = "Fernet Decrypt"; + this.module = "Default"; + this.description = "Fernet is a symmetric encryption method which makes sure that the message encrypted cannot be manipulated/read without the key. It uses URL safe encoding for the keys. Fernet uses 128-bit AES in CBC mode and PKCS7 padding, with HMAC using SHA256 for authentication. The IV is created from os.random()."; + this.infoURL = "https://asecuritysite.com/encryption/fer"; + this.inputType = "string"; + this.outputType = "string"; + this.args = [ + { + "name": "Secret", + "type": "string", + "value": "" + }, + ]; + this.patterns = [ + { + match: "^[A-Z\\d\\-_=]{20,}$", + flags: "i", + args: [] + }, + ]; + } + /** + * @param {String} input + * @param {Object[]} args + * @returns {String} + */ + run(input, args) { + const [secretInput] = args; + const fernet = require("fernet"); + const secret = new fernet.Secret(secretInput); + const token = new fernet.Token({ + secret: secret, + token: input + }); + return token.decode(); + } } export default FernetDecrypt; diff --git a/src/core/operations/FernetEncrypt.mjs b/src/core/operations/FernetEncrypt.mjs index f85bd3b1..e929cc84 100644 --- a/src/core/operations/FernetEncrypt.mjs +++ b/src/core/operations/FernetEncrypt.mjs @@ -1,50 +1,49 @@ /** - * @author kassi [kassi@noreply.com] - * @copyright KS 2018 - * @license Apache-2.0 - */ +* @author kassi [kassi@noreply.com] +* @copyright KS 2018 +* @license Apache-2.0 +*/ -import Operation from '../Operation'; +import Operation from "../Operation"; /** - * FernetEncrypt operation - */ +* FernetEncrypt operation +*/ class FernetEncrypt extends Operation { - /** - * FernetEncrypt constructor - */ + /** + * FernetEncrypt constructor + */ + constructor() { + super(); - constructor() { - super(); - - this.name = 'Fernet Encrypt'; - this.module = 'Default'; - this.description = 'Fernet is a symmetric encryption method which makes sure that the message encrypted cannot be manipulated/read without the key. It uses URL safe encoding for the keys. Fernet uses 128-bit AES in CBC mode and PKCS7 padding, with HMAC using SHA256 for authentication. The IV is created from os.random().'; - this.infoURL = 'https://asecuritysite.com/encryption/fer'; - this.inputType = 'string'; - this.outputType = 'string'; - this.args = [ - { - 'name': 'Secret', - 'type': 'string', - 'value': "" - }, - ]; - } - /** - * @param {String} input - * @param {Object[]} args - * @returns {String} - */ - run(input, args) { - const [secretInput] = args; - var fernet = require('fernet'); - var secret = new fernet.Secret(secretInput); - var token = new fernet.Token({ - secret: secret, - }) - return token.encode(input); - } + this.name = "Fernet Encrypt"; + this.module = "Default"; + this.description = "Fernet is a symmetric encryption method which makes sure that the message encrypted cannot be manipulated/read without the key. It uses URL safe encoding for the keys. Fernet uses 128-bit AES in CBC mode and PKCS7 padding, with HMAC using SHA256 for authentication. The IV is created from os.random()."; + this.infoURL = "https://asecuritysite.com/encryption/fer"; + this.inputType = "string"; + this.outputType = "string"; + this.args = [ + { + "name": "Secret", + "type": "string", + "value": "" + }, + ]; + } + /** + * @param {String} input + * @param {Object[]} args + * @returns {String} + */ + run(input, args) { + const [secretInput] = args; + const fernet = require("fernet"); + const secret = new fernet.Secret(secretInput); + const token = new fernet.Token({ + secret: secret, + }); + return token.encode(input); + } } export default FernetEncrypt; diff --git a/src/core/operations/Malbolge.mjs b/src/core/operations/Malbolge.mjs index 0dcef568..c3f2c669 100644 --- a/src/core/operations/Malbolge.mjs +++ b/src/core/operations/Malbolge.mjs @@ -1,88 +1,91 @@ /** - * @author kassi [kassi@noreply.com] - * @copyright KS 2018 - * @license Apache-2.0 - */ +* @author kassi [kassi@noreply.com] +* @copyright KS 2018 +* @license Apache-2.0 +*/ -import Operation from '../Operation'; +import Operation from "../Operation"; +import OperationError from "../errors/OperationError"; /** - * Malbolge operation - */ +* Malbolge operation +*/ class Malbolge extends Operation { /** - * Malbolge constructor - */ + * Malbolge constructor + */ + constructor () { + super(); - constructor () { - super(); - - this.name = 'Malbolge'; - this.module = 'Default'; - this.description = 'Malbolge, invented by Ben Olmstead in 1998, is an esoteric programming language designed to be as difficult to program in as possible. The first ‘Hello, world!’ program written in it was produced by a Lisp program using a local beam search of the space of all possible programs. It is modeled as a virtual machine based on ternary digits.'; - this.infoURL = 'http://esolangs.org/wiki/Malbolge'; - this.inputType = 'string'; - this.outputType = 'string'; - this.args = [ - { - 'name': 'User Input (line by line)', - 'type': 'text', - 'value': '' - } - ]; - this.patterns = [ - { - match: '^(?:[\\x21-\\x7e])?$', - flags: 'i', - args: [] - } - ]; - } - - /** - * @param {String} input - * @param {Object[]} args - * @returns {String} - */ - run (input, args) { - const [userInput] = args; - const EOF = 59048; - - var mb = require('malbolge-vm'), - vm = mb.load(input), - temp, - userInputLines = userInput.split('\n'), - userInputIndex = 0, - output = ''; - - while (true) { - try { - while ((temp = mb.step(vm)) !== mb.EXIT) { - if (temp !== null) { output += String.fromCharCode(temp); } - } - break; - } catch (e) { - if (e === mb.WANTS_INPUT) { - var txt; - if (userInputIndex < userInputLines.length) { - txt = userInputLines[userInputIndex]; - userInputIndex++; - } else { - txt = window.prompt('User input expected', ''); - } - for (var i = 0; i < txt.length; i++) { - mb.step(vm, txt.charCodeAt(i)); - } - mb.step(vm, EOF); - } else { - console.log('Error: ' + e); - } - } - break; + this.name = "Malbolge"; + this.module = "Default"; + this.description = "Malbolge, invented by Ben Olmstead in 1998, is an esoteric programming language designed to be as difficult to program in as possible. The first ‘Hello, world!’ program written in it was produced by a Lisp program using a local beam search of the space of all possible programs. It is modeled as a virtual machine based on ternary digits."; + this.infoURL = "http://esolangs.org/wiki/Malbolge"; + this.inputType = "string"; + this.outputType = "string"; + this.args = [ + { + "name": "User Input (line by line)", + "type": "text", + "value": "" + } + ]; + this.patterns = [ + { + match: "^(?:[\\x21-\\x7e])?$", + flags: "i", + args: [] + } + ]; } - return output; - } + /** + * @param {String} input + * @param {Object[]} args + * @returns {String} + */ + run (input, args) { + const [userInput] = args; + const EOF = 59048; + + const mb = require("malbolge-vm"); + const vm = mb.load(input); + const userInputLines = userInput.split("\n"); + const inputLoop = true; + let temp, + userInputIndex = 0, + output = ""; + + while (inputLoop) { + try { + while ((temp = mb.step(vm)) !== mb.EXIT) { + if (temp !== null) { + output += String.fromCharCode(temp); + } + } + break; + } catch (e) { + if (e === mb.WANTS_INPUT) { + let txt; + if (userInputIndex < userInputLines.length) { + txt = userInputLines[userInputIndex]; + userInputIndex++; + } else { + txt = window.prompt("User input expected", ""); + } + for (let i = 0; i < txt.length; i++) { + mb.step(vm, txt.charCodeAt(i)); + } + mb.step(vm, EOF); + } else { + throw new OperationError(`Error: ${e}`); + } + } + break; + } + + return output; + } } export default Malbolge;