Skip to content

Instantly share code, notes, and snippets.

@justin-himself
Last active Oct 14, 2021
Embed
What would you like to do?
C++ Brainfuck Interpreter (Obfuscated)
++++[->++++++++<]>..[->+++<]>-....+[->+++<]>.[->+++<]>-....+[->+++<]>.....[->+++<]>-....+[->+++<]>.[->+++<]>-.+[->+++<]>.......[->+++<]>-.>++++++++++.[->+++<]>++.[-->+++<]>-.+[--->++<]>.[->+++<]>-...-[-->+<]>.+[--->++<]>.[->+++<]>-...[->++++<]>.[---->+<]>+...[-->+++<]>-.+[--->++<]>.[->+++<]>-...[->++++<]>.[---->+<]>+.-[->++++<]>.[---->+++<]>++.+[->+++<]>...[->+++<]>-.[->++++<]>.[---->+<]>+.-[->++++<]>.[---->+++<]>++..>++++++++++.>--[-->+++<]>-.[---->+<]>+.-[->++++<]>.[---->+<]>+...-[->+++<]>-.+++...+[->+++<]>.-[->+++<]>-.+[--->+<]>+..-[->++++<]>.[---->+<]>+.-[->++++<]>.[---->+<]>+...-[->++++<]>.[---->+<]>+.-[->++++<]>.[---->+<]>+.-[->++++<]>.[---->+<]>+.-[->++++<]>.[---->+<]>+.-[->++++<]>.[---->+<]>+.+++++++.-[-->+++++<]>.+[->+++<]>.-[->+++<]>-.[++>---<]>.>--[-->+++<]>-.[---->+<]>+.-[->++++<]>.[---->+++<]>++...+[->+++<]>.[->+++<]>-...++++[->+++<]>.---------.-[->++++<]>.[---->+<]>+.-[->++++<]>.[---->+<]>+.-[->++++<]>.[---->+++<]>++...[->++++<]>.[---->+<]>+.-[->++++<]>.[---->+<]>+.-[->++++<]>.[---->+++<]>++.[->++++<]>.[---->+<]>+.-[->++++<]>.[---->+<]>+.-[->++++<]>.[---->+++<]>++.++++[->+++<]>.---------.-[->++++<]>.>++++++++++.[->+++<]>++.-[->+++<]>-.+++....[->++++<]>.[---->+++<]>++....-[-->+<]>.+[--->++<]>...-[->+++<]>-.+++....[->++++<]>.[---->+++<]>++.[->++++<]>.[---->+++<]>-.+++..-[-->+<]>---.+++[->++<]>+.[->++++<]>.[---->+++<]>++.-[-->+<]>-.+[->++<]>+..-[-->+<]>.>++++++++++..[->+++<]>++.....[->+++<]>-.+[->+++<]>.......[->+++<]>-.+[->+++<]>.........[->+++<]>-.+[->+++<]>...[->+++<]>-.>++++++++++.[->+++<]>++....-[->++++<]>.[---->+<]>+.-[->++++<]>.[---->+<]>+.[->+++<]>-...+[->+++<]>.++++++++.[++++>---<]>+.++++[->+++<]>.[--->+<]>----.+[->+++<]>.[->+++<]>-..+[->+++<]>...-[->++++<]>.[---->+<]>+.-[->+++<]>-.+[--->+<]>+.-[->++++<]>.[---->+<]>+.-[->++++<]>.[---->+<]>+.[->+++<]>-.....+[->+++<]>......[->+++<]>-..>++++++++++.[->+++<]>++.[->+++<]>-.+[->+++<]>..-[->++++<]>.[---->+<]>+.-[->++++<]>.[----->++++<]>-.+[--->++<]>.[->+++<]>-.+[->+++<]>.-[->+++<]>-.+[--->++++<]>.[---->+<]>+.-[->++++<]>.[---->+<]>+.+++++++.-[-->+++++<]>.+[->+++<]>.-[->+++<]>-.+[--->+<]>+..-[->++++<]>.[---->+<]>+..-[->+++<]>-.+[--->++++<]>.[---->+<]>+.-[->++++<]>.[----->++++<]>-.+[--->++<]>.[->+++<]>-.+[->+++<]>.-[->+++<]>-.+[--->+<]>+.-[->+++<]>-.+[--->+<]>+.[-->+++<]>-.-[->++<]>.+[--->+<]>+.[-->+++<]>-.+[--->++<]>.[-->+++<]>-.>++++++++++.>--[-->+++<]>-.[---->+<]>+.-[->++++<]>.[---->+++<]>++.[->++++<]>.[---->+<]>+.-[->++++<]>.[---->+<]>+.++++++++.[++++>---<]>+.++++[->+++<]>.---------.-[->++++<]>.[---->+<]>+.-[->++++<]>.[---->+<]>+.-[->++++<]>.[---->+<]>+.-[->++++<]>.[---->+<]>+.-[->++++<]>.[---->+<]>+.-[->++++<]>.[---->+<]>+.-[->++++<]>.[---->+++<]>-.+[--->+<]>+..-[->++++<]>.[---->+<]>+.++++++++.[++++>---<]>+.++++[->+++<]>.---------.-[->+++<]>-.+[--->+<]>+.>+[--->++<]>.+[--->+<]>+++..>+[--->++<]>.+[--->+<]>+++.[-->+++<]>-.>++++++++++.[->+++<]>++.-[->+++<]>-.+++...-[-->+<]>.+[--->++<]>.-[->+++<]>-.+++...-[-->+<]>.>--[-->+++<]>-.[---->+++<]>++.[->++++<]>.[---->+++<]>++.[->++++<]>.[---->+<]>+.-[->++++<]>.[---->+++<]>++.[->++++<]>.[---->+<]>+.-[->++++<]>.[---->+++<]>++.[->++++<]>.[---->+<]>+.-[->+++<]>-.+++.[->++++<]>.[---->+++<]>-.+++...-[-->+<]>.+[--->++<]>.-[->+++<]>-.+++.-[-->+<]>.-[->++<]>.+++.-[-->+<]>.>++++++++++.
/* Date: 2021-10-14 */ #define __(F) if (*___ == F) {
/* Name: Brainf*ck Interpreter */ #define ______(F) if (F) {
/* Author: Justin Zhang */ #define _ "><+-.,[]"
/* Link: git.io/bfinterpreter */ #define __________(F) putchar(F);
/* Usage: - gcc interpreter.c -o bf */ #define _____________ getchar();
/* - ./bf # No arguments */ #define _____(F) while (F) {
/* - ./bf "..." # Interpreter */ #define _______ 0xFFFE
/* Brainf*ck Code Table: */ #define ________ char
/* > increment the data pointer */ #define ___________ _______[______]
/* < decrement the data pointer */ #define ___(F) __(F[_])
/* + increment the data pointed */ #define ____ }
/* - decrement the data pointed */ #define _F int _________
/* . output data pointed (ascii) */ #define __F ________
/* , input data to data pointed */ #define ___F **__________
/* [ if *ptr = 0, jump after matched ']' */ #define ____________ main(_F,__F ___F) {
/* ] if *ptr!= 0, jump after matched '[' */ #include <stdio.h>
________ ______[_______ + (_______ == _______)]; ____________ ________ *___ = (_________ == (_ ==
_)) ? "++++[++++>---<]>.>-[--->+<]>--.+[--->+<]>++++.+[->++<]>+.+[--->+<]>.+++++++++.+[->+++<]>.++\
[->+++<]>.------------.+++++[->++<]>.[-->+++<]>.------.+++++.-[->+++++<]>-. [-->+++++<]>--.-[-- \
->+<]>.++++++++.+[---->+<]>+++." : /**/*(__________ + (_ == _)), *_____ = ______; _____(*___) ___((
_______^_______/*__ ___*/)) ++_____; ____
___((_ == _))--/**_ ______*/_____; ____
___(((_ == _)/*_)(_ /___*/<< (_ == _)))++
*_____; ____/*(_==_ ()*/___((((_ == _) <<
(_ == _)) |/*__&&__ ▄▄▄▄ ▄▄▄▄ __;___*/ (_ == _)))--
*_____; ____/*.++++ ██▀▀▀▀█ ▄█▀▀▀▀█ ___*/___((((_ == _) \
<< (_ == _))/*<< __ ██▀ ██▄ __*___*/<< (_ == _)))
__________(*/***^__ ██ ▀████▄ _^_^___*/_____); ____
___(((((_ ==/*__; _ ██▄ ▀██ ____*/_) << (_ == _))
<< (_ == _))/*___;_ ██▄▄▄▄█ █▄▄▄▄▄█▀ __=_=__*/| (_ == _)))
*_____ =/*_________ ▀▀▀▀ ▀▀▀▀▀ ______*/_____________
____ ___((((/*_(!*_) _____*/(_ == _) << (_
== _)) << (_/*_____ ____*/== _)) | ((_ ==
_) << (_ == _/*__=_ (__=__)<<*/))))______
(!*_____)++/*<<(__= Written by Justin __!*____*/___ ; _____
( ___________/*____ Oct 14 2021 _____*/) ___(((((_ ==
_) << (_ ==/*++.<<_ ==_____*/_)) << (_ ==
_)) | (((_ ==/*(__<< --__*/_) << (_ == _))
| (_ == _))))/*_____ >>___*/++___________;
____ ___((((/*______ ||____*/_ == _) << (_
== _)) << (((_ == _) << (_ == _)) | (_ == _))))-- ___________; ____++ ___; ____ ____ ____ ___(((((_
== _) << (_ == _))/**/ << (_ == _)) | (((_ == _) << (_ == _)) |(_ == _)))) ______(*_____)-- ___,
++___________; _____(___________) ___(((((_ == _) << (_ == _)) << (_ == _)) | (((_ == _) << (_ ==
_)) | (_ == _)))) ++___________; ____ ___(((((_ == _) << (_ == _)) << (_ == _)) | ((_ == _) << (_
== _))))-- ___________; ____-- ___;/* _____ ___ ______ ;____ ____*/ ____ ____ ____ ___++; ____ ____
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char **argv) {
if (argc < 2)
return -1;
string path(argv[1]);
ifstream readFile(path);
if (!readFile.good())
return -1;
string strbuf;
char cstrbuf[4096];
while (readFile.read(cstrbuf, sizeof(cstrbuf)))
strbuf.append(cstrbuf, sizeof(cstrbuf));
strbuf.append(cstrbuf, readFile.gcount());
string ret;
for (string::iterator it = strbuf.begin(); it != strbuf.end(); it++) {
if (*it == '/' && *(it + 1) == '/')
while (++*it != '\n');
if (*it == '>' || *it == '<' || *it == '+' || *it == '-' || *it == '.' ||
*it == ',' || *it == '[' || *it == ']') {
ret += *it;
}
}
cout << ret;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment