Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

BrainF*** Interpreter

by Toodles (Monk)
on Oct 13, 2001 at 13:23 UTC ( [id://118647]=obfuscated: print w/replies, xml ) Need Help??

This is my first posting, and a couple of things caught my eye in one night. First of which is uncovering the language BrainF*** (yup, very Anglo-Saxon name, that). Thinking, I realized just how easy it would be to make an interpreter for that language. Dreadfully simple actually, so I can't really take pride it. But, I would like feed back. This works fine on all known good BF programs I can find, however on the '99 Bottle of Beer' program, it gets to 91 bottles, and hangs, spiking the CPU. Any ideas how to fix I would like to here. Getting the obfu to look good is damn near impossible. Are there any programs to assist with that to get those 'Perl Artist' look to them? (See Swamp Thing below. *drool*)

Here's the code:

<-----Cut Here------>

#!/usr/bin/perl #BrainF*** interpreter. Give filename as arguement, or #reads from STDIN s''while(<d>){s/ [^\<\>\[\]\.\,\+\ -]//g ;$a.=$_ ;}$_=$a;$,=0;@,= ();d y/\<\ >\[\]\ +\-\.\, /zbxu_qs k/; s/z/\$,-- \;/g; s/b/\$,++\;/g;s/x /while(\$,[\$, ]!=0){/g;s/u/}/ g;s/_ /\$,[\$, ]++; /g; s/q/\$ ,[\$ ,]-- ;/g; s/s/ pridntdf"%c",\$, [\$, ];/g;s/k/gdetc \$,[ \$,];/g;edvad l;';s [\s|d]$$g; eval
<-----Cut Here----->Link for BrainF*** scripts:Here

Toodles

Replies are listed 'Best First'.
Re: BrainF*** Interpreter
by CubicSpline (Friar) on Oct 14, 2001 at 00:28 UTC
    Getting the obfu to look good is damn near impossible. Are there any programs to assist with that to get those 'Perl Artist' look to them?

    I'm no Perl Artist, that's for sure, but I was faced with the same thing when trying to format an obfu. It's tough to just move the source code around and try and make it look nice. I looked for code on PM to help do this, but couldn't find any. But as it turns out, it's not that difficult to roll your own utility to help out.

    My solution was to make a script that will take as input a perl source file and a format pattern file. The pattern file is just a text file with with characters and spaces (or black and white pixels, if you will). The script reads in the source and the pattern and it sticks the source into the format of the pattern.

    I posted the code in the Snippets Section. You can find it here.

    HTH

Re: BrainF*** Interpreter
by jynx (Priest) on Oct 14, 2001 at 03:33 UTC

    Usually when formatting obfuscations artists use the typical $_='...';s/\s+//g;eval; wrapper trick, which allows the source to be moved around to whatever position you want so long as the final lines that make the string runnable are runnable. For examples of this you can check out many of Erudil's obfu's, including Camel Code.

    You have to be careful that your code is not dependant on spaces to run, and if it is find a way to either take them out or work around them. You can also help yourself during this process by putting in a die $@ if $@ line at the end so that if your code doesn't compile correctly after wrapping it you can find out why...

    Hope This Helps,
    jynx

Re: BrainF*** Interpreter
by miyagawa (Chaplain) on Oct 13, 2001 at 18:58 UTC
      C:\perl>perl -e "use Inline::BrainF***;" syntax error at -e line 1, near "*;" Execution of -e aborted due to compilation errors.
      Looks like they'll have to use the uncensored name.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: obfuscated [id://118647]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-03-28 14:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found