Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Image that contains the code that generated it (allrgb.com)
124 points by rahimnathwani on Jan 25, 2022 | hide | past | favorite | 26 comments


Actually it's not so amazing. The program does not render the characters based on code, it actually loads its own source code from a cpp file and renders it as an image. You probably could run this program but give it a different cpp file and it would generate another image...


Yeah that's not a quine. It's cheating.

It's not even that hard to write a real quine.



This is a better version: https://jtra.cz/stuff/essays/math-self-reference/index.html (it actually contains the entirety of the description of what to plot. Also there's an updated version which uses bezier curves for a smooth output)


That is actually what I was expecting when I clicked the link. Was pleasantly surprised!


Am I right that the image doesn't actually contain the code, as in encode it, but rather has a blurred, stylized version of the code? It's not some kind of quine or whatever the of the code to create the image counts as. (Edit: I'm on mobile so just saw a thumbnail, I realized now that it does have all the code in it)

The really cool thing I noticed about this website was the different sizes of the image. The aim is to make a 2^24 pixel image that uses each color on the rgb color space once. That's 48 MB notionally, and some of the images are 20 or 30 MB, but then others are < 1 MB that have a repeating pattern.

Obviously it's possible to encode the image that contains its code in a few kb corresponding to the 100ish lines of code in the image, but the actual size is 42 MB, unsurprisingly the png encoding or whatever it is didn't find the shortcut


"Am I right that the image doesn't actually contain the code, as in encode it, but rather has a blurred, stylized version of the code?"

AIUI that's correct. The code is in the picture, not in the binary representation of the image. The code generates a particular encoding of the picture, but the code is visible in the image regardless of that (and even if you have a printed version of the image).


So, the quine-stion we're all asking now - is there a valid image, that also happens to be a valid executable, that when run, outputs the image?

And/or what about an interpret or compile step in there?


I created something very similar. It is a PNG and bootable x86 MBR polyglot. When executed, it rewrites the PNG's image data, to convey the program's output.

https://twitter.com/OverTheWireCTF/status/146574242275182182...

Someone who solved the challenge did a writeup:

https://joe.lothan.net/ctfs/2021-advent-otw/00-warmup/


Wow, such an impressive CTF! Did the author solve it in the exact way you intended? I'm curious what the real answer to problem 8 was, now!


To be honest there is no singular intended solution, I deliberately designed it so that there were multiple approaches that could make sense (especially in combination). Intended solutions include but are not limited to:

- Guessing by hand.

- Bruteforce by programatically feeding input into QEMU (as in that writeup).

- Bruteforce by only emulating the "important" code, via something like Unicorn.

- Bruteforce by reimplementing the algorithm in another language (There are some tricks you can use to make it go fast - maybe I should write those up...)

- Reducing the search space by grepping for likely keywords.

- Bruteforce of remaining bytes of the RC4 key (also as in that writeup).


If a Game Boy ROM counts as an executable, it's been done: https://github.com/pinobatch/little-things-gb/tree/master/gb...


> is there a valid image, that also happens to be a valid executable, that when run, outputs the image?

Yes, this exists:

https://codegolf.stackexchange.com/a/23255



Mayne a quine in postscript gnuplot or some other graphical language would be equivalent. I found the link below for postscript but I'm on my phone so I can't readily test it

http://www.nyx.net/~gthompso/self_post.txt


(12 12 moveto /Courier 10 selectfont <28> show show <29> show (dup cvs exec) show)dup cvx exec


Yeah, just need to add an OCR step.


No, it's not a quine, it reads its own source code. That's cheating.


I see it reads its own .cpp file. I wonder if you can avoid that and turn it into the equivalent of a quine somehow.


It would be exactly a quine, you'd just ram the generated source code through the image generation algorithm rather than printing to stdout. So yes, the existence of quines means that it must be possible. It'd probably be about twice as long, though, based on the typical shape of C/C++ quines.


How do you go about finding or searching for functions/code that generates a representation when you graph/run it? Was this done by hand or was there some search involved?


The simplest quines have the form:

  1. Construct encoded string
  2. Decode string
  3. Print decoded string
Once you get that up and running, you can stuff anything you want into the payload.


Love all of these, wondering if / how they could incorporate some quasi-color theory?


I've got some early entries on there. For instance, this one from 12 years ago (https://allrgb.com/old-laser-printer)

I can answer any questions you've got


Quick! Make NFTs and sell them for $30,000 each!

In all seriousness, I really like this: https://allrgb.com/greedy-spaghetti-pandemonium


You kid but it's been done for $20,000... https://opensea.io/assets/0xcb0aaefaf53f94b439a79c3aa232a9f7...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: