Created
November 4, 2013 13:44
-
-
Save jsrn/7302650 to your computer and use it in GitHub Desktop.
Conceal Brainfuck in ASCII artwork
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
brainfuck = File.open("helloworld.bf", "rb").read | |
ascii_art = File.open("animaniacs.art", "rb").read | |
if brainfuck.length > ascii_art.gsub(" ","").length | |
abort "The supplied brainfuck will not fit inside the ASCII art." | |
end | |
output = "" | |
ascii_art.split("").each do |i| | |
if brainfuck != "" | |
if i != " " and i != "\n" | |
i = brainfuck[0,1] | |
brainfuck = brainfuck[1..-1] | |
end | |
end | |
output << i | |
end | |
File.open( "hidden.bf", "w" ) do |file| | |
file.write( output ) | |
end |
This is really cool. How do you guarantee that the fake BF padding at the end doesn't do anything unexpected?
By only using the >, +, and - characters. if a program finishes running it doesn't need those values anymore, it doesn't generate syntax errors, and it doesn't go out of bounds left. The only thing that can happen is that it goes out of bounds right. It always halts after running those instructions because it doesn't create a loop, and it doesn't freeze because it's never asking for user input. It also doesn't mess up the output because it never prints anything.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I rewrote the script to include faking brainfuck code to make it less obvious, and only replace certain characters in the ascii art.
It's good for things like this where you only want to replace ":" for example:
This is what Hello World (with a lot of garbage end data) looks like in ascii art of my name:
Way less obvious where the code ends that way, and still runs just fine (just takes a bit longer to halt and uses slightly more memory for programs that don't loop themselves).
You can find the script in this github repo