Fix linter
This commit is contained in:
parent
dcee118f4a
commit
9ac188d398
@ -1,136 +1,132 @@
|
|||||||
/**
|
/**
|
||||||
* @author kassi [kassi@noreply.com]
|
* @author kassi [kassi@noreply.com]
|
||||||
* @copyright KS 2018
|
* @copyright KS 2018
|
||||||
* @license Apache-2.0
|
* @license Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import Operation from '../Operation';
|
import Operation from "../Operation";
|
||||||
import OperationError from "../errors/OperationError";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BaconCipherDecode operation
|
* BaconCipherDecode operation
|
||||||
*/
|
*/
|
||||||
class BaconCipherDecode extends Operation {
|
class BaconCipherDecode extends Operation {
|
||||||
/**
|
/**
|
||||||
* BaconCipherDecode constructor
|
* BaconCipherDecode constructor
|
||||||
*/
|
*/
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
constructor() {
|
this.name = "Bacon Cipher Decode";
|
||||||
super();
|
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.name = 'Bacon Cipher Decode';
|
this.infoURL = "https://en.wikipedia.org/wiki/Bacon%27s_cipher";
|
||||||
this.module = 'Default';
|
this.inputType = "string";
|
||||||
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.outputType = "string";
|
||||||
this.infoURL = 'https://en.wikipedia.org/wiki/Bacon%27s_cipher';
|
this.args = [
|
||||||
this.inputType = 'string';
|
{
|
||||||
this.outputType = 'string';
|
"name": "Alphabet",
|
||||||
this.args = [
|
"type": "option",
|
||||||
{
|
"value": ["ABCDEFGHIKLMNOPQRSTUWXYZ", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"]
|
||||||
'name': 'Alphabet',
|
},
|
||||||
'type': 'option',
|
{
|
||||||
'value': ['ABCDEFGHIKLMNOPQRSTUWXYZ', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ']
|
"name": "Translation",
|
||||||
},
|
"type": "option",
|
||||||
{
|
"value": ["0/1", "A/B", "Case", "A-M/N-Z"]
|
||||||
'name': 'Translation',
|
},
|
||||||
'type': 'option',
|
{
|
||||||
'value': ['0/1', 'A/B', 'Case', 'A-M/N-Z']
|
"name": "Invert Translation",
|
||||||
},
|
"type": "boolean",
|
||||||
{
|
"value": false
|
||||||
'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";
|
|
||||||
}
|
}
|
||||||
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 {
|
} else {
|
||||||
group = group + "0";
|
char = "?";
|
||||||
}
|
}
|
||||||
break;
|
output += char;
|
||||||
case "A-M/N-Z":
|
|
||||||
if (char.match(regexAM)) {
|
|
||||||
group = group + "1";
|
|
||||||
}
|
|
||||||
else if (char.match(regexNZ)) {
|
|
||||||
group = group + "0"
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
return output;
|
||||||
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++) {
|
|
||||||
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;
|
export default BaconCipherDecode;
|
||||||
|
|||||||
@ -1,48 +1,47 @@
|
|||||||
/**
|
/**
|
||||||
* @author kassi [kassi@noreply.com]
|
* @author kassi [kassi@noreply.com]
|
||||||
* @copyright KS 2018
|
* @copyright KS 2018
|
||||||
* @license Apache-2.0
|
* @license Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import Operation from '../Operation';
|
import Operation from "../Operation";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Brainfuck operation
|
* Brainfuck operation
|
||||||
*/
|
*/
|
||||||
class Brainfuck extends Operation {
|
class Brainfuck extends Operation {
|
||||||
/**
|
/**
|
||||||
* Brainfuck constructor
|
* Brainfuck constructor
|
||||||
*/
|
*/
|
||||||
|
constructor () {
|
||||||
|
super();
|
||||||
|
|
||||||
constructor () {
|
this.name = "Brainfuck";
|
||||||
super();
|
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.name = 'Brainfuck';
|
this.infoURL = "http://esolangs.org/wiki/Brainfuck";
|
||||||
this.module = 'Default';
|
this.inputType = "string";
|
||||||
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.outputType = "string";
|
||||||
this.infoURL = 'http://esolangs.org/wiki/Brainfuck';
|
this.args = [
|
||||||
this.inputType = 'string';
|
{
|
||||||
this.outputType = 'string';
|
"name": "User Input",
|
||||||
this.args = [
|
"type": "text",
|
||||||
{
|
"value": ""
|
||||||
'name': 'User Input',
|
}
|
||||||
'type': 'text',
|
];
|
||||||
'value': ''
|
}
|
||||||
}
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {String} input
|
* @param {String} input
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {String}
|
* @returns {String}
|
||||||
*/
|
*/
|
||||||
run (input, args) {
|
run (input, args) {
|
||||||
const [userInput] = args;
|
const [userInput] = args;
|
||||||
var brainfuck = require('brainfuck-javascript');
|
const brainfuck = require("brainfuck-javascript");
|
||||||
let output = brainfuck.text(input, userInput);
|
const output = brainfuck.text(input, userInput);
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Brainfuck;
|
export default Brainfuck;
|
||||||
|
|||||||
@ -1,58 +1,57 @@
|
|||||||
/**
|
/**
|
||||||
* @author kassi [kassi@noreply.com]
|
* @author kassi [kassi@noreply.com]
|
||||||
* @copyright KS 2018
|
* @copyright KS 2018
|
||||||
* @license Apache-2.0
|
* @license Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import Operation from '../Operation';
|
import Operation from "../Operation";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FernetDecrypt operation
|
* FernetDecrypt operation
|
||||||
*/
|
*/
|
||||||
class FernetDecrypt extends Operation {
|
class FernetDecrypt extends Operation {
|
||||||
/**
|
/**
|
||||||
* FernetDecrypt constructor
|
* FernetDecrypt constructor
|
||||||
*/
|
*/
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
constructor() {
|
this.name = "Fernet Decrypt";
|
||||||
super();
|
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.name = 'Fernet Decrypt';
|
this.infoURL = "https://asecuritysite.com/encryption/fer";
|
||||||
this.module = 'Default';
|
this.inputType = "string";
|
||||||
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.outputType = "string";
|
||||||
this.infoURL = 'https://asecuritysite.com/encryption/fer';
|
this.args = [
|
||||||
this.inputType = 'string';
|
{
|
||||||
this.outputType = 'string';
|
"name": "Secret",
|
||||||
this.args = [
|
"type": "string",
|
||||||
{
|
"value": ""
|
||||||
'name': 'Secret',
|
},
|
||||||
'type': 'string',
|
];
|
||||||
'value': ""
|
this.patterns = [
|
||||||
},
|
{
|
||||||
];
|
match: "^[A-Z\\d\\-_=]{20,}$",
|
||||||
this.patterns = [
|
flags: "i",
|
||||||
{
|
args: []
|
||||||
match: "^[A-Z\\d\\-_=]{20,}$",
|
},
|
||||||
flags: "i",
|
];
|
||||||
args: []
|
}
|
||||||
},
|
/**
|
||||||
];
|
* @param {String} input
|
||||||
}
|
* @param {Object[]} args
|
||||||
/**
|
* @returns {String}
|
||||||
* @param {String} input
|
*/
|
||||||
* @param {Object[]} args
|
run(input, args) {
|
||||||
* @returns {String}
|
const [secretInput] = args;
|
||||||
*/
|
const fernet = require("fernet");
|
||||||
run(input, args) {
|
const secret = new fernet.Secret(secretInput);
|
||||||
const [secretInput] = args;
|
const token = new fernet.Token({
|
||||||
var fernet = require('fernet');
|
secret: secret,
|
||||||
var secret = new fernet.Secret(secretInput);
|
token: input
|
||||||
var token = new fernet.Token({
|
});
|
||||||
secret: secret,
|
return token.decode();
|
||||||
token: input
|
}
|
||||||
})
|
|
||||||
return token.decode();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default FernetDecrypt;
|
export default FernetDecrypt;
|
||||||
|
|||||||
@ -1,50 +1,49 @@
|
|||||||
/**
|
/**
|
||||||
* @author kassi [kassi@noreply.com]
|
* @author kassi [kassi@noreply.com]
|
||||||
* @copyright KS 2018
|
* @copyright KS 2018
|
||||||
* @license Apache-2.0
|
* @license Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import Operation from '../Operation';
|
import Operation from "../Operation";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FernetEncrypt operation
|
* FernetEncrypt operation
|
||||||
*/
|
*/
|
||||||
class FernetEncrypt extends Operation {
|
class FernetEncrypt extends Operation {
|
||||||
/**
|
/**
|
||||||
* FernetEncrypt constructor
|
* FernetEncrypt constructor
|
||||||
*/
|
*/
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
constructor() {
|
this.name = "Fernet Encrypt";
|
||||||
super();
|
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.name = 'Fernet Encrypt';
|
this.infoURL = "https://asecuritysite.com/encryption/fer";
|
||||||
this.module = 'Default';
|
this.inputType = "string";
|
||||||
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.outputType = "string";
|
||||||
this.infoURL = 'https://asecuritysite.com/encryption/fer';
|
this.args = [
|
||||||
this.inputType = 'string';
|
{
|
||||||
this.outputType = 'string';
|
"name": "Secret",
|
||||||
this.args = [
|
"type": "string",
|
||||||
{
|
"value": ""
|
||||||
'name': 'Secret',
|
},
|
||||||
'type': 'string',
|
];
|
||||||
'value': ""
|
}
|
||||||
},
|
/**
|
||||||
];
|
* @param {String} input
|
||||||
}
|
* @param {Object[]} args
|
||||||
/**
|
* @returns {String}
|
||||||
* @param {String} input
|
*/
|
||||||
* @param {Object[]} args
|
run(input, args) {
|
||||||
* @returns {String}
|
const [secretInput] = args;
|
||||||
*/
|
const fernet = require("fernet");
|
||||||
run(input, args) {
|
const secret = new fernet.Secret(secretInput);
|
||||||
const [secretInput] = args;
|
const token = new fernet.Token({
|
||||||
var fernet = require('fernet');
|
secret: secret,
|
||||||
var secret = new fernet.Secret(secretInput);
|
});
|
||||||
var token = new fernet.Token({
|
return token.encode(input);
|
||||||
secret: secret,
|
}
|
||||||
})
|
|
||||||
return token.encode(input);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default FernetEncrypt;
|
export default FernetEncrypt;
|
||||||
|
|||||||
@ -1,88 +1,91 @@
|
|||||||
/**
|
/**
|
||||||
* @author kassi [kassi@noreply.com]
|
* @author kassi [kassi@noreply.com]
|
||||||
* @copyright KS 2018
|
* @copyright KS 2018
|
||||||
* @license Apache-2.0
|
* @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 {
|
class Malbolge extends Operation {
|
||||||
/**
|
/**
|
||||||
* Malbolge constructor
|
* Malbolge constructor
|
||||||
*/
|
*/
|
||||||
|
constructor () {
|
||||||
|
super();
|
||||||
|
|
||||||
constructor () {
|
this.name = "Malbolge";
|
||||||
super();
|
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.name = 'Malbolge';
|
this.infoURL = "http://esolangs.org/wiki/Malbolge";
|
||||||
this.module = 'Default';
|
this.inputType = "string";
|
||||||
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.outputType = "string";
|
||||||
this.infoURL = 'http://esolangs.org/wiki/Malbolge';
|
this.args = [
|
||||||
this.inputType = 'string';
|
{
|
||||||
this.outputType = 'string';
|
"name": "User Input (line by line)",
|
||||||
this.args = [
|
"type": "text",
|
||||||
{
|
"value": ""
|
||||||
'name': 'User Input (line by line)',
|
}
|
||||||
'type': 'text',
|
];
|
||||||
'value': ''
|
this.patterns = [
|
||||||
}
|
{
|
||||||
];
|
match: "^(?:[\\x21-\\x7e])?$",
|
||||||
this.patterns = [
|
flags: "i",
|
||||||
{
|
args: []
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
export default Malbolge;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user