Lockbox PIN Code Generator
by Victor
Months ago, an associate was commenting on the oddities of a physical key lockbox. I'm sure you're familiar with the type of lockbox typically used by realtors which are intended to securely store a house key; opened with a PIN code or dial combination lock. So my associate's "uncle" had "forgotten" the combination or acquired one of these things and was trying to brute-force the box.
The lock box in question was of the push-button variety, opening with a numeric PIN. While the PIN length can vary, he knew that the PIN on his lockbox was four digits long. Trying up to 10,000 PINs sounds like quite a boring task, right? But wait, there's more. The lockbox in question was made by Supra and, after some querying, he learned there were deficiencies in the design of this lockbox that significantly reduced the number of unique PINs. The PIN couldn't repeat any numbers and the order in which the PIN was entered didn't matter (e.g., 1234 was the same as 4321)!
My associate started searching, but couldn't find a ready-made list of PINs. His initial attempts at generating a list weren't quite right and I was drawn into the idea of solving this with some Python.
I'll give you the executive summary and you can jump straight to the code. We're generating the PINs as a string, so it can be padded with leading zeroes to the necessary length. Converting the PIN to a list allows us to sort. Sorting the PIN's characters is what addresses the fact that the order in which a PIN is entered does not matter. There's also a check to eliminate PINs which use any digit more than once.
The check to eliminate PINs using any digit more than once might look strange to those less familiar with Python syntax:
This is really a one-liner for creating a list. See "List Comprehension" in the Python docs. It iterates the characters in the PIN and returns a list containing only characters that exist more than once in the PIN. Python's if evaluates to true only when the returned list contains something.
It was reported to me that the resulting list of PINs and a six-pack later, his uncle was triumphant! I suspect the Supra lockbox model in question was mechanical in nature (as opposed to having some electronic guts), which led to these strange properties. The number of viable PINs was shockingly low, as you can see below. What I hadn't thought of is that because PIN order doesn't matter, a five-digit PIN is the most secure - more or less digits reduces security. Remember that when brute-forcing, you're likely to hit on the winner halfway through the key space, so halve those numbers below to get a better idea of just how few tries it's likely to take.
It might be worth taking a minute to tinker and search for vulnerabilities with any lockbox you plan to use. I suspect those industrious fellows in the Lockpick Village are having a chuckle at this... I'm certain there are more egregious physical flaws in these types of products.
This is a fine start for PIN-generating needs which I've reused a couple of times already. Happy hacking and I'd like to give a nod to $@LV@TiON for bringing this puzzle to my attention.
Code: lockbox.py