3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Cryptap: A rhythm-based door lock

Step 5Code

Code
«
  • 1217092028-01.jpg
  • 1217092028-00.jpg
I've tried to comment my code. Keep in mind that this is 1.0 software, meaning that it is not bug-free.

## OPERATION ##

1. Press the start/stop button to signal that you are ready to begin code input. The status light begins to flash slowly.
2. Tap in your code on the code button. The status light will blink at 120 BPM, so you can use this as your metronome if you want. However, the cryptap program will measure the pulse lengths relative to each other proportionally, so you could also use your own tempo. Just make sure you that are accurate enough!
3. When the code input is done, press the start/stop button again. The program will then decide whether to let you in.

Since humans are not very accurate time keepers (yours truly is not), I set the tolerance ratio to +/- 30%. That means that the beat lengths can be inaccurate by that amount, and still pass muster.  This is good enough to tell the difference between pretty similar tunes. There is a small amount of hard-to-reach overlap between double and triple-length beats, but the code is still pretty hard to break.

To unlock the door, the beats must be in the correct proportions to each other (+/- the tolerance ratio), and the number of beats must be correct. If an invalid password is entered, the program waits for a few seconds while ignoring any user input. It will also flash the status light quickly.  If the correct code is entered, the status light will turn on steadily and the door will unlock for 8 seconds.

## USER CONFIGURATION ##

The key is stored in an array like this:
#define keylength 5
const int key = { 2, 1, 3, 3, 3 }; // "Happy birthday to you"

The array stores the amount of time that happens BETWEEN the beats. So if your password has SIX notes like "Happy birthday to you", there should be FIVE elements in the array. If your password is really long and you have more than 16 beats in it, (really hard, I don't recommend it), you must increase the number defined in this line:
#define inputCodeLength 16

## THE REST OF THE CODE ##

I was curious about interrupts, so I had my buttons trigger interrupts.  To make these interrupts easy to use, I had my interrupt handlers check for certain function pointers. If the pointer is not set to NULL, the function it points to is invoked.  These are set with the various "mode-setting" functions inside cryptap.c.

I made an effort to avoid buffer overflows by setting a maximum number of inputted pulses. If the maximum number of pulses are input, the program immediately starts password analysis and decides whether to unlock the door.

I hope my comments in the code help.

## BUGS ##

I tried to remove the USB debugging code, but the code won't work if I do. So, I left in usb_init() and the various print() statements. I would appreciate it if someone could remove them and still have the program work. Even better if they can explain why it didn't work for me.

Immediately after being programmed, the Teensy sometimes doesn't accept code input.  To solve this, power-cycle the circuit.


« Previous StepDownload PDFView All StepsNext Step »
2 comments
Dec 19, 2009. 1:53 AMallenrodgersjr says:
do you have a video of it in action? great instructable!

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
0
Followers
1
Author:MusashiAharon