Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Top Posters

Who's Online (1)

Powered by Vanilla. Made with Bootstrap.
[C++] Brainfuck print string code generator
  • sangf
    Posts: 203
    just a simple thing i made after reading the brainfuck page on wikipedia, i finally understand it.. so this program takes a string input and generates the appropriate brainfuck code to print said string out!


    /**
    * brainfuck_textgen.cpp
    *
    * generates brainfuck code to print out an arbitrary string
    * usage: ./brainfuck_textgen input string goes here
    *
    * author: sangf
    * license: public domain
    */

    #include <iostream>
    #include <cstring>
    #define ASCII_SPACE_CHAR 0x20

    int main(int argc, char *argv[])
    {
    if (argc > 1)
    {
    unsigned int p = 0;
    for (int i = 1; i < argc; i++)
    {
    for (unsigned int n = 0; n < strlen(argv[i]); n++)
    {
    if (p == (unsigned int) argv[i][n])
    {
    std::cout << \".\";
    }
    else if (p < (unsigned int) argv[i][n])
    {
    for (unsigned int x = 0; x < ((unsigned int) argv[i][n]) - p; x++)
    {
    std::cout << \"+\";
    }
    p = (unsigned int) argv[i][n];
    std::cout << \".\";
    }
    else
    {
    for (unsigned int x = p; x > (unsigned int) argv[i][n]; x--)
    {
    std::cout << \"-\";
    }
    p = (unsigned int) argv[i][n];
    std::cout << \".\";
    }
    }
    if ((i + 1) < argc)
    {
    std::cout << \">+[-]\";
    for (unsigned int x = 0; x < ASCII_SPACE_CHAR; x++)
    {
    std::cout << \"+\";
    }
    std::cout << \".<\";
    }
    }
    }
    return 0;
    }


    example i/o:
    brainfuck_textgen.exe Hello world! >> bf.txt

    bf.txt
    said:


    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++++++++.+++++++..+++.>+[-]++++++++++++++++++++++++++++++++.<++++++++.--------.+++.------.--------.-------------------------------------------------------------------.


    prints:

    Hello world!


    i should note that since it uses program parameters to parse, quoting the input string will yield different results. it's not optimized very well, but that's not the point :)
  • Da fuck is brainfuck. Seems useless.
  • sangf
    Posts: 203
    as programming languages go, it is pretty useless, yes. although, it's actually quite capable.. just not a practical language by design. similar to lolcode or other such languages, it's usefullness is not key ;)
  • Sh3llc0d3
    Posts: 1,910
    Oh jesus, more crap to learn. You should get a crack on and come up with a new reversing/cryptography challenge sangf :P Hope it takes less than an hour next time!