The link provided by Eugene should respond to both of your quests. This answer is a bit offtopic, but you are asking for solutions for people.
In the real world, you probably should rely more on Social Engineering or heuristics , and then on mathematics. I talk about real life:
I went to the apartment and I found out that my mobile phone is dead. You can now contact the person making the visit. I was about to return when I saw that the door had a 0 - 9 keyboard and AB . I made a few assumptions:
- The code is 5 digits long. The length is pretty standard depending on the region in which you are located. I based this assumption on the buildings that I had access to (legally: D).
- The code starts with numbers, then
A or B (based on my own building). - The keyboard was not new. Conclusion The numbers used in the code were slightly damaged. I knew with certainty which numbers were not in the code, and three of the four numbers in the code (given my previous assumptions)
- By the number of damaged keys, I assumed that the code does not contain duplicate keys (7 were damaged, it was clear that
A used, B not used)
In the end, I had 3 numbers that were in the code for sure, 2 candidates for the last number, and I was sure that A was at the end. The key was slightly damaged compared to others.
I just needed to list the permutations, starting with a candidate who seemed more damaged, giving me 4! + 4! = 48 4! + 4! = 48 4! + 4! = 48 attempts. Believe me, on the 5th attempt, the door was open. If I can give my 2 cents, the old put a key and open the door is still the most reliable method of restricting access to the building.
source share