Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Brainfuck interpreter #470

Merged
merged 6 commits into from Oct 3, 2020
Merged

Add Brainfuck interpreter #470

merged 6 commits into from Oct 3, 2020

Conversation

mav8557
Copy link
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!

@bee-san
Copy link
Member

bee-san commented Oct 3, 2020

@all-contributors please add @mav8557 for code

@allcontributors
Copy link
Contributor

@bee-san

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

@bee-san
Copy link
Member

bee-san commented Oct 3, 2020

This is some great code, excellent self-documenting code 馃憤

ciphey/basemods/Decoders/brainfuck.py Outdated Show resolved Hide resolved
ciphey/basemods/Decoders/brainfuck.py Show resolved Hide resolved
ciphey/basemods/Decoders/brainfuck.py Show resolved Hide resolved
@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 Ciphey:master Oct 3, 2020
@mav8557 mav8557 deleted the brainfuck branch October 3, 2020 23:57
@bee-san
Copy link
Member

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
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
Member

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