Welcome to HBH! If you had an account on hellboundhacker.org you will need to reset your password using the Lost Password system before you will be able to login.

Brainfuck


Brainfuck

By ghostghost | 6542 Reads |
0     0

I know there has been an other article about Brainfuck but I thought I could do better at some points so I decided to write my own.

Now to begin with, I saw comments on the other Brainfuck article which were like: "wtf man? seriously. what can you do with this? why would you want to do something with this?" "what the fuck is this" "Brainfuck….HAHAHAHAHAHAHAHAHAHA learn asm,C++/C,html, and even visual fucking basic compared to this bull shit. you noobs make me laugh"

I hope you can get an answer to these "questions" in this article.

Now what is Brainfuck? Brainfuck is the most simplistic programming language there is. It uses only 8 operators and it's meant as a challenge, and to amuse programmers. Its really the smallest language there is. There are compilers out there which are smaller than 200 bytes! And the language uses only 8 operators and everything you can do in any other language, is possible with these operators too. You just have to be creative to figure out how to. Now you don't have to tell me this language isn't practical because I know it isn't. But it's alot of fun to program in brainfuck and it stimulates creativity and logic thought. And it also helps me kill time in boring classes :P

Brainfuck uses a list of bytes, which all start at 0, and a bytepointer, which, as the name says, points to a byte. The operators are: ><+-[].,

> moves the bytepointer one byte to the right. < moves the bytepointer one byte to the left.

  • increases the byte where the bytepointer is currently pointing to with 1.
  • decreases the byte where the bytepointer is currently pointing to with 1.

[ if the byte which the bytepointer is currently pointing to equals 0, jump to the corresponding ]. ] if the byte which the bytepointer is currently pointing to does not equal 0, jump back to the corresponding [.

. output of the value of the byte which the bytepointer is currently pointing to. , get input from user, and store its value in the byte which the bytepointer is currently pointing to.

Output is usually the character with the ascii value of the byte, but it could be anything, like for example, the color for a pixel. Input is usually the ascii value of the key which is used for input (eg A would write 65 in the byte and 0 would write 48 in the byte).

Yes, that's all there really is to it.

Some simple code would be: +++++++++++++++++++++++++++++++++++++++++++++++++.+.+.

Let's analyze it:

+++++++++++++++++++++++++++++++++++++++++++++++++ Will first put the byte's value at 49 (the ascii value of 1). Then . will output this, so it would output 1. Then +. will increase it, and output the new value, which will then be 2. Then another +. will increase it, and output the new value again. which will then be 3.

So the output will be: 123.

Now we can do a nifty trick here to make the code much, much shorter: ++++++++[->++++++<]>+.+.+.

What did we do? As you can see the end is still the same. but alot of the +s are gone.

We replaced ++++++++++++++++++++++++++++++++++++++++++++++++ (thats 48 of them) with ++++++++[->++++++<]>

So first, the byte is put at 8 (the ++++++++ does that). then, it checks if the byte is nonzero, yes it is. so we will decrease the byte and it will be left at 7. then we go one byte to the right, and increase it with 6. then we go one byte to the left (that's the one wich was at value 7) and it checks if its nonzero. Yes it is, so we repeat what's in between the [].

What this does, is add 6 to the second byte, 8 times. so it will then, in the end, be 48. Then after that, the > moves the bytepointer to the byte which is at 48, and it then repeats the lasts steps from the first example. So again, the output will be 123.

That's just one of lots of little tricks you can make up with these operators, like [-] will clear a byte, and [<] will find the first empty byte at the left of the bytepointer. I'm sure you can think of many more tricks like this.

Now a simple little script might look like this: ,>,<[->+<]++++++[->––––<]>. I think this was the first script I wrote myself.

It's a simple script which asks for 2 numbers, and then outputs the sum of the numbers. The sum can't be larger than 9 or it won't give the right outcome.

The simplicity of the languages also allows for fun ascii art scripts. Like you could hide your script in a steganographic way in an ascii art picture :D I unfortunately couldn't put an example of this in here because html and this font don't like ascii art. -_-

Well that's all the basics, and some more advanced aspects, of Brainfuck. I hope you guys liked it, and finally got a better view on Brainfuck and what you can do with it.

Here's the interpreter I use: http://dracuul.tripod.com/brainfck/brainfck01.zip I haven't tested alot of them but I like this one but there are many more, and probably some better than this.

Comments
ghost's avatar
ghost 17 years ago

Looks cool. Im lazy, could you put a link to the compiler or something =D

SySTeM's avatar
SySTeM 17 years ago

Google for one, there's quite a few out there :p

ghost's avatar
ghost 17 years ago

No Hello World???? Nice Stuff Though, I Used To Program In Brainfuck About Two Years Ago And Later On Shifted To Boolfuck And Double Fuck. I'll Rate It Good…

ghost's avatar
ghost 17 years ago

much better artcile :) i'll have to give it a go

ghost's avatar
ghost 17 years ago

boolfuck, doublefuck, shitfuck, assfuck…. nice article btw

ghost's avatar
ghost 17 years ago

while ure at it you can try my sig challenge (click on my name to see the sig and a link to the thread) you need to know what bf is in order to complete it

ghost's avatar
ghost 17 years ago

I think this article was very well put together and clearly explained BrainFuck. I rate this article "Awesome". :)

