Magstripe Magic!

Have you ever wondered what exactly is on those magnetic stripes? This article includes some useful information on how the stripes are encoded, examples of how they can be read and, if you’re willing to make the effort, enough information to reconstruct a do-it-yourself card reader!

I’m sure you’ve heard the stories. You know how they go... “Hotels are storing your credit card number on the hotel room key!!!” Now, I’m not saying that that might not be happening somewhere in the world, but generally speaking, it’s just not true. Even so, you might wonder what is on those magical magnetic stripes?

Many different items today have magnetic stripes. While there are probably non-standard items out there (there always are), the standard for magnetic stripe data indicates that the data will be stored on one or more of three distinct stripes. The stripes are distinguished primarily based on their placement on the stripe. There are also some differences in how the data itself is recorded (how many bits per character, what the character set is, etc.).

At one point, we were producing a prototype for future miniaturization that would allow Law Enforcement to quickly and easily identify magnetic card data stored on any stripe that actually contained credit card data. In the end, the project was supplanted by a rather expensive ($1,000) Pocket PC with a magstripe reader. We were disappointed since our solution cost only about $35 in parts. In any event, rather than let that work go to waste, we thought we’d share it with you.

The heart of our project is a PIC 16F819 processor. We did not select this out of any preference or because it’s really awesome at reading card data; it just happened to be what we had handy in enough numbers that if we fried a few it wouldn’t matter much.

The other major piece of hardware that is required in order to read a magnetic stripe is some sort of magnetic stripe head. While you can make your own (we sure don’t advise that) and there are lots on the market, we found that the Magtek 21047019 mini magnetic head assembly was perfect for our application. The especially nice part about using this part is that you don’t have to write code to figure out when the card has been inserted and where the stripe began (or which way the card was going). All of this is taken care of through an embedded processor and buffer which reads the stripes. Once the card has been swiped, you simply (we use that word loosely) need to read the data out of the buffer and interpret it! The other advantage to this particular part is that it runs at 5 volts DC rather than 3.5 volts, which is pretty common for a card read head. This simplifies the circuit design since (at least for us) since all of the PIC parts we had handy are 5 volts.

The one thing that we are not “releasing” is our actual circuit design. The design is extremely simple and, if you’re patient, you can probably reconstruct it from the image or the source code below, but we felt that there should be some hurdle for people who might want to take this and turn it into a card skimmer for nefarious purposes. Even so, we are releasing all of the source code for driving the card reader. In tomorrow’s blog post we’ll also release and detail the code for the LCD driver in case you have a Hitachi based LCD that you’re trying to drive from a PIC.

Card Reader.c
Card Reader.h