# Is my pin algorithm secure?

I'm a hobby programmer and very new to this field. I opened a bank account recently and got two pins. One for the girocard and the other for a creditcard. And I needed two more pins for the online banking account, that I could choose by myself. Just for fun I tried to come up with an algorithm, that generates each pin for me, so that I don't need to remember all.

Let's say the two predefined pins are:

1. 2812
2. 7791

The other two pins will be generated shortly.

The algorithm I came up with is the following and it operates on each digit seperately.

(x + n(k + n)) mod 10 = d

where d is one digit of the n-th pin.

Using simple arithmetic I got the following lists:

x = [9, 1, 5, 5]

k = [2, 6, 5, 6]

k is the secret key I memorize.

If I want to get the second pin for example I set n = 2 and use the first k with the first x to get the first digit of my second pin.

the other two pins my algorithm generates with n = 3 and n = 4 are

1. 4893

2. 3115

With this method I can generate up to 10 pins and need to remember only one key. I don't have any knowledge of cryptography and this is just my amateurish attempt. I'm not even sure if this has something to do with cryptography but I hope this is the write place to ask.

Is there some mysterious way someone could decrypt those pins just knowing of the algorithm and the list x?

## 1 Answer

Assuming that someone discovers your encrypted PINs, knows about your algorithm, but does not know $n$ or $k$, then it is more secure than if they discovered the plain PINs. As you normally only get a few attempts at guessing a PIN

However, there are some features of your algorithm that make it less than perfectly secure.

If you replaced the expression $n(k+n)$ with just $k$, and memorised a different four digits for $k$ for each PIN to encode, then what you would have is a one time pad. This is perfectly secure, but you have gained very little - you may as well remember the PINs. It might be relevant though if you needed to send a new PIN to someone else in future, but could only communicate privately and securely beforehand. So you could agree a value of $k$ in private then send the encrypted PIN safe in the knowledge that to an observer not knowing $k$, the real value of the PIN could be anything.

The security of re-using your value of $k$ depends on the behaviour of $n(k+n)$ mod $10$ with different $n$. Immediately we can see a problem - when $n$ is $0$, the output is the original PIN. Therefore using $n=0$ is out. Other values of $n$ have a more subtle problem - several of them do not cover all possible variations, $n=5$ for instance only gives 16 variations of $n(k+n)$ mod $10$ for a 4-digit PIN, so if an attacker knew or guessed $n=5$ they would have a good chance of guessing the original PIN without needing to know $k$. The "bad" values of $n$ for you are anything which shares a common factor with $10$. The "good" values are therefore $[1,3,7,9]$

So your algorithm can in theory protect four PINs reasonably well? Sort of, there is one more problem. The algorithm is easily reversible, therefore if somehow an attacker learned one of your PINs, they would be able to figure out 4 potential values of $k$ and only need 12 guesses (different values of $n$ and $k$ that still work) to figure out the next PIN. Then only 2 for the third one, and immediately get the fourth.