Skip to content

Instantly share code, notes, and snippets.

@Buggem
Last active October 1, 2025 03:10
Show Gist options
  • Save Buggem/4edfc5ac24487c1822e147bf5efb7c60 to your computer and use it in GitHub Desktop.
Save Buggem/4edfc5ac24487c1822e147bf5efb7c60 to your computer and use it in GitHub Desktop.
Obfuscated brainfuck runtime in 502 bytes of C
#include <stdio.h>
#include <stdint.h>
FILE *F;int C,S,D,P,L=30000;uint8_t d[30000];void main(int c,char** v){if(c==2){F=fopen(v[1],"r");while((C=fgetc(F))!=-1){if(C==62)P=(P+1)%L;if(C==60)P=(P+L-1)%L;if(C==43)d[P]++;if(C==45)d[P]--;if(C==46)putchar(d[P]);if(C==44)d[P]=getchar();if(C==91&&d[P]==0){D=1;while(D>0&&(S=fgetc(F))!=-1){if(S==91)D++;if(S==93)D--;}}if(C==93&&d[P]!=0){D=1;fseek(F,-2,1);while(D>0&&ftell(F)>0){fseek(F,-1,1);S=fgetc(F);fseek(F,-1,1);if(S==93)D++;if(S==91)D--;}}};fclose(F);}}

BrainfuCk

A BF runtime written in C, aiming to put file size over speed.

Any suggestions to improve the obfuscations in the comments are very, very welcome, as I'm new to this type of stuff and would love to learn!

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#define BUF_LEN 30000
uint8_t datap = 0;
uint8_t data[BUF_LEN];
FILE *filePtr;
int curChar, parScan;
int main(int argc, char** argv) {
if(argc != 2) {
return 1;
}
filePtr = fopen(argv[1], "r");
memset(data, 0, BUF_LEN);
while((curChar = fgetc(filePtr)) != EOF) {
switch(curChar) {
case '>':
datap++;
break;
case '<':
datap--;
break;
case '+':
data[datap]++;
break;
case '-':
data[datap]--;
break;
case '.':
printf("%c", data[datap]);
break;
case ',':
scanf("%c", &data[datap]);
break;
case '[':
if (data[datap] == 0) {
int depth = 1;
while (depth > 0 && (parScan = fgetc(filePtr)) != EOF) {
if (parScan == '[') depth++;
else if (parScan == ']') depth--;
}
}
break;
case ']':
if (data[datap] != 0) {
int depth = 1;
fseek(filePtr, -2, SEEK_CUR);
while (depth > 0 && ftell(filePtr) > 0) {
fseek(filePtr, -1, SEEK_CUR);
parScan = fgetc(filePtr);
fseek(filePtr, -1, SEEK_CUR);
if (parScan == ']') depth++;
else if (parScan == '[') depth--;
}
}
break;
}
if(datap >= BUF_LEN) {
datap = 0;
}
}
fclose(filePtr);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment