How to build a magstripe reader from scratch
You will need a magnetic head which are very common I recommend a magnetic head from an old tape deck. It is important to be careful not to damage the head when removing it. The magnetic heads are usually secured with two screws. (Note: Do not discard the screws we will need them latter for mounting the head) You will also need a 3.5 mm mono phone plug (with a 2-conductor wire) you can easily find one of these on an old monaural earphone or in an electronics store. You will also need a soldering iron and some solder.
Optional but recommended
Wood or other sturdy material to mount the head on
(Hint: I used the back of the tape deck)
Ruler to slide cards across (This ones up to you)
Construction
The actual hardware design is incredibly simple. The interface consists of simply connecting the output of the magnetic head directly to the mic input of a sound card. Solder the wire connecting the 3.5mm mono phone plug (base and tip) to the leads of the magnetic stripe head. Polarity does not matter.
I recommend that you mount the head in a way that makes it easy to swipe a card over it with a constant velocity. This is where your custom hardware ingenuity comes in. Mount a ruler (or other straight edge) perpendicular to the magnetic head, with the reading solenoid (usually visible as a black rectangle on the head) at the correct distance from the base for the corresponding track. Track 1 starts at 0.223″ from the bottom of the card, Track 2 starts at 0.333″, and Track 3 starts at 0.443″.
Alternatively, you can purchase a surplus reader with no interface (i.e., scrapped or with a cheap TTL interface) and follow the same instructions with the exception that the magnetic head will already be mounted. Most surplus readers come preset to Track 2, although it is usually a simple hardware mod to move it to the track you’d like to read. This will save you the trouble of building a custom swiping mechanism and will also improve the reliability of the reads. There are surplus readers that can be purchased for less than $10 US at various online merchants.
Software
In this project, the software does all the heavy lifting. The “dab” utility included in this article takes the raw DSP data from your sound card, decodes the FSK (frequency shift keying - a.k.a. Atkin Biphase) modulation from the magnetic stripe, and outputs the binary data. Additionally, you can decode the binary data using the “dmsb” utility to output the ASCII characters and perform an LRC check to verify the integrity of the data, provided that the stripe conforms to the specifications described in ISO 7811, 7813, and optionally ISO 4909 (for the uncommon Track 3). Becoming familiar with these specifications will help you understand the contents of the magnetic stripe when viewing the decoded data.
The provided software is more proof-of-concept than production code, and should be treated as such. That said, it does its job well. It is open source and released under the MIT license. Feel free to contribute.
Requirements
- Linux (or the desire to port to another operating system)
- A configured 16-bit sound card
- Access to the /dev/dsp device
- libsndfile
Note that “dab” can also take input from any audio file supported by libsndfile. However, it must be a clean sample that starts at the beginning of the file. This is useful to eliminate the requirement of a sound card and allow samples to be recorded from another device (e.g., an MP3 player/recorder) and decoded at another time.
Download
dab.c (v0.7)- Decode Atkin Biphase
dmsb.c (v0.1)- Decode (standard) Magnetic Stripe Binary
Compiling
Edit any configuration #defines near the top of the dab.c file and proceed to compile the source with the following commands:
cc dab.c -o dab -lsndfile
cc dmsb.c -o dmsb
Usage
Usage: dab [OPTIONS]
-a, –auto-thres Set auto-thres percentage
(default: 30)
-d, –device Device to read audio data from
(default: /dev/dsp)
-f, –file File to read audio data from
(use instead of -d)
-h, –help Print help information
-m, –max-level Shows the maximum level
(use to determine threshold)
-s, –silent No verbose messages
-t, –threshold Set silence threshold
(default: automatic detect)
-v, –version Print version information
Usage: dmsb [OPTIONS]
-V, –verbose Verbose messages
-h, –help Print help information
-v, –version Print version information
dmsb will wait on stdin for raw magnetic stripe data (string of 0s and 1s
followed by a newline) and print the decoded data to stdout.
Be sure that the mic is set as the recording device for your sound card (using a utility such as aumix or your preferred mixer). Standard usage on the command line with the hardware interfaced directly to the sound card (mic in) will be as follows with standard cards:
./dab | ./dmsb
My original reader. With this reader I would use a ruler as a track guide. This way I could not only read the three standard tracks, but also data on non-standard cards, some of which have tracks in odd positions such as through the middle of the card.


Examples
Below are some examples of a few (hopefully) less common cards as to get an idea of the sort of data you’re likely to find.
Park Inn (Berlin-Alexanderplatz) Door Key Cards
Room: 2006
Checkout Date: 12/30/2004
Card 1
Track 2 Data: ;5101152006010912130124000120000000000?
Card 2
Track 2 Data: ;5101152006020912130124000120000000000?
Room: 2005
Checkout Date: 12/30/2004
Card 1
Track 2 Data: ;5101152005010160230124000120000000000?
Card 2
Track 2 Data: ;5101152005020160230124000120000000000?
SEPTA Monthly TransPass Cards
Month: November 2004
Serial: 001467
Track 2 Data: ;010100110104113004000001467?
Month: June 2003
Serial: 002421
Track 2 Data: ;010100060103063003000002421?
Month: January 2002
Serial: 028813
Track 2 Data: ;010100010102013102000028813?
Sony Connect Cash Cards
Card Number: 603571 010462 1134569
PIN: 9014
Track 1 Data: %B6035710104621134569^^49120000040?
Track 2 Data: ;6035710104621134569=49120000040?
Card Number: 603571 010462 1132282
PIN: 5969
Track 1 Data: %B6035710104621132282^^49120008147?
Track 2 Data: ;6035710104621132282=49120008147?
Starbucks Cards
Card Number: 6015 0613 2715 8426
Track 1 Data: %B6010565061327158^0040/MOMSDAY04^25010004000060018426 ?
Track 2 Data: ;6010565061327158=25010004000060018426?
Card Number: 6014 5421 5637 9529
Track 1 Data: %B6010564542156377^0027/EXCLUSIVEB2B04^25010004000060019529 ?
Track 2 Data: ;6010564542156377=25010004000060019529?
Card Number: 6014 5421 6302 5757
Track 1 Data: %B6010564542156377^0027/EXCLUSIVEB2B04^25010004000060019529 ?
Track 2 Data: ;6010564542163027=25010004000060015757?
I hope this will inspire more people to look and see what they are carrying around in their wallets. You might be surprised.