What's under the hood of a dynamic magnetic strip?

Introductory


Time does not stand still - it flows and changes. Technological progress dictates its own rules of life. One of these rules is the presence of the most important tool of everyday life - a plastic card. Credit, settlement, deposit, business card, club, loyalty cards - now no civilized society can do without them. But what if there are too many of these “universally recognized tools of human life”? What if from their excess your favorite wallet begins to burst at the seams? Today we will talk about how this problem can be avoided. Namely, how to turn a few cards ... into one.

Bit of theory


How is information stored? Yes, very simple. In fact, a magnetic strip is a sequence of small sections magnetized in opposite directions. At the transition between sections, the magnetic field changes sharply. It is this change in the magnetic field that the magnetic head captures, which slides along the strip when you hold the card. Due to a sharp change in the magnetic field in the head coil, an EMF (electromotive force) occurs, in other words, a voltage pulse appears, which is then amplified and transmitted further.

To distinguish between zeros and ones, the so-called F / 2F coding is used: that is, when coding zero, the frequency F is used, and for the unit, the frequency 2F is used. For example, at the beginning of the track, we have several zeros that serve for synchronization, then the decoding device approximately calculates the frequency F (in particular, the time of one half-cycle equal to T), and if the pulse occurred after the time T, then we are dealing with zero, if in the middle of this time and at the end (doubled frequency), then this is a logical unit.

image

This method is based on the principle that we will not be able to instantly change the wire speed by a card 1.5 times. Due to the fact that we have a pulse at the end of each bit, we can adjust the time T without fear of a smooth change in speed. Otherwise, it will cause synchronization to fail.

Each magnetic stripe card always has 3 tracks. Another thing is that they are not always used.
1st trackALPHA format79 characters7 bits per character210 bps
2nd trackBCD format40 characters5 bits per characterrecording density 75 bits per inch
3rd trackBCD format107 characters5 bits per character210 bps

In the case of discount cards, only the second track is most often used, due to the fact that it has the lowest recording density, and, as a result, the greatest resistance to interference in the form of adhering substances, scratches or even cracks. Usually there is written the numerical identifier of the card carrier, it is just in case duplicated on the front of the card itself.

In the case of bank cards, the first and second tracks are used. The meaning of the data is known only to the banks themselves.
The third track in the vast majority of cases is not used.
The physical width of the information track is 2.8 mm.

BCD format
b1 b2 b3 b4 b5 Character Function
0 0 0 0 one 0 (0H) Data
one 0 0 0 0 one (1H) "
0 one 0 0 0 2 (2H) "
one one 0 0 one 3 (3H) "
0 0 one 0 0 4 (4H) "
one 0 one 0 one 5 (5H) "
0 one one 0 one 6 (6H) "
one one one 0 0 7 (7H) "
0 0 0 one 0 8 (8H) "
one 0 0 one one nine (9H) "
0 one 0 one one: (AH) Control
one one 0 one 0; (Bh) Start sentinel
0 0 one one one < (CH) Control
one 0 one one 0 = (DH) Field separator
0 one one one 0 > (Eh) Control
one one one one one? (Fh) End sentinel


The 5th bit acts as a parity bit.

In the alpha encoding format (where there are 7 bits per character), it is possible to store numbers, Latin letters and a few special characters.