ghost's avatar
ghost 17 years ago

You missed out the most important thing about brainfuck. It is Turing complete and therefore you can do anything with it

ghost's avatar
ghost 17 years ago

thanx for all the positive comments guys, and mozzer, ur right I didnt say it was turing complete, but I did note that anything is possible with it

ghost's avatar
ghost 17 years ago

Never understood (or tried to understand) brainfuck before, but I understand it now :P

ghost's avatar
ghost 17 years ago

lmao y'all crack meh up XD good article btw

Uber0n's avatar
Uber0n 17 years ago

++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.——.––––.>+.>. That's a simple 'Hello World' code ;)

Uber0n's avatar
Uber0n 17 years ago

Btw this tutorial was really good. I appreciate it :D

ghost's avatar
ghost 17 years ago

Uber0n, that is very long Hello World. I might try something, but I think I will get confused.

ghost's avatar
ghost 17 years ago

@Uber0n, pitty u copied that code from wikipedia eh… well it is one of the shortest hello worlds, I tried to make a shorter one but I couldn't find a way =/ so kaksii, goodluck trying to improve it xD

ghost's avatar
ghost 17 years ago

++++++++++++++++++[>++>+++>++++>+++++>++++++>+++++++<<<<<<-]++++++++++++++++++>>>>+++++++.>—–.<.>++.+++++.<<<<––.>>>>—–.—.<<<<.>>>>>—–.<+++++++++.>––.<<<<<+++++++.>>>>+++.<++++.<<<—––.>>>++++.>––.>-.<<––.>>–.<<.>>+.+.<<.-.<<–––––.<.>>>>-.>+++++.<<<<<.>>>>++++++.<+++++.–.<<<.>>>+.—––.>.<<<<.>>>.<<<.>>>++.+++++.—––.>—––..<++++.>++.<++.–.<<<.>>>>>—–.<<+++.—––.>>.<<<<<.>>>>>+.–.<<++++.>>.<<<<<.>>>—.>>-.<<-.>—–.>––.<—.>+++++++.<<++.>+++++.<<<++.<.>>>>–.+++..<<<<.>>>>++++.>.-.<<<<<.>>>>>+++++.<-.>––.<<<<<.>>>>.-.<<<<.>>>>-.>++++.<<<<<.>>>+++++.—––.>-..<<<<.>>>>+++.<+++++.<<<.>>>.—–.>–.<++++.<<<.>>>++++.—.<<<.>>>>>.<++.>––.<<<<<.>>>.+++.>-.<.>>–.<<-.<<<.>>>+.>>+.<<<<<.>>———–.<—–.

ghost's avatar
ghost 17 years ago

i know that the compiler itself is usually very small for brainfuck, but what about the compiled programs. how large does "hello world" get once compiled for instance? oh and nice article.

ranma's avatar
ranma 16 years ago

You could make this into a decryption challenge