
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
Another Brainfuck interpreter written in JavaScript,
- Customizable and Easy to use · Works in the Browser, Node and Deno -
Machine instance, ( what runs the .bf ) can be customized; bits per cell, length of the tape and its InstructionSet. You can try a demo here.Deliver the package via a cdn:
https://cdn.jsdelivr.net/npm/fuckbrain
https://unpkg.com/fuckbrain
npm install fuckbrain
yarn add fuckbrain
Include the file fuckbrain.min.js , from build/ in your project directory. Then:
Browser:
<script src="path/to/fuckbrain.min.js">
Node:
const Machine = require("path/to/fuckbrain.min.js");
In the build directory is an es6 module of the library. The main|default import of the module id the Machine class:
import Machine from "fuckbrain.min.mjs";
import Machine from "https://cdn.jsdelivr.net/npm/fuckbrain/build/fuckbrain.min.mjs";
To ensure that fuckbrain just works ensure the following JavaScript features are available; If not get some polyfills or consider using a transpiler 🐱🐉.
[Iterators] (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators)*
[Symbol.iterator] (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterator_protocol)*
[Maps] (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)*
To run basic brainfuck code, with as little configuration as possible:
import Machine from "fuckbrain.min.mjs";
let code = "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.";
let myMachine = new Machine();
let output = myMachine.run(code);
console.log(output);
// -> ["H", "e", "l", "l", "o", ",", " ", "w", "o", "r", "l", "d", "!"]
console.log(output.join(""));
// Hello, world!
Because brainfuck code outputs values one byte at a time, the resultant output is an array of ASCII char values. As you would expect, it also expects input one at a time. Brainfuck ingests input as integers, depending on your cellSize. To send data to brainfuck, fuckbrain employs the standard Iterator protocol to allow the user to use their own input stream implementation( input what you want, how you want, when you want it, as long as it's an integer ). Anyways, its quite easy to produce a stream of integers from a String, thanks to ASCII character conversion and a static helper method in the Machine class, Machine.StringInputGenerator:
import Machine from "fuckbrain.min.mjs";
let reverse = "+[>,]<-[+.<-]"; // Reverses its input and spits it out
let myMachine = new Machine();
let output = myMachine.run(brainfuck, Machine.StringInputGenerator("ToiletPaper"));
console.log(output.join(""));
// repaPtelioT
A Machine.BrowserPromptInputGenerator method exists so a prompt popup appears in the browser when input is needed. Do not use this generator in node.js. This method takes an argument, a question to be shown on the popup, defaults to "[INPUT] Brainfuck asks of your input, leave empty to exit:". An empty answer terminates the stream, probably inform the user:
import Machine from "fuckbrain.min.mjs";
let reverse = "+[>,]<-[+.<-]"; // Reverses its input and spits it out
let myMachine = new Machine();
let output = myMachine.run(reverse, Machine.BrowserPromptInputGenerator());
console.log(output.join(""));
// sapmuLapmU
Output is also available instantaneously, just provide an object with a write method as a third parameter to machine.run() and this method will be called every time output is available. You can just wait for execution to complete and receive an array as a return value of machine.run():
import Machine from "fuckbrain.min.mjs";
let tt = "--------[-->+++<]>.."; // The text "tt"
let myMachine = new Machine();
let outputWriter = {
data: [],
write( char ){
this.data.push("s" + char + "er")
},
complete( output ){
// Called with the same output that would be returned by machine.run()
console.log( output ); // -> [ "t", "t" ]
}
};
myMachine.run(tt, Machine.BrowserPromptInputGenerator(), outputWriter);
console.log(myWriter.data.join(""));
// sterster
All these settings are optional and have defaults if not defined;
Manually set the length of the tape:
import Machine from "fuckbrain.min.mjs";
let myMachine = new Machine({
// 4500 cells, defaults to 30000
length: 4500
});
Specify the cell size, ( number of bits per cell ):
import Machine from "fuckbrain.min.mjs";
let myMachine = new Machine({
// 16 bits per cell, -- MUST be a power of 2, defaults to 8 bits per cell --
cellSize: 16
});
Define your own custom instructions: Define a function that is bound to an instruction. This function is called when the instruction is met along the tape. It also gives the instruction meaning and prevents it from getting filtered out during optimizations. Use this to add debugging functionality or extend the InstructionSet in many various creative and spooky ways. To maintain basic functionality I advise extending the built-in instruction set instead of building on from the ground up on your own, you can if you want tho;
import Machine from "fuckbrain.min.mjs";
let custom = Machine.InstructionSet(); // A JavaScript map
custom.set("!", (machine, code, input, output) => {
// A debug instruction that spits out some information
console.log(`[STACK, POINTER]`, machine.stack, machine.pointer)
});
let myMachine = new Machine({
InstructionSet: custom
});
The function passed takes four arguments; machine a reference to the machine instance running the brainfuck code, this includes all its properties and methods, code an array containing all instructions waiting to be executed ( NOTE this is not the code passed to machine.run() as a first argument but a filtered version containing only viable instructions ), **input**a reference to the input iterator passed to **machine.run()**as a second argument, output a reference to the output object passed as the third argument to machine.run().
A "machine" is what runs your brainfuck. I assume you know how brainfuck works. It has a tape, which is basically an "infinite" array of cells initialized at zero. A pointer which points to a specific cell in the tape. Also, your brainfuck code is an array of instructions. An execution pointer points to an instruction in that array. A machine has all these represented as properties, you can access and them alter them:
import Machine from "fuckbrain.min.mjs";
let machine = new Machine();
machine.pointer // ( Number ) The memory pointer's location along the tape
machine.execution // ( Number ) The instruction pointer's location along the instruction tape
machine.tape // ( TypedArray ) The tape
machine.stack // [ Number ] The stack, used for storing the last location of a "[" instruction within the instruction tape
machine.metadata // ( Object ) This allows you to attach some arbitrary data
machine.terminate() // Terminates and resets the machine
All these properties are reset after your brainfuck is done executing. No need to create another machine instance to run more brainfuck, just machine.run() again.
We want to give brainfuck the following features:
v.^.#.import Machine from "fuckbrain.min.mjs";
let custom = Machine.InstructionSet(); // A JavaScript map
custom.set("v", (machine) => {
// Read data from current cell and put to storage
machine.metadata.storage = machine.tape[machine.pointer];
});
custom.set("^", (machine) => {
// Read data from storage and inject into current cell
machine.tape[machine.pointer] = machine.metadata.storage || machine.tape[machine.pointer];
});
custom.set("#", (machine) => {
// Kill the machine
machine.terminate();
});
let machine = new Machine({ InstructionSet: custom });
let code = "++++v>^<.>.#>+[>+]";
let output = machine.run(code);
console.log(output.join("")); // ♦♦
// I call this brainfuck flavour: "bagfuck"
0 - 1 == 255, values wrap around.machine.pointer - 0 == 0Iterator finishes all further input prompts default to 0Number values by default. Input inString format.These are for the default Machine.InstructionSet, you can obviously create your own instruction set from bottom to top with vastly different rules.
FAQs
A simple customizable brainfuck interpreter, that actually works
We found that fuckbrain demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.