7 ms·
Primg – Generate prime numbers whose binary representation looks like any image
- jwilk 9y agoSource: https://github.com/geonnave/primg https://github.com/geonnave/primg
- notahacker 9y agoNot convinced I actually look like 179769313486231590772930519078902473361797697894230657273430081157732675805500963132708477322407536021120113879871393357110553379400815780032957688591226535854678434413850350192892043530395436831148532011789232552521569332295554081981793617293526812832242447096911185919439189235252915185597964786711096720343 tbh ;-)
- oehpr 9y agoI'm not 100% sure, but do you wear glasses? I think I see how to view this. I can see a silhouette. 17976931348623159077293 05190789024733617976978 94230657273430081157732 67580550096313270847732 24075360211201138798713 93357110553379400815780 03295768859122653585467 84344138503501928920435 30395436831148532011789 23255252156933229555408 19817936172935268128322 42447096911185919439189 23525291518559796478671 1096720343 look at this and unfocus your eyes
- ClassyJacket 9y agoIt's the binary representation that looks like the image, not the decimal one.
- muthdra 9y agoI unfocused it wrong and now I can see it in hexadecimal. Awesome!
- gunn 9y agoputs number.to_s(2).split("").in_groups_of(32).map{|g| g.join("")} Well... it looks like your face was illuminated from the right?
- jchavannes 9y agoIs there a way to link to a number? Or enter a number to view the image?
- geonnave 9y agoThat is very a good idea! For now it is stateless & frontend-only. But I was thinking on improving it, like a prettier UI and adding a "print" button, or maybe a "export to png". If I ever add a server side to it, it will feature a share & see option. Afterthought: actually, I was thinking on using IPFS to store stuff, but I do not know if its model applies to this scenario. Feedback is appreciated.
- fovc 9y agoYou could link to a number by just adding a query or hash with the base64 encoding of the number in 171 characters. You'd lose the original image of course. Edit: I bet a RLE would compress down really nicely except for the bottom row if you want to reduce URL sizes
- geonnave 9y agoThanks guys, you can now access a prime dog right there: https://geonnave.github.io/primg/#179769313486231590772930519078902473361797697894230657273429661642538456588077306078196596037783249291026990862829670919205888565609581869739105202524725614169647793002230079727461396703734603105685474079081886809070115786113168328330817484522518138348888081075292599304124949646601273927687076353436639295493 https://geonnave.github.io/primg/#17976931348623159077293051...
- mbrd 9y agoRelevant Numberphile on generating prime pictures: https://www.youtube.com/watch?v=fQQ8IiTWHhg https://www.youtube.com/watch?v=fQQ8IiTWHhg
- ars 9y agoCan you use this for encryption? Make the decryption key the prime number generated by this, and you unlock it by pointing the camera at the right thing?
- adrusi 9y agoI suppose if you have a very good camera, and are super-humanly precise at aiming the camera, and you have perfectly consistent lighting, then maybe.
- redfast00 9y agoNo, not really: if you take a picture of something, it won't have the exact same pixel values every time you take it. A QR code would be way easier.
- ars 9y agoIt's scaled to 32x32 black and white. The pixel values don't have to be that similar, only reasonable close.
- Cyberdog 9y agoBut then I'm guessing it fudges pixels/bits until it ends up with a prime number. Is that fudging deterministic, or just random?
- progval 9y agoIt tests primality of numbers greater than the number corresponding to the input image by incrementing. So it's deterministic.
- Cyberdog 9y agoIncrementing… So pixels at the bottom right of the image are the most likely to be flipped from the source image. Interesting. (Edit: Assuming big-endianness and left-to-right, top-to-bottom printing of the pixels/bits) Nonetheless, yes, using this to create security keys would probably be a good way to lose your bitcoin. :D
- JorgeGT 9y agoIs this in response to https://mathwithbaddrawings.files.wordpress.com/2017/10/2017-10-6-odd-number-theorists.jpg https://mathwithbaddrawings.files.wordpress.com/2017/10/2017... ?
- jwilk 9y agohttps://github.com/geonnave/primg https://github.com/geonnave/primg links to https://www.reddit.com/r/math/comments/7qpfls/does_there_exist_a_prime_number_whose/ https://www.reddit.com/r/math/comments/7qpfls/does_there_exi... .
- mkl 9y agoPrevious discussion: https://news.ycombinator.com/item?id=16192608 https://news.ycombinator.com/item?id=16192608 The Python version I wrote and linked to back then (which is a bit less general): https://gitlab.com/snippets/1694391 https://gitlab.com/snippets/1694391
- oh_sigh 9y agoPerhaps it shouldn't even bother generating a binary number that ends in '0'
- knodi123 9y agoThe example on https://github.com/geonnave/primg https://github.com/geonnave/primg shows a binary number ending with zero; doesn't that mean it's even, and therefore divisible by 2?
- geonnave 9y agoHmm, that screenshot is from first tests, it is clearly a bug -- but hopefully fixed now :)
- deleted 9y ago[deleted]
- jwilk 9y agoIf you decrease the binary number by 1, it becomes prime. Perhaps it's this bug: https://github.com/geonnave/primg/commit/7ec6cfaa4b581902ea160e684127e34f6747bc51 https://github.com/geonnave/primg/commit/7ec6cfaa4b581902ea1...
- geonnave 9y agoIt is indeed! Haven't noticed the binary was wrong too.
- com2kid 9y agoThis takes a very, very, very long time. 20 minutes in, it is up to 13388 in Firefox. Funny enough, I ran the same image through Chrome, it said it was finish at iteration 458. I'm guessing it is not completely deterministic?
- Retr0spectrum 9y agoYou could probably speed things up a lot using isProbablePrime(), at least to pre-filter candidate numbers. (Assuming you're using this library: https://www.npmjs.com/package/big-integer#isprobableprimeiterations https://www.npmjs.com/package/big-integer#isprobableprimeite...)
- geonnave 9y agoI used isProbablePrime() before, when I had a 50x50 canvas. But it was still really really really slow. After changing to a 32x32 canvas, the difference between isPrime() and isProbablePrime() seemed negligible.
- Retr0spectrum 9y agoInteresting. I guess in that case the only way to speed it up is with multithreading and/or asm.js.
- schoen 9y agoThat makes me think that their probable prime implementation isn't that great or else that they're losing a ton of efficiency to the Javascript interpreter. $ time python -c 'import gmpy; gmpy.next_prime(2**2500)' real 0m0.443s Was it taking a lot longer than that for you? Edit: I can see that there is an element of luck in terms of how many candidates you have to look at, but I'm still seeing everything in this size range take under 2 seconds. Maybe it's a question of what probability of error you're accepting from the test?
- johndough 9y agoGMP is very well optimized and implemented in assembly. There's no way that a JavaScript implementation can get anywhere close to that performance since JavaScript doesn't even have support for 64 bit integers. WebAssembly might be faster, but is still lacking many instructions commonly used for big integer arithmetic.
- krishna2 9y agoYou could color the 1s and 0s - so the image is more obvious and enhanced.
- shabda 9y agoHere is my Python implementation: https://github.com/shabda/experiments/tree/master/prime_dinos https://github.com/shabda/experiments/tree/master/prime_dino... I put up a show HN, but no one liked it :) https://news.ycombinator.com/item?id=16198861 https://news.ycombinator.com/item?id=16198861
- nurettin 9y agoYou should have added "in python" to the title.
- shabda 9y agoPossibly. But I think the immediate results from browser make this one easier for people to see what is happening.
- geonnave 9y agoHi shabda. I've seen your version when I was searching if someone has done this before. And you are right, I did it in Javascript because I wanted to share it with the world more easily.
- shabda 9y agoHaha, awesome! Glad if it helped in anyway. Are you putting your code on github or such? (edit: disregard the question. Its obviously at: https://github.com/geonnave/primg/ https://github.com/geonnave/primg/)
- geonnave 9y agoYes it did, especially as a confirmation that such a thing could be done xD So long and thanks for all the fish!
- Kenji 9y agoI know the pain. I made lots of awesome stuff that received 0 recognition.
- ot 9y ago> numberBigInt = numberBigInt.minus(1) https://github.com/geonnave/primg/blob/master/index.html#L82 https://github.com/geonnave/primg/blob/master/index.html#L82 Could go double as fast subtracting 2 instead of 1 (why try the even numbers).
- geonnave 9y agoI assume the BigInteger library, which offers isPrime() and isProbablyPrime() functions, already does that kind of optimization.
- memyselfando 9y agoWould it not be preferrable to change as little bits as possible? Instead of counting up from your number you should first try to change single bits (one bit, two, three ...) Changing a single out of 3232 bits gives you 1024 variations. Changing two already gives you 10241023/2 = 523776 variations.
- OskarS 9y agoThese are very neat, but all of these I've seen the last few weeks use the same trick of putting some garbage at the end to make it a prime. I wish people would vary their techniques a bit: like, make it base 10 and make an ascii-art image, and introduce imperceptible noise to make it a prime. Or, vary the number of rows and columns, and maybe scale of the image, to make it prime. We need to disrupt the "images as primes" industry!
- reificator 9y agoLast time this kind of thing was on the front page I suggested a frame of noise around the image, which would work to hide the bottom corner.
- geonnave 9y agoHaha! I may change that over the next weekend. Also, PRs are welcome :)
- seertaak 9y agoAh, but can you generate a prime number that encompasses the full list of true statements, please? :)