News for hackers. Stuff that matters.
Re:How random are TOTP codes? by SoftTalker on Friday July 05, 2024 @12:17AM (#40879800)
We like to see patterns. I think the same thing with TOTP codes, I'm always noticing when they have repeated digits, or only 2 different digits, stuff like that, but that's just the nature of the human brain looking at random numbers.
Re:How random are TOTP codes? by GrantMoyer on Friday July 05, 2024 @01:52AM (#40880116)
Me too. I was particularly pleased when I got 332211 as my TOTP once.
Re:How random are TOTP codes? by BrightOne on Friday July 05, 2024 @03:57PM (#40885510)
I remember getting a GABEN code from Steam 2FA. Was 100% sure it was not random
Re:How random are TOTP codes? by Fr0styMatt88 on Friday July 05, 2024 @02:36AM (#40880278)
For me it’s “I swear I feel like I’ve gotten the exact same TOTP code not that long ago!”.

What’s the actual likelihood of seeing the same TOTP code from different apps at different times?

What about those ones that get sent out in phone messages?

Re:How random are TOTP codes? by masklinn on Friday July 05, 2024 @03:03AM (#40880390)
> What’s the actual likelihood of seeing the same TOTP code from different apps at different times?

There’s only a million 6 digit TOTP codes, so I reckon you get to 50% odds of collision at ~1200 values.

Re:How random are TOTP codes? by yulle on Friday July 05, 2024 @03:48AM (#40880601)
For those curious on how to find that ~1200 values are needed before a 50% probability of collision, this is a generalized form of the birthday problem [0].

With a calculator [1], we can find the exact amount. plugging in D=10^6 (# of unique codes) with P=0.5 (odds of collision) gives you 1178 values.

[0] https://en.wikipedia.org/wiki/Birthday_problem

[1] https://www.bdayprob.com/

Re:How random are TOTP codes? by codeflo on Friday July 05, 2024 @03:58AM (#40880664)
The very rough rule of thumb that I think one should remember is: You get a 50% chance of collision with sqrt(total) samples.

Sqrt(1 000 000) = 1 000, close enough to the exact number you calculated.

Re:How random are TOTP codes? by ColinWright on Friday July 05, 2024 @05:52PM (#40886368)
More accurately, for 50% it's \sqrt(\ln(4))\sqrt(N) which is \sqrt( ln(4) N ).

That's about 1.17741 times \sqrt(N).

The reasons are explained here: https://news.ycombinator.com/item?id=40886363

Re:How random are TOTP codes? by dickfickling on Friday July 05, 2024 @10:57AM (#40883357)
I have long considered building a code generator that only serves "nice" codes.

The standard implementation would use a hard coded set of patterns. The enhanced version would pair automatic random code generation with a public site where members of the public can decide in real time whether a given code is "nice" before it's sent along to the intended recipient.

(note @tptacek if you're reading this, I swear it's (mostly) a joke)

Re:How random are TOTP codes? by whalesalad on Friday July 05, 2024 @12:38PM (#40884149)
I've always been under the impression that popular TOTP implementations were specifically designed to produce "nice" codes. They always have repeated digits, like 202838.
Re:How random are TOTP codes? by wavemode on Friday July 05, 2024 @03:51PM (#40885467)
I think that's just the birthday paradox. It's highly likely for a randomly generated number to have some repeated digits.
Re:How random are TOTP codes? by cozzyd on Friday July 05, 2024 @03:29PM (#40885332)
Hmm for 2 digits you only have one "nice" code (69). For three digits it's the same (069). For four digits you do get two (0069 and 6969), but I think you need a lot of digits before "nice" codes are effective.