Well, as my first theme I want to tell you about the Peruvian National Identity Card, named DNI. The Peruvian DNI is given to all the peruvian nationals at the age of 18 and from some years ago is also given to all new born. To his parents, I mean.

As you guess the Peruvian DNI has a number, an 8-digit number that you have to remember for the rest of your life. But if you look carefully, following the 8-digit number there´s a number or a letter, the validation character.

I was googling for some time searching for the algorithm to calculate the validation character of the Peruvian DNI without success, so I decided to deduce it. My approach was this:

"Consider a 9 characters length string where the last of this characters is calculated from first eight ones by an unknown algorithm you have to deduce the algorithm from a set of examples."

The set of examples can be obtained from a public service here.

I treated this problem like an encryption challenge, my first guess was that the algorithm is a modified form of modulus 11, and I was right. Then, with a set of 40 strings was easy to deduce the coeficients and the variations to the original modulus 11 algorithm.

In my next post I'll show you the algoritm in C++.