Brainfuck beware: JavaScript is after you (2012)
patriciopalladino.com
patriciopalladino.com
What prevents language designers from avoiding all these lurking bugs with a generic type-conversion operator? E.g. here's how it might look in a Python-like language:
>>> x = 1
>>> y = "2"
>>> print(x + cast(y))
3
>>> print(cast(x) + y)
"12"
>>> print(cast(x) + cast(y))
Exception: ambiguous type cast(unknown_type) <op> known_type
The programmer could just write tostring or tonumber instead of cast, if the type of the other operand is known >_>So, to take things a step further, lets use, say, the $ operator for casting. Then we have:
>>> x = 1
>>> y = "2"
>>> print($x + y)
3
>>> print(x + $y)
"12"
>>> print($x + $y)
CastError: ...
What do you think? >>> print(str(x) + y)
"12"
>>> print(x + int(y))
3
>>> print (x+y)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'str'
That's already PythonI think you can abuse nearly every language to write crazy code in one way or other.
Here's an example interaction. There's a difference, though, since + is only for {Num instance,Fin} addition while ++ is {String,List,Vect} concatenation.
$ cat evil.py
class cast(object):
def __init__(self, x):
if isinstance(x, cast):
self.x = x.x
else:
self.x = x
def __add__(self, other):
return other.__class__(self.x) + other
def __radd__(self, other):
return other + other.__class__(self.x)
$ python3 -i evil.py
>>> a = 1
>>> b = "2"
>>> a + b
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'str'
>>> cast(a) + b
'12'
>>> a + cast(b)
3
>>> cast(a) + cast(b)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "evil.py", line 9, in __add__
return other.__class__(self.x) + other
File "evil.py", line 9, in __add__
... repeated many times ...
File "evil.py", line 9, in __add__
return other.__class__(self.x) + other
RuntimeError: maximum recursion depth exceeded馃弳
It's nice that this guy actually explains how it works
Gotta love this language... It's a wonder we can get any work done with it. But, used with discipline, it's not too bad.
There was a guy who wrote an entire novel that never used the letter "e" [1]. Is that showing off? Maybe, I guess. It's also a really interesting exercise in writing.
https://stallman.org/articles/on-hacking.html
芦The MIT group defined a hack as a project undertaken or a product built to fulfill some constructive goal, but also with some wild pleasure taken in mere involvement.禄
I once wrote an emulator for a 4 bit microprocessor in Befunge (a 2D esoteric programming language). Then, I was definitely showing off something that really does not matter. 100% useless.
This is a little different. The motivation is the same, but it also proves that you cannot sanitise Javascript by removing letters or words. It's very easy to assume that such sanitisation works, and such an assumption can be a security-critical mistake. I've actually read this article before because I needed to solve such a problem.
Apparently BCPL [0], which dates back to 1966, had a compiler that took up 16k of RAM, some bootstrapped. BCPL influenced B [1], B influenced C [2].
[0] http://en.wikipedia.org/wiki/BCPL [1] http://en.wikipedia.org/wiki/B_(programming_language) [2] http://en.wikipedia.org/wiki/C_(programming_language)
However, if there were a magic wand that you could wave which would show the maximum impact of a particular vulnerability and identify all of the sites in the world which were vulnerable and notified all of the site owners instantly with a full report I can guarantee you that there would be a lot of people out there with some sleepless nights and a lot of emergency work ahead of them.
Compare it to art where an artist only uses a pencil, or limited colour pallet, or limited materials.
Or even art from just a single, constant weighted line: http://www.ignant.de/2013/08/12/one-line-drawing/
There are other benefits to this program in general, one in the area of security and exploring the options for different attack vectors.
[1]: https://gist.githubusercontent.com/nubs/5849633/raw/78bae58f...
For e.g. I believe encoding code using something similar is the only way to solve this challenge - http://escape.alf.nu/9/