Pocket maths: your verification code is 446267


< change language

It has become quite common for online services to provide some form of 2-factor authentication when logging in from unknown devices. For example, whenever I try to access my Gmail account from a computer I never used, I get a text message with a one-time use 6-digit code.

One day I was using that same service to log in into my email, when I noticed that one of the digits in the security code appeared twice, like the $1$ in $315641$. But when I read the other text messages from Google, I noticed that there were plenty more security codes with repeated digits than security codes that had six different digits. I found that weird and then decided to compute the probabilities of these events, just to check whether my intuition was tricking me or not...

We are about to compute some probabilities regarding these $6$-digit codes - which I will start calling PINs for the sake of brevity - with the rather intuitive formula $$P(\text{some property}\ A) = \frac{\text{# PINs that satisfy property}}{\text{# of existing PINs}}$$ It is easy to see that there are a total of $10^6$ valid PINs, so for the different properties we only need to compute the total number of PINs that satisfy it.

Below you can find a table with some properties listed and the probability that the next PIN you will receive on your cellphone satisfies that probability.
(if you find any mistake on the calculations, suspect one of the numbers is wrong or want to know how I computed a specific probability, leave a comment below!)

Property Probability (up to $2$ decimal places)
$6$ unique digits (e.g. 123456) $15.12\%$
$5$ or less unique digits (e.g. 525678) $84.88\%$
$5$ unique digits, repeated digit is consecutive (e.g. 551234) $18.14\%$
$5$ unique digits, no restrictions on repeated digit (e.g. 024328) $45.36 \%$
$4$ or less unique digits (e.g. 235293) $39.52 \%$
$4$ unique digits, repeated ones are together (e.g. 226997) $3.02 \%$
$3$ or less unique digits (e.g. 123231) $6.76 \%$
$2$ or less unique digits (e.g. 111331) $0.28 \%$

After all, having a 6-digit code with a repeated digit is much more common than having a 6-digit code where every digit is different!!
Nos dias que correm já é comum os serviços online oferecerem alguma forma de autenticação a dois passos para proteger as nossas contas. Por exemplo, sempre que tento aceder à minha conta Google a partir de um computador que nunca usei, recebo um sms com um código único de 6 dígitos.

Numa das vezes em que usei esse serviço, reparei que o meu código tinha um dígito repetido, tal como o $1$ em $315641$. Quando olhei para os códigos que já tinha usado em vezes anteriores, reparei que na verdade isso acontecia bastantes mais vezes do que eu estaria à espera. Isto pareceu-me estranho e portanto decidi calcular as probabilidades desses eventos, verificando assim se a minha intuição me estava a pregar partidas ou não...

Vou mostrar uma tabela com probabilidades de várias propriedades destes códigos de $6$ dígitos - a que vou chamar PINs por comodidade minha - com a fórmula intuitiva usual: $$P(\text{some property}\ A) = \frac{\text{# PINs that satisfy property}}{\text{# of existing PINs}}$$ É fácil de ver que há um total de $10^6$ PINs válidos, portanto para cada propriedade que eu escolha só vou ter de calcular o número de PINs que a satisfazem.

A tabela que se segue contém algumas propriedades com as respetivas probabilidades: o próximo PIN que eu receber no meu telemóvel vai satisfazer a propriedade descrita com uma probabilidade igual à indicada.
(se encontrarem erros, se acharem que algum dos números está mal ou se quiserem saber como calculei alguma probabilidade específica, deixem um comentário!)

Property Probability (up to $2$ decimal places)
$6$ dígitos únicos (e.g. 123456) $15.12\%$
$5$ ou menos dígitos únicos (e.g. 525678) $84.88\%$
$5$ dígitos únicos, os repetidos estão juntos (e.g. 551234) $18.14\%$
$5$ dígitos únicos sem restrições no dígito repetido (e.g. 024328) $45.36 \%$
$4$ ou menos dígitos únicos (e.g. 235293) $39.52 \%$
$4$ dígitos únicos, os repetidos estão juntos (e.g. 226997) $3.02 \%$
$3$ ou menos dígitos únicos (e.g. 123231) $6.76 \%$
$2$ ou menos dígitos únicos (e.g. 111331) $0.28 \%$

Afinal de contas é muito mais comum aparecer um código com um dígito repetido do que um código onde todos os dígitos são diferentes!!

  - RGS

Popular posts from this blog

Tutorial on programming a memory card game

Markov Decision Processes 01: the basics

The hairy ball theorem and why there is no wind (somewhere) on Earth