Skip to content

Instantly share code, notes, and snippets.

@jsrn
Created November 4, 2013 13:44
Show Gist options
  • Save jsrn/7302650 to your computer and use it in GitHub Desktop.
Save jsrn/7302650 to your computer and use it in GitHub Desktop.
Conceal Brainfuck in ASCII artwork
#!/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
@coolymike
Copy link

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