Instructables

Step 5: Code

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.


 
Remove these adsRemove these ads by Signing Up
do you have a video of it in action? great instructable!
MusashiAharon (author)  allenrodgersjr5 years ago
Thanks! Unfortunately, I had to disassemble it because I left my dorm for winter break.  When I get back in about a a month, I plan to reassemble it and take a video. Reassembly will definitely be one of the first things I do - I think I'm going to need this thing several times when I forget my room key. Luckily, I designed all the modules so that it is quick and easy to put together - it took only about 10 minutes to disassemble, so I think I will be able to plug it back together just as easily.