4 ms·
JavaScript was Brainfuck all along
- artbit 3y agoJavaScript type coercion allows for some really obscure transformations, that make it look like BrainFuck.
- makeworld 3y agohttps://jsfuck.com/ https://jsfuck.com/
- artbit 3y agoHah! That's awesome. I wasn't aware of it. But yeah, it's not a new idea really. Even my original article was written, over a decade ago: https://blog.djordjeungar.com/post/2011-09-13-obscure-javascript/ https://blog.djordjeungar.com/post/2011-09-13-obscure-javasc...
- Player6225 3y agoAnd then there was that time some people used jsfuck to do xss on Ebay: https://arstechnica.com/information-technology/2016/02/ebay-has-no-plans-to-fix-severe-bug-that-allows-malware-distribution/ https://arstechnica.com/information-technology/2016/02/ebay-...
- pona-a 3y agoCloudflare uses it for some of their challenges.
- kderbyma 3y agoI have used this on some coding challenges when you try to get the shortest answer or oneliner.
- klyrs 3y agoHard mode: write a nontrivial program the intersection of javascript and brainfuck (no characters except []+-,.<>), which does the same thing in both languages.
- trealira 3y agoBrainfuck interpreters just ignore the characters in the file that aren't those particular Brainfuck operators, treating them as comments. So, you could just write a Brainfuck interpreter in JavaScript that interprets a string literal, then write the Brainfuck program as a string literal. You'd still have to write the JavaScript BF interpreter so that everything that isn't the string literal has no observable effect when interpreted by a BF interpreter.
- vrighter 3y agoput the interpreter into a function placed in an array at the beginning. use an array constructor for this and your whole interpreter is now wrapped by a bf loop at the start of the program. Which bf will immediately skip tecause the initial cell will be 0. Then index into an array to get the first item. Another loop on the initial cell. Skipped. Then pass the bf source to the function. No brainfuck commands are needed for this. <pre><code> [ function(src){ // interpreter goes here } ][[]]("brainfuck source goes here"); </code></pre>So your interpreter could be anything you want and it won't conflict with any other bf code as long as you keep your square brackets matched up (this is easy to do in js). The rest is, of course, an exercise left to the reader.
- klyrs 3y agoThat's easy mode
- hyperhello 3y agoDoesn't TypeScript let you build things like this right in the static types?
- specialist 3y agoThe design and impl of Brainfuck represents more thought, effort, esthetics, and clarity of purpose than the initial JavaScript.
- Our_Benefactors 3y agoHaha JavaScript bad, amirite fellow codemonkeys?!