Skip to content

Add Brainfuck interpreter#470

Merged
SkeletalDemise merged 6 commits intobee-san:masterfrom
mav8557:brainfuck
Oct 3, 2020
Merged

Add Brainfuck interpreter#470
SkeletalDemise merged 6 commits intobee-san:masterfrom
mav8557:brainfuck

Conversation

@mav8557
Copy link
Copy Markdown
Contributor

@mav8557 mav8557 commented Oct 3, 2020

Hello! Great project idea everyone 👍 and thanks for opening to contributors.

This PR adds a Brainfuck decoder. Brainfuck as a language does support user input (a "key" in this case), but the keyspace in this case is practically infinite. For that reason I'd argue a Brainfuck decoder is appropriate, especially for those CTF problems that simply convert strings to Brainfuck programs.

As a result, this decoder is a trimmed implementation of a full Brainfuck interpreter.

A program that can be "decoded" with this is one that:

  • Does not require user input ("," instruction)
  • Includes at least one putchar instruction (".")
  • Does not contain anything but the main 7 instructions,
    (excluding ",") and whitespace.

The last requirement isn't actually a requirement going forward, as some programs might have comments or other text inside of them that can usually be safely ignored. Right now the code does enforce this and return None if there are comments or anything outside of the Brainfuck operators and whitespace, as well as if any of the other requirements are violated.

As requested in #353 the decoder will timeout eventually, at 60 seconds by default. This seemed high to me but if it's alright with you then it's okay.

The Brainfuck specification asks for 30000 memory cells by default, but this seemed excessive for programs that are often not that long. Instead the code starts with 100 cells and appends on any as needed. This can also be changed and is definitely something that I chose arbitrarily as a speed trade-off, so feel free to course correct me on that and we can choose to stick to the spec or something else instead.

Looking to hear what you all think. Thanks for the help with getting started and for maintaining the project!

re-added test_tap_code()

removed tap_code test by mistake, should be fixed.
@bee-san
Copy link
Copy Markdown
Owner

bee-san commented Oct 3, 2020

@all-contributors please add @mav8557 for code

@allcontributors
Copy link
Copy Markdown
Contributor

@bee-san

I've put up a pull request to add @mav8557! 🎉

@bee-san bee-san requested a review from SkeletalDemise October 3, 2020 21:05
@bee-san
Copy link
Copy Markdown
Owner

bee-san commented Oct 3, 2020

This is some great code, excellent self-documenting code 👍

@SkeletalDemise SkeletalDemise changed the title Added Brainfuck decoder Add Brainfuck interpreter Oct 3, 2020
@SkeletalDemise SkeletalDemise linked an issue Oct 3, 2020 that may be closed by this pull request
@SkeletalDemise SkeletalDemise merged commit 862555f into bee-san:master Oct 3, 2020
@mav8557 mav8557 deleted the brainfuck branch October 3, 2020 23:57
@bee-san
Copy link
Copy Markdown
Owner

bee-san commented May 20, 2021

Hey we're changing from MIT to GPLv3 because some of our projects are licensed with that, do you approve? If you do not approve we will be forced to delete your code and rewrite it 😢

By approving of this change, you are agreeing to re-license the code you wrote under GPLv3.

@mav8557
Copy link
Copy Markdown
Contributor Author

mav8557 commented May 20, 2021

Hey we're changing from MIT to GPLv3 because some of our projects are licensed with that, do you approve? If you do not approve we will be forced to delete your code and rewrite it 😢

By approving of this change, you are agreeing to re-license the code you wrote under GPLv3.

That's totally fine. Thanks!

@bee-san
Copy link
Copy Markdown
Owner

bee-san commented May 20, 2021

Thank you!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Brainfuck interpreter

3 participants