Lately I've been experimenting with a magnetic stripe card reader. In summary, I bought the cheapest one I could find on Amazon, opened it up, soldered some wires to it, added some electronic components, plugged it to my computer's microphone socket and recorded things like this: the raw signal read from a magnetic stripe. In this post I'll explain how magnetic stripe cards work and how to decode them.
Magnetic stripe cards were invented by Forrest Parry in 1969, which was quite the prolific year for giant leaps for humankind. The first company to develop and produce those cards was IBM, which chose to leave the basic ideas "open" for the rest of the industry to develop their own card systems. Some time later, the banking and airline industries met up and defined a set of standards so that all magnetic stripe cards would have the same size, their magnetic stripes in the same position, use the same encodings, etc.
The magnetic stripe is the usually dark-colored strip that appears in the back of the card. The data in the card are recorded in the magnetic stripe, but before I can talk about how those data are stored, I need to talk about magnets.
Illustration of the magnetic fields for several magnets.
Imagine you have a magnet in the shape of a straight rod. One end of the rod is the magnet's "North pole" and the other end is the "South pole". The magnet produces a magnetic field, which is represented using "force lines" which go out of one pole into the other pole. Where the force lines are denser, the magnetic field is more intense. Almost all force lines go out or in through one of the poles, so that's where the magnetic field has its highest intensity. This means that if you take a lump of iron and you move it close to a magnet, it will be attracted with more force towards a pole than towards, say, the center of the rod, where the force lines are more separated.
If you take two magnets and try to join them end to end, two things may happen. The first possibility is that you are trying to join a magnet's North pole with the other magnet's South pole. In this case, both magnets' force lines will combine and, when the two magnets touch, they'll behave as if they were a single magnet that's twice as long: the two poles that touch disappear, and only the two free poles remain, where the combined magnet's force lines go out and in. If, on the other hand, you were trying to join the same pole in both magnets, the two magnets will start to repel each other, the force lines will squish together between the magnets because they will not cross, and the intensity of the magnetic field between the magnets will increase. As the magnets come closer, the repulsion force increases and with it the intensity of the magnetic field.
A magnetic stripe is made up of many magnetic particles which behave like tiny magnets. Imagine that all those particles are oriented with the North pole to their right. In this case, the magnetic stripe would behave like a single magnet with its North pole to the right and its South pole to the left, with its most intense magnetic field on each end of the stripe. However, it's possible to use a permanent magnet or an electromagnet to reverse the orientation of some particles. In this case, there will be an intense magnetic field in the regions that separate the particles with different orientations. A "write head", which is an electromagnet, can set the orientation of the particles located underneath.
If the write head is moved from one side to the other as it induces one or other orientation, the magnetic stripe ends up looking like a series of magnets that are joined pole-to-same-pole. The magnetic field in this magnetic stripe will have intensity peaks where the same poles of two magnetic domains meet. Those intensity peaks can be detected using a "read head", which is a device that produces a small electric current when it's exposed to a magnetic field with changing intensity. By swiping this read head on the magnetic stripe, the differing intensity in different spots of the magnetic stripe causes electric current pulses to be produced: in one direction if it's two North poles that meet, or in the opposite direction if it's two South poles.
In summary, the write head produces polarity reversals and the read head produces an electric pulse every time it detects such a reversal. If a particular pattern of polarity reversals is recorded, the read head will afterwards produce an analogous pattern of electric pulses. That's how you can record binary data (zeros and ones) in a magnetic stripe and read it afterwards. The system works like spirit communication in a séance: one pulse means "zero" and two pulses mean "one".