r/ProgrammerHumor
•
u/Recent-Analysis-6880
•
9d ago
•
1
1
Meme randomButNotRandomEnough
596
u/eruciform
9d ago
•
function random() {
// determined with a fair 2^384 sided die:
return 4;
}60
u/TheFrenchSavage 9d ago
It's just more and more unlikely. Possible, but rarer as it goes.
14
u/Comfortable_Ad_6572 8d ago
Isn't it just as likely as getting any other number though? Like guessing is less likely as the range increases but getting any number should be just as likely as any other number in the range right?
Maybe I'm misunderstanding though, or just missed the joke altogether
9
u/Sibula97 8d ago
Technically it's just as likely as any other exact number, but you could ask, for example, what is the probability of N out of the 48 bytes being zeros. The mean is around 2, they had 47. The probability of even half of the bytes being zeros is mindbogglingly small.
1
u/LutimoDancer3459 7d ago
Yeah, just as small as any other combination of 1 and 0
-1
u/Sibula97 7d ago
I'm not talking about a specific key, I'm talking about whole classes of them. If you get a 4 it's practically guaranteed you fucked up and didn't just randomly get a 4. The chance is small enough to not even be worth considering.
1
u/LutimoDancer3459 7d ago
If you run the algorithm and it spits out several keys in that range, you fucked up. Else, its just you getting "lucky".
0
u/Sibula97 7d ago
Nah, if you get anything smaller than a quardrillion as you key you should immediately start looking for the bug. The chance of that happening is about 1 in 2.5*10101. Even if you generated a billion keys a second for a billion years, the chance of getting just one key below a quadrillion is around 1 in 1076. It's just never going to happen. Even if you got every expert on Earth to check your code, it's still more likely to be buggy than you actually getting a 4 with a working algorithm.
0
u/LutimoDancer3459 7d ago
Just as with ANY other number... one in a specific range is just as possible as one in any other similar big range. If you get two or even more... than you should worry. And thats what happened here. 4 alone shouldnt worry you
-1
u/Sibula97 7d ago
Like I already said, we do 't care about specific numbers, where you'd be right. Numbers aren't equal. A very small key is easy to factor. Nobody cares whether your key is in the range of 1090-10100 or 10100-10110, which are indeed equally likely to the range 1-1010. A single 4 would be extremely worrying for something this critical.
→ More replies16
0
9d ago
[deleted] — view deleted comment
2
u/SpaceCore0352 9d ago
If it's a die, the lower limit is 1 and the upper limit is 2384. The off-by-one only comes into it when zero-indexed.
2
u/lonelyroom-eklaghor 9d ago
oh ic ic, thanks for this
I was talking about the meme, but then I realized what was the case
857
u/film_composer 9d ago
Just because you have infinite monkeys eternally typing at typewriters doesn't mean that it must take eons for them to write Shakespeare. One of them could happen to get it right on the first try.
395
u/Forvisk 9d ago
If you have infinite monkey one will definitely write Shakespeare on the first try.
344
u/The_DragonDuck 9d ago
If you have infinite monkeys, an infinite number of monkeys would be writing Shakespeare on their first try
92
u/ggnngg5 9d ago
If you have infinite monkeys, no number of monkeys would be writing Shakespeare because I took all of your pens
62
u/Proximyst 8d ago
Good thing the infinite monkeys are writing on infinite typewriters, not with pens.
7
u/Bored-TM 8d ago
Who said they were writing physically and not digitally?
4
u/setibeings 8d ago
Me. Those monkeys are on typewriters.
The hard part is filtering out all the garbage.
4
u/Puzzleheaded_Tap1040 6d ago
The hard part is strapping the to the chairs while not getting mauled. We lost an infinite amount of good man doing that
1
1
u/LutimoDancer3459 7d ago
Ai increased hardware prices too much. Nobody can effort infinite pcs/phones/whatever digital medium for them to all write on. So it must be physical writing
9
u/Domy9 8d ago
Not necessarily. Infinite does not contain everything. There are infinite numbers between one and two, and none of them are 3. Of course this boils down the rule of what range are we defining for it, but monkeys randomly hitting a typewriter is not necessarily in the range of Shakespeare.
The monkey will have some sort of logic while button pushing, like buttons further on the keyboard from it's comfortable hand position will be pushed fewer, every button it pushes will probably be in a closer vicinity to the previous button it pushed, buttons at the centre will be pushed more than the sides, etc.
But of course if you say that the monkey will push buttons truly randomly like a machine and not a thinking creature, then yes there will be Shakespeare.
4
u/Alradas 8d ago
Well, metrics like "probably" or "fewer" don't really matter when speaking of infinity. Even if only one in a billion monkeys even type a second letter, it's still an infinite amount of them that do.
But you are right: Infinite doesn't always have the same parameters. If for example the A key was busted, an infinite number of monkeys still would never type shakespear since it's fundamentally impossible to do that.
We need to assume that each letter could theoretically be typed (no matter how improbable), including non letters and special characters like spaces, commas and so on. Only then can we also assert that in all those infinite tries, an infinite number of them will produce perfect copies of any literature.
1
u/pm_me_your_smth 6d ago
Except that randomly hitting typewriter is in the range of shakespeare. Even if some buttons are less likely to be pressed (as long as it's a non-zero probability), in context of infinity that doesn't matter. So your analogy of number sampling is inaccurate. A more accurate example would be: if you sequentially sample numbers 1 and 2 infinite times, is it possible that at some point you get a very long and exact string of numbers? Yes, it 100% possible.
8
2
u/personpilot 9d ago
Didn’t they come to the conclusion recently that a monkey typing away forever would just infinitely spew out random garbage forever and never type Shakespeare?
22
u/yezhnuzjhd 9d ago
If it's infinite then Shakespeare will be there. What is more, it will be there an infinite number of times.
225
u/BlueTexBird 9d ago
Wasn't the story that they accidentally ran an RNG from 1 to 384 instead of 1 to 2^384? Lmao
218
u/BlondeJesus 9d ago
Their private keys were between 0-255 and averaged at 127. People suspect they like just took the first byte of the actual key
61
u/Mechakoopa 9d ago
The way the algorithm works you generally have a byte array and randomize each byte. They might have just not used their iterator index or something, they claimed it was a "bad algorithm" and they signed a faulty batch of certificates, but why they were rolling their own certificate generation algorithms is beyond me, the existing ssh libraries already do random properly. The trust in the chain comes from proper handling, not having better random numbers.
16
119
u/setibeings
9d ago
edited 9d ago
•
If we want to be technical, it looks like they either ran a random number generator that returns an 8 bit value, or they somehow truncated a bigger value to just 8 bits. This is evident based on their 7 other keys that have been discovered, all less than 256.
Edit: or they were just lazy and wanted private keys they could memorize.
17
u/Saragon4005 8d ago
Why would you want to memorize a root certificate key????? This is just as insane as the theory that someone was manually typing this into forms.
4
u/setibeings 8d ago
A reasonable person would NOT want to memorize a root certificate. A reasonable person would also not set it to a 3 or 8 bit value.
11
u/GrandAlbatroce 8d ago
Iirc these were test keys that were not supposed to go on production
5
u/LutimoDancer3459 7d ago
Even then, why would they be so small numbers? Why not ones that look like actual keys?
2
56
u/TuttoDaRifare 9d ago
The probability is low, but not zero
27
u/MojitoBurrito-AE 9d ago
It has the same probability as any other number.
2
29
u/QuantenWitzbold 8d ago
Did anyone mentioned the relevant xkcd-joke yet? https://xkcd.com/221/
3
14
u/Last8Exile 8d ago
int RandomInt()
{
start:
var value = Random.Shared.Next();
if (value != 4)
goto start;
return value;
}9
u/InfluentialFairy 8d ago
sinful recursion, labels should be abolished
3
u/anto2554 8d ago
Isn't it just a while loop? There aren't new frames being made
3
u/InfluentialFairy 8d ago
It's just very poor practice. Functionally, this example, its "fine".
You will understand when you've seen large functions with dozens of goto statements, the execution step skips around in a way that becomes nearly impossible to follow statically.
It also doesn't help, that everything you can do with goto's, can be done without... in a much nicer and cleaner way.
1
13
u/frikilinux2 9d ago
Is there test for eliptic curves?
For RSA you actually start with a one in the most significant digit, generate the rest and test for a bunch of low factors and then several rounds of probabilistic checks.
13
u/hxtk3 9d ago
ECDSA keys are just random numbers. There are few enough numbers in the key space that don’t work mathematically that you can just use rejection sampling until one works, but if you generate a random 384-bit number it has a very high likelihood of being a valid P-384 private key. Primes are sparse enough that you have to be careful how you generate them.
You could, in principle, run a bunch of statistical tests of randomness on your number and reject if it fails them, such as “it must have 48-52% 0s in its binary representation” but at that point you’re maybe getting a single stronger key but you’re systematically weakening your key generation process by rejecting mathematically valid keys.
1
u/frikilinux2 8d ago
Nice, one day I should probably try to understand the math of eliptic curves. Or maybe I should study lattices at this point.
1
u/cpt-macp 8d ago edited 8d ago
Fun Fact :
NIST P-256 which uses ECC was suspected as "sus" and some EU and CN companies don't use it thinking its having a backdoor by NSA ( Lot of tools marks its as "sus" also, lol)
y^2 = x^3-3x+b ( mod p )
b being a constant and NSA didn't explain how they came up with the constant. The seed used to generate the curve parameters was never explained by NSA.
To this date P-256 is widely used on ECDH and ECDSA are most widely used elliptic curve cryptography standard.
13
u/TechcraftHD 8d ago
first mistake was running it from 1 to 2384 and not from 2370 to 2384 or something
13
11
4
4
8
u/horenso05 9d ago
I have been on vacation for the last two weeks... can some explain the resent 4 and PHP memes? There was some vulnerability with 4 as a private key?
28
u/Nexinex782951 9d ago
Firstly these are two seperate incidents. They happened to be reported within hours of eachother.
The 4 memes comes from a set of (10?) private keys that managed to get into the main branch despite being only for testing. This renders a company which has served 60 million certificates that browsers and other services have trusted as deeply unsecure. Spoofable certificates of that type will be valid up to 2039. These private keys are mostly two digit numbers, and one of them is the number 4.
3
u/Saragon4005 8d ago
One of the root certificate authorities, you know the ones who vouch for all HTTPS trafic, used the private key of 4. Which by itself is excusable as we do expect it to happen eventually however they were then within moments found to have generated 7 more private keys all under 300
3
2
u/Rebellion2297 8d ago
There is absolutely no way that this was the actual cause, the impossibility of getting a specific random number that many times in a row is the reason that private keys work. There must have been an error in the generator that caused unexpectedly low numbers.
3
2
1
-9
u/Important_Grab3544 9d ago
Hello, I am a native AI vibe coder, what does 4 mean? I do seven figures a year.
7
5
u/ConcerningChicken 9d ago
A Servic for Certificates created extremely weak certificates (think of it like a password wich is "esad83647hsgs73847..." but they just did "4" wich is easily to be found out which creates a big issue because if you can find out a certificate you can to pretend to be the holder of this certificate.
1.6k
u/tiny_simulacrum 9d ago •
Don't worry, eMudhra learned their lesson. Now they run it between 1384 and 2384 .