alpha encoding format
b1b2b3b4b5 b6b7Character Function
000000one space (0H) Special
one000000! (1H) "
0one00000 " (2H) "
oneone0000one # (3H) "
00one0000 $ (4H) "
one0one000one % (5H) Start sentinel
0oneone000one& (6H) Special
oneoneone0000'' (7H) "
000one000( (8H) "
one00one00one) (9H) "
0one0one00one * (AH) "
oneone0one000+ (Bh) "
00oneone00one, (CH) "
one0oneone000- (DH) "
0oneoneone000. (Eh) "
oneoneoneone00one / (Fh) "
0000one000 (10H) Data (numeric)
one000one0one one (11H) "
0one00one0one 2 (12H) "
oneone00one003 (13H) "
00one0one0one 4 (14H) "
one0one0one00 5 (15H) "
0oneone0one00 6 (16H) "
oneoneone0one0one 7 (17H) "
000oneone0one8 (18H) "
one00oneone00nine (19H) "
0one0oneone00: (1AH) Special
oneone0oneone0one; (1BH) "
00oneoneone00 < (1CH) "
one0oneoneone0one = (1DH) "
0oneoneoneone0one > (1EH) "
oneoneoneoneone00? (1FH) End sentinel
00000one0 @ (20H) Special
one0000oneone A (21H) Data (alpha)
0one000oneone B (22H) "
oneone000one0 C (23H) "
00one00oneone D (24H) "
one0one00one0 E (25H) "
0oneone00one0 F (26H) "
oneoneone00oneoneG (27H) "
000one0oneone H (28H) "
one00one0one0 I (29H) "
0one0one0one0 J (2AH) "
oneone0one0oneone K (2BH) "
00oneone0one0 L (2CH) "
one0oneone0oneoneM (2dh) "
0oneoneone0oneoneN (2EH) "
oneoneoneone0one0 O (2FH) "
0000oneoneoneP (30H) "
one000oneone0 Q (31H) "
0one00oneone0 R (32H) "
oneone00oneoneone S (33H) "
00one0oneone0 T (34H) "
one0one0oneoneone U (35H) "
0oneone0oneoneoneV (36H) "
oneoneone0oneone0 W (37H) "
000oneoneone0 X (38H) "
one00oneoneoneoneY (39H) "
0one0oneoneoneoneZ (3AH) "
oneone0oneoneone0 [ (3BH) Special
00oneoneoneoneone (3DH) Special
one0oneoneoneone0 ] (3EH) Special
0oneoneoneoneone0 ^ (3FH) Field separator
oneoneoneoneoneoneone _ (40H) Special


The 7th bit acts as a parity bit.

Information on the 2nd or 3rd track is stored in the following sequence:
  1. A certain number of zero bits, about 20;
  2. The character of the beginning of the data “;”;
  3. a number or several numbers separated by the symbol "=";
  4. sign of data end “?”;
  5. LRC (Longitudinal Redundancy Check) - to check the entire message;
  6. A certain number of zero bits, about 20;

The first track contains a similar sequence with the exception of the start symbol “%”.

To practice


In order to simulate the magnetic strip during the wire card, it is necessary to generate a change in the magnetic field near the read head. For this, a simple coil is suitable, to which a specially modulated signal will be supplied. In order for our card simulator to be stretched, it is necessary to place a reel throughout the entire card. It is also good that the direction of magnetization coincides with the direction on the card. Here we were lucky: it runs along the long edge of the card and a single-layer coil of about the length of the card will be enough. To enhance the magnetization, we will use a soft magnetic ferromagnet of electric steel (transformer core) as the core. The shape of the core is rectangular; flat to the read head,

image

In the process of winding a screwdriver will help us. It is also desirable to coat the core with varnish before this, in order to exclude the possibility of a short circuit of the turns through the core, otherwise the coil area in the spaces between the closed turns is not effective.

For ease of reading, we pack our coil in a “case” similar to the shape of a standard plastic card.

image

Tape with tape.

image

Now let's think about how we will send a signal to the coil. For this we need a driver. Since the output power of the GPIO ports of the controller is not enough for us, we will use an H-bridge type circuit.

image

We connect MS1 and MS2 to the controller ports, output P1 - to the coil.
Capacitors C43 and C44 serve as filters for removing the DC component from the coil. This allows you to save battery power, as well as control the steepness of the pulse edges, which in turn positively affects the magnetic interaction of the coil and the magnetic head (the magnitude of the EMF is directly proportional to the rate of change of the magnetic field).

Install a filter to save the rest of the circuit from power surges.

image

To generate pulses at the output of the head, we need to apply pulses in antiphase to the outputs of the coil. To do this, at the same time, we change the logical levels on MS1 ​​and MS2 to the opposite, so that doubled VMS voltage will be applied to the coil outputs for a short time. Another way is to use only one arm of the H-bridge on one side of the coil and a midpoint on the other.

image

The controller for controlling the circuit is taken with a reserve of computing power - STM32F405.

So, the code on the example of the second track:

//инициализация порта:
#define STRIPE_2_PIN_P GPIO_Pin_13
#define STRIPE_2_PIN_N GPIO_Pin_14
#define STRIPE_2_PORT GPIOB
#define STRIPE_2_RCC_PERIPH RCC_AHB1Periph_GPIOB
void stripe_init(void) {
    GPIO_InitTypeDef GPIO_InitStructure;
    RCC_AHB1PeriphClockCmd(STRIPE_2_RCC_PERIPH, ENABLE);
    GPIO_SetBits(STRIPE_2_PORT, STRIPE_2_PIN_P);
    GPIO_ResetBits(STRIPE_2_PORT, STRIPE_2_PIN_N);
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_Pin = STRIPE_2_PIN_P | STRIPE_2_PIN_N;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(STRIPE_2_PORT, &GPIO_InitStructure);
}
//генерация одного импульса:
void stripe_2_toggle(void) {
    GPIO_ToggleBits(STRIPE_2_PORT, STRIPE_2_PIN_P | STRIPE_2_PIN_N);
}
//передача логического нуля: 
void stripe_2_tx_0 (void) {
    stripe_2_toggle();
    vait_stripe_2_period();
}
//передача логической единицы:
void stripe_2_tx_1 (void) {
    stripe_2_toggle();
    vait_stripe_2_half_period();
    stripe_2_toggle();
    vait_stripe_2_half_period();
}

Functions for transmitting bits are ready.

A more advanced level is to convert information into a sequence of zeros and ones and begin to transmit them one by one (if each character is converted at the time of transmission, this promises time shifts and a violation of synchronization of the receiving part). But we neglect this for ease of execution.

//отправка сообщения
void buff_2_to_magnetic(char * stripe_2_buff) {
    unsigned char i, lrc = 0;
    for (i = 0; i < 20; i++) {
        stripe_2_tx_0();
    }
    while (*stripe_2_buff) {
        for (i = 0; i < 5; i++) {
            if (*stripe_2_buff & (1 << i)) {
                stripe_2_tx_1();
            } else {
                stripe_2_tx_0();
            }
        }
        lrc ^= *stripe_2_buff;
        stripe_2_buff++;
    }
    for (i = 0; i < 5; i++) {
        if (lrc & (1 << i)) {
            stripe_2_tx_1();
        } else {
            stripe_2_tx_0();
        }
    }
}

If you plan to simulate two or more bands at the same time, it should be noted that due to the different recording density on the tracks between pulses, different time intervals arise, for the measurement of which an appropriate number of time meters will be required. For example, you can use timers or “task” in the operating system.

Research part


  1. Basically, the success of an undertaking depends on the following factors:
  2. VMS voltage;
  3. The number of turns of the coil;
  4. The diameter of the wire in the coil;
  5. Core cross section;
  6. Capacitor capacitance C43 and C44;
  7. Frequency f;
  8. The distance of the coil from the read head;
  9. Magnetic permeability of the core.

It is worth considering that some parameters are variable within specific limits, some are dependent on each other.

For example, let's apply a different voltage to the coil and find out how its change will affect the result, taking into account the immutability of the remaining parameters:

Voltage VActuation distance mmImpact distance mmUneven reading%Unevenness of exposure%
2.30010% off15% off
2.60one30% off70% off
2.80270%thirty%
2.9one5one hundred%0%
327one hundred%0%
3.34elevenone hundred%0%


Response distance - the maximum distance at which a successful read occurs (0 with direct contact).

Impact distance - the distance at which reading is done, but with an error.

Uneven reading - due to the fact that the magnetic core is not closed, there is a stronger magnetic field at its ends.

According to the table compiled, the best result falls on the voltage range 2.8-2.9 V.

voltage waveforms at the ends of the coil as a function of voltage
2.3 V:

image

2.6 V:

image

2.8 V:

image

2.9 V:

image

3 V:

image

3.3 V:

image

conclusions


In the process, there are two drawbacks:
  1. The influence of the signal of the previous track on the adjacent;
  2. Uneven magnetic field intensity along the coil. It manifests itself especially strongly when dragging a card, in contrast to its stationary state.

In the first case, the use of additional screens, or a schematic solution in the form of supplying a weakened signal to an adjacent coil in an inverse connection, can help. Thus, the signal and interference will be in antiphase and cancel each other out. Also, additional help is provided by the closure of the magnetic circuit.

image

In the second case, a closed magnetic circuit can help, as well as a smooth change in the cross-sectional area of ​​the core closer to the ends of the coil.

image

Video device operation:



Github

Also popular now: