Physical Keygen: Duplicating House Keys on a 3D Printer

3D Printed House Key

It occurred to me recently that I had printed almost nothing actually useful on my RepRap 3D printer, aside from parts to improve on or build more RepRaps.  I am rectifying that with this project.  The goal here is to generate working house keys by inputing the key code of the lock into a parametric OpenSCAD model.  Instead of having to explain to my landlord how I ended up with a wedge of plastic jammed in my front door, I ordered a box of (well) used locks and latches from eBay to experiment on.  Luckily, the lot includes both Kwikset KW1 and Schlage SC1 locks, which are the two most commonly found in the US.  I created an SC1 model to start with, but I’ll probably make a KW1 soon.  I’ve uploaded the KW1 model now as well.

Key in Lock

Designing the key model was actually pretty straightforward.  I measured a key with a ruler and calipers and created an approximate model of it that is reasonably easy to print.  I then got pin depth specifications and parametrically differenced them out of the model.  To generate new keys, you can just edit the last line of the file and enter in the key code for your key.  If the code isn’t written on the key, you can measure the height of each bit and compare to the numbers in the Root Depth column on the aforementioned pin depth site.  Perhaps more nefariously, you could implement something like SNEAKEY to generate key codes without physically measuring the key.

You’ll of course need OpenSCAD to edit the .scad file and generate an STL to print out, unless your key just happens to be 33172 like the example STL posted below.  If it is, you can unlock the doorknob currently sitting on my desk.  As a small, precise object, this is a great test of how accurate your Skeinforge settings are.  You may need to adjust some thicknesses or the built in pin depth fudge factor to get it working properly with your printer.  The pictures above show the key being used on a disconnected lock cylinder, but I found it was also strong enough to turn a deadbolt.  If your lock needs a lot of force to turn, you may need to cut a space into the key to use a torsion wrench with it.


Speeding Up Skeinforge with PyPy

PyPy 1.5 vs CPython 2.6.6 for Skeinforge

Now that I’ve recovered from Maker Faire, I can continue documenting what I did.  In the lead up to the event, I tried to streamline the FaceCube project as much as possible so visitors wouldn’t have to waste precious Faire time waiting for a print to start.  On the hardware side, I kept the extruder and heated bed warmed up to operating temperature and (literally) hot swapped 4″x4″ pieces of glass so that prints could run back to back.  I updated the FaceCube script to do capture, cleaning, meshing, scaling, and running through OpenSCAD with a single button press.  The remaining bottleneck was running Skeinforge on my geriatric in computer years laptop.  Skeinforge is an amazing utility, but written in Python, it is slower than a drunk sloth.

There are ways of speeding up drunk sloths though.  Psyco is commonly recommended, but does not support 64 bit architectures.  My roommate Will came up with a plan to run a Skeinforge server on PyPy on a faster computer and have a client on my laptop send STLs to it for skeining.  We ran out of time on that, but we did get PyPy running normal Skeinforge on my laptop.  As of PyPy 1.5, there is support for Tkinter.  Following those instructions to install PyPy and Tkinter and run Skeinforge on 64 bit Linux:

tar -xjvf pypy-1.5-linux64.tar.bz2
cd pypy-c-jit-43780-b590cf6de419-linux64
./bin/easy_install tkinter-pypy
./bin/pypy ~/path_to_skeinforge/

The fonts may look slightly different, but the application should behave the same.  Export times should decrease the first couple of times you put a file through as the JIT compiler optimizes and then stay good as long as you keep the process running.  On my laptop with a 2.00 GHz Core 2 Duo, Skeinforge runs 2 to 3 times faster on PyPy than on stock CPython 2.6.6. The tested objects were a Weighted Storage Cube, a Flower, Whistle v2, and the Prusa Mendel vertex.