CN110838204B - Decoding method for magnetic stripe card swiping terminal - Google Patents

Decoding method for magnetic stripe card swiping terminal Download PDF

Info

Publication number
CN110838204B
CN110838204B CN201911070639.6A CN201911070639A CN110838204B CN 110838204 B CN110838204 B CN 110838204B CN 201911070639 A CN201911070639 A CN 201911070639A CN 110838204 B CN110838204 B CN 110838204B
Authority
CN
China
Prior art keywords
data
value
array
bit
judging whether
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201911070639.6A
Other languages
Chinese (zh)
Other versions
CN110838204A (en
Inventor
李滨滨
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Vanstone Electronic Beijing Co Ltd
Original Assignee
Vanstone Electronic Beijing Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Vanstone Electronic Beijing Co Ltd filed Critical Vanstone Electronic Beijing Co Ltd
Priority to CN201911070639.6A priority Critical patent/CN110838204B/en
Publication of CN110838204A publication Critical patent/CN110838204A/en
Application granted granted Critical
Publication of CN110838204B publication Critical patent/CN110838204B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G07CHECKING-DEVICES
    • G07FCOIN-FREED OR LIKE APPARATUS
    • G07F7/00Mechanisms actuated by objects other than coins to free or to actuate vending, hiring, coin or paper currency dispensing or refunding apparatus
    • G07F7/08Mechanisms actuated by objects other than coins to free or to actuate vending, hiring, coin or paper currency dispensing or refunding apparatus by coded identity card or credit card or other personal identification means
    • G07F7/086Mechanisms actuated by objects other than coins to free or to actuate vending, hiring, coin or paper currency dispensing or refunding apparatus by coded identity card or credit card or other personal identification means by passive credit-cards adapted therefor, e.g. constructive particularities to avoid counterfeiting, e.g. by inclusion of a physical or chemical security-layer
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06KGRAPHICAL DATA READING; PRESENTATION OF DATA; RECORD CARRIERS; HANDLING RECORD CARRIERS
    • G06K7/00Methods or arrangements for sensing record carriers, e.g. for reading patterns
    • G06K7/08Methods or arrangements for sensing record carriers, e.g. for reading patterns by means detecting the change of an electrostatic or magnetic field, e.g. by detecting change of capacitance between electrodes
    • G06K7/082Methods or arrangements for sensing record carriers, e.g. for reading patterns by means detecting the change of an electrostatic or magnetic field, e.g. by detecting change of capacitance between electrodes using inductive or magnetic sensors
    • G06K7/087Methods or arrangements for sensing record carriers, e.g. for reading patterns by means detecting the change of an electrostatic or magnetic field, e.g. by detecting change of capacitance between electrodes using inductive or magnetic sensors flux-sensitive, e.g. magnetic, detectors

Landscapes

  • Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Artificial Intelligence (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Signal Processing For Digital Recording And Reproducing (AREA)

Abstract

The invention discloses a decoding method for a magnetic stripe card swiping terminal, wherein a magnetic card chip is arranged in a magnetic stripe card, and a processor is arranged in the card swiping terminal; s1, when the card is swiped, the magnetic card chip is connected with the processor to judge whether the processor monitors interruption; if yes, the processor closes the interrupt, starts the timeout timer and executes the step S2; if not, exiting the interruption; s2, updating the timing count; s3, the processor reads the level states of three external IOs, judges whether the IO has level jump or not, if so, records the IO with level jump and the time interval of the last jump of the IO into an array corresponding to the IO, each IO corresponds to one magnetic track, each magnetic track corresponds to one T array, and executes S4; if not, directly executing S4; and the like. The advantages are that: the success rate of decoding is increased, the probability of reporting error codes is reduced, the design cost is reduced, and the user experience is improved.

Description

Decoding method for magnetic stripe card swiping terminal
Technical Field
The invention relates to the field of electronic communication and financial payment, in particular to a decoding method for a magnetic stripe card swiping terminal.
Background
In daily life, the magnetic stripe card is used as a carrier for information recording, and has the advantages of low cost, high strength, and convenient, stable and reliable carrying. Is widely applied to the fields of various bank cards, gift cards, transportation cards and the like. The financial terminal is used as a card reading device and can read the magnetic stripe card. But with the wide application, some problems are brought. For example, after the magnetic stripe card is used for a period of time, the recognition rate is reduced due to abrasion; the card swiping speeds of users are inconsistent, and the habits of positive and negative swiping are different, so that the magnetic card is not easy to be identified and read by equipment; in order to ensure that the card reading and reading rate is increased with a plurality of software and hardware functions during design, the cost is increased.
Disclosure of Invention
The invention aims to provide a decoding method for a magnetic stripe card swiping card terminal, so as to solve the problems in the prior art.
In order to achieve the purpose, the technical scheme adopted by the invention is as follows:
a magnetic stripe card is provided with a magnetic card chip, and a card swiping terminal is internally provided with a processor; the decoding method comprises the steps of, after decoding,
s1, when the card is swiped, the magnetic card chip is connected with the processor, and whether the monitoring of the processor is interrupted or not is judged; if yes, the processor closes the interrupt, starts the timeout timer and executes the step S2; if not, exiting the interruption;
s2, updating the timing count;
s3, the processor reads the level states of three external IOs, judges whether the IO has level jump or not, if so, records the IO with level jump and the time interval of the last jump of the IO into an array corresponding to the IO, each IO corresponds to one magnetic track, each magnetic track corresponds to one T array, and executes S4; if not, directly executing S4;
s4, the processor judges whether the overtime exceeds the preset time length, if yes, the step S5 is executed; if not, returning to the step S2;
s5, copying the T array content of one track into the p array by the processor;
s6, the processor decodes the time interval data in the p array into binary data, and the binary data is stored in the m array;
s7, the processor decodes the binary data according to the coding format to obtain decoded data, stores the decoded data in an m _ bit array, finds the corresponding ASCII code of the decoded data according to a table look-up mode to obtain corresponding data, and stores the corresponding data in an out array;
s8, the processor checks the decoded data and the corresponding data, if the check is passed, the step S9 is executed; if the verification fails, go to step S10;
s9, the processor transfers the corresponding data to the global data, the processor sets the successful flag of the magnetic track card swiping, and executes the step S11;
s10, the processor sets the failure flag of the magnetic track card swiping, and executes the step S11;
s11, repeating the steps S5 to S10; judging whether the T arrays corresponding to the three magnetic tracks are completely analyzed, and if so, exiting the interruption; if not, the process returns to step S5.
Preferably, the processor decodes the time interval data in the p array into binary data in step S6, specifically,
a1, acquiring an array pointer p of the p array, and setting the length of time interval data to be decoded to len and the initial reference value to bitlen;
a2, defining the count value as I, j, and endowing both I and j with an initial value of 0; defining a first skip and a second skip of the zone bits, and endowing the first skip and the second skip with an initial value of 0;
a3, judging whether i is less than len-1, if yes, executing step S44; if not, executing the step A4;
a4, judging whether the first skip is equal to 0, if yes, executing S47, and if no, executing A5;
a5, assigning the first skip as 0;
adding 1 to the value of A6 and i, and returning to S43;
a7, judging p [ i ] < bitlen 0.7, namely judging whether the ith bit of p is less than 0.7 times of a reference value bitlen; if yes, A8 is executed; if not, executing A11;
a8, judging p [ i +1] < bitlen 0.7, namely judging whether the i +1 th bit of p is less than 0.7 times of a reference value bitlen; if yes, A9 is executed; if not, executing A11;
a9, judging whether the sum of the data of the ith bit and the i +1 bit of p is less than 1.4 times of a reference value or not, namely judging whether the sum of the data of the ith bit and the i +1 bit of p is less than 1.4 times of the reference value; if yes, A10 is executed; if not, executing A11;
a10, updating bitlen, and calculating bitlen ═ bitlen × 0.8+ (p [ i ] + p [ i +1]) × 0.2; taking the weight of 80% of the original reference value plus the weight of 20% of the sum of the ith bit and the (i + 1) th bit of p as a new reference value; executing m [ j + + ] -1, and the second Skip-1, namely the decoding result is 1, recording the data at the j position of the m array, and simultaneously adding 1 to the value of j, setting the second Skip as 1; and jumps to A6;
a11, judging p [ i ] < bitlen 0.8, namely judging whether the ith data of p is less than 0.8 times of a reference value bitlen; if yes, go to step S412; if not, executing A13;
a12, executing p [ i +1] ═ p [ i +1] - ((Bitlen-p [ i ]) 0.8), namely, updating the i +1 th bit data of p into the i +1 th bit data of p minus the 80% weight of the difference value between the reference value and the i-th bit data of p;
a13, executing BItlen 0.8+ p [ i ] 0.2m [ j + + ] -0, namely, the decoding result is 0, recording the result to j bits of the m arrays, and increasing the count value j by 1; jumping to execute A6;
wherein, p represents an array pointer of a p array; m represents an m array; len is the data length of the time interval to be decoded; bitlen is an initial reference value; i is a count value of a p array; j is the count value of the m array; the first skip is a zone bit of a p array, and the second skip is a zone bit of an m array; skip indicates whether the current flag bit is skipped.
Preferably, the process of converting the binary data into ASCII code in step S7, specifically,
b1, substituting the parameters m, len, ch and out into a first analytical function;
b2, taking i, j as a count value, and respectively recording the position of binary data to be decoded and the position of storing an ASCII code; assigning initial values of i, j, start and c as 0;
b3, judging whether i is smaller than len, if so, adding 1 to i; if not, adding 1 to i and then executing B6;
b4, judging whether the ith bit in m is not 0, if yes, executing B5; if not, execute B3;
b5, assigning the data i to start, and indicating that the current position is assigned to start;
b6, judging whether ch is 0, namely judging whether the current magnetic track is a1 magnetic track; if yes, execute B7; if not, execute B9;
b7, updating the count value i to be the record value of start;
b8, judging whether i is smaller than the difference value of len-5, if yes, executing B10; if not, execute B9;
b9, updating the record value with the count value i as the start, and executing B15;
b10, calculation
c ═ c (m [ i +6] < <6) + (m [ i +5] < <5) + (m [ i +4] < <4) + (m [ i +3] < <3) + (m [ i +2] < <2) + (m [ i +1] < <1) + (m [ i ]); namely, 7 data are taken from the i position of m, calculated according to a formula and given to c;
b11, clearing the highest bit of c to 0;
b12, substituting the character c into the table track1cset, and if the position indicated by c is not 0, executing B14; if not, execute B13;
b13, adding 1 to the value of i, and jumping to execute A8;
b14, assigning the data of the position c in the table to the j bit of the out array, recording the value of c to the m _ bit array of the array, and adding 1 to j;
b15, judging whether the value i is smaller than the difference value of len-5, if yes, executing B16; if not, B21 is executed.
B16, calculation
c is (m [ i +4] < <4) + (m [ i +3] < <3) + (m [ i +2] < <2) + (m [ i +1] < <1) + (m [ i ]), namely 5 data are taken from the i position of m, calculated according to a formula and given to c;
b17, clearing the highest 3 bits of c to 0;
b18, substituting c into the table track3cset, judging whether the data of the c position in the table is not 0, if yes, executing B19; if not, execute B20;
b19, assigning the value of the position c in the table to the j bit in the out array, recording the value of c in the m _ bit array of the array, and adding 1 to j;
b20, i is added with 1, and the jump is executed B15;
b21, assigning the value of the j-1 position in the out array to be 0;
b22, returning the value of j and exiting the first analytical function;
wherein m is an m array; len is the data length decoded from binary data; ch is the track number; start is the track valid data position; c is the result of the current decoding; i is a count value in the m array; j is the count value in the out array.
Preferably, the processor performs a verification process on the decoded data and the corresponding data in step S8, specifically,
and C1, substituting the m _ bit array, the size and the ch of the parameters into a second analytic function.
C2, definition lrc, and assigned a value of 0; definition lrc _ p, assigned a value of 0; defining a code length value bits and defining counting values i and j;
c3, judging whether ch is 0, namely judging whether the current track is 0; if yes, go to C5; if not, go to C4;
c4, startb assigned 0x0 b; endb is assigned a value of 0x1 f; bits is assigned a value of 4; namely, the start flag bit 0x0b and the end flag bit 0x1f of the data length of 4 are determined, and C6 is performed;
c5, startb assigned 0x 45; endb is assigned a value of 0x1 f; the bits is assigned a value of 6; namely, the start bit flag 0x45 and the end bit flag 0x1f of the judgment data are 6 in data length;
c6, judging whether m _ bit [0] is equal to startb, namely judging whether the data head is correct; if yes, go to C7; if not, go to C23;
c7, assigning the count value i to be 0;
c8, judging whether i is smaller than size, if yes, executing C9; if not, go to C12;
c9, calculating lrc according to a formula, wherein lrc is lrc ^ m _ bit [ i ]; computing lrc exclusive or sum of valid data;
c10, judging whether the value of the i bit in the m _ bit array is equal to endb, namely judging whether an ending mark is found; if yes, go to C13; if not, go to C11;
c11, adding 1 to the value of i; jump execution C8;
c12, judging whether the value of the i bit in the m _ bit array is equal to endb, namely judging whether an ending mark is found; if yes, execute B13; if not, executing C22;
c13, assigning j to 0;
c14, judging whether j is smaller than bits, if so, executing B15; if not, go to C17;
c15, calculating lrc _ p ^ (lrc & (1< < j)) > > j according to a formula;
c16, j value plus 1; jump execution C14;
c17, calculating lrc _ p ^ 1 according to a formula;
c18, calculating lrc & (1< < bits) -1 according to a formula; lrc ═ lrc | (lrc _ p < < bits);
c19, determine whether m _ bit [ i +1] is equal to lrc, i.e., determine lrc is correct; if yes, go to C20; if not, go to C21;
c20, return data value 0;
c21, return data value 3;
c22, return data value 2;
c23, return data value 1;
wherein, size is data length; ch is track data; startb is track start data; endb is track end data; lrc is a check byte; lrc _ p is the parity bit of the check byte; bits is a data coding length mark; i is the count value of the m _ bit array; j is the count value of the second analytical function.
The invention has the beneficial effects that: the success rate of decoding is increased, the probability of reporting error codes is reduced, the design cost is reduced, and the user experience is improved.
Drawings
FIG. 1 is a flow chart of a decoding method according to an embodiment of the present invention;
fig. 2 is a schematic structural diagram of a processor and a magnetic card chip according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is further described in detail below with reference to the accompanying drawings. It should be understood that the detailed description and specific examples, while indicating the invention, are intended for purposes of illustration only and are not intended to limit the scope of the invention.
As shown in fig. 1 to 2, the present embodiment provides a decoding method for a card swiping terminal of a magnetic stripe card, wherein the magnetic stripe card is provided with a magnetic card chip, and the card swiping terminal is provided with a processor; the decoding method comprises the steps of, after decoding,
s1, when the card is swiped, the magnetic card chip is connected with the processor, and whether the monitoring of the processor is interrupted or not is judged; if yes, the processor closes the interrupt, starts the timeout timer and executes the step S2; if not, exiting the interruption;
s2, updating the timing count;
s3, the processor reads the level states of three external IOs, judges whether the IO has level jump or not, if so, records the IO with level jump and the time interval of the last jump of the IO into an array corresponding to the IO, each IO corresponds to one magnetic track, each magnetic track corresponds to one T array, and executes S4; if not, directly executing S4;
s4, the processor judges whether the overtime exceeds the preset time length, if yes, the step S5 is executed; if not, returning to the step S2;
s5, copying the T array content of one track into the p array by the processor;
s6, the processor decodes the time interval data in the p array into binary data, and the binary data is stored in the m array;
s7, the processor decodes the binary data according to the coding format to obtain decoded data, stores the decoded data in an m _ bit array, finds the corresponding ASCII code of the decoded data according to a table look-up mode to obtain corresponding data, and stores the corresponding data in an out array;
s8, the processor checks the decoded data and the corresponding data, if the check is passed, the step S9 is executed; if the verification fails, go to step S10;
s9, the processor transfers the corresponding data to the global data, the processor sets the successful flag of the magnetic track card swiping, and executes the step S11;
s10, the processor sets the failure flag of the magnetic track card swiping, and executes the step S11;
s11, repeating the steps S5 to S10; judging whether the T arrays corresponding to the three magnetic tracks are completely analyzed, and if so, exiting the interruption; if not, the process returns to step S5.
In this embodiment, in step S1, the processor IO may generate a jump due to the card swiping event being affected by the magnetic card chip, and the IO jump of the processor may trigger the monitoring interrupt. Referring to fig. 2, the processor includes three IOs, each IO corresponds to one track, each track corresponds to one T array, the three IOs are IO1, IO2, and IO3, and the corresponding T arrays are T1 array, T2 array, and T3 array, respectively. Any IO transition will cause processor interrupt.
In this embodiment, in step S4, the timeout exceeds the preset duration, which indicates that all three IOs are jumping within the timeout period. The preset duration can be specifically set according to actual needs so as to better meet the actual needs.
In this embodiment, in step S6, the processor decodes the time interval data in the p array into binary data, specifically,
a1, acquiring an array pointer p of the p array, and setting the length of time interval data to be decoded to len and the initial reference value to bitlen;
a2, defining the count value as I, j, and endowing both I and j with an initial value of 0; defining a first skip and a second skip of the zone bits, and endowing the first skip and the second skip with an initial value of 0;
a3, judging whether i is less than len-1, if yes, executing step S44; if not, executing the step A4;
a4, judging whether the first skip is equal to 0, if yes, executing S47, and if no, executing A5;
a5, assigning the first skip as 0;
adding 1 to the value of A6 and i, and returning to S43;
a7, judging p [ i ] < bitlen 0.7, namely judging whether the ith bit of p is less than 0.7 times of a reference value bitlen; if yes, A8 is executed; if not, executing A11;
a8, judging p [ i +1] < bitlen 0.7, namely judging whether the i +1 th bit of p is less than 0.7 times of a reference value bitlen; if yes, A9 is executed; if not, executing A11;
a9, judging whether the sum of the data of the ith bit and the i +1 bit of p is less than 1.4 times of a reference value or not, namely judging whether the sum of the data of the ith bit and the i +1 bit of p is less than 1.4 times of the reference value; if yes, A10 is executed; if not, executing A11;
a10, updating bitlen, and calculating bitlen ═ bitlen × 0.8+ (p [ i ] + p [ i +1]) × 0.2; taking the weight of 80% of the original reference value plus the weight of 20% of the sum of the ith bit and the (i + 1) th bit of p as a new reference value; executing m [ j + + ] -1, and the second Skip-1, namely the decoding result is 1, recording the data at the j position of the m array, and simultaneously adding 1 to the value of j, setting the second Skip as 1; and jumps to A6;
a11, judging p [ i ] < bitlen 0.8, namely judging whether the ith data of p is less than 0.8 times of a reference value bitlen; if yes, go to step S412; if not, executing A13;
a12, executing p [ i +1] ═ p [ i +1] - ((Bitlen-p [ i ]) 0.8), namely, updating the i +1 th bit data of p into the i +1 th bit data of p minus the 80% weight of the difference value between the reference value and the i-th bit data of p;
a13, executing BItlen 0.8+ p [ i ] 0.2m [ j + + ] -0, namely, the decoding result is 0, recording the result to j bits of the m arrays, and increasing the count value j by 1; jumping to execute A6;
wherein, p represents an array pointer of a p array; m represents an m array; len is the data length of the time interval to be decoded; bitlen is an initial reference value; i is a count value of a p array; j is the count value of the m array; the first skip is a zone bit of a p array, and the second skip is a zone bit of an m array; skip indicates whether the current flag bit is skipped.
In this embodiment, the process of converting the binary data into ASCII code in step S7 is, specifically,
b1, substituting the parameters m, len, ch and out into a first analytical function;
b2, taking i, j as a count value, and respectively recording the position of binary data to be decoded and the position of storing an ASCII code; assigning initial values of i, j, start and c as 0;
b3, judging whether i is smaller than len, if so, adding 1 to i; if not, adding 1 to i and then executing B6;
b4, judging whether the ith bit in m is not 0, if yes, executing B5; if not, execute B3;
b5, assigning the data i to start, and indicating that the current position is assigned to start;
b6, judging whether ch is 0, namely judging whether the current magnetic track is a1 magnetic track; if yes, execute B7; if not, execute B9;
b7, updating the count value i to be the record value of start;
b8, judging whether i is smaller than the difference value of len-5, if yes, executing B10; if not, execute B9;
b9, updating the record value with the count value i as the start, and executing B15;
b10, calculation
c ═ c (m [ i +6] < <6) + (m [ i +5] < <5) + (m [ i +4] < <4) + (m [ i +3] < <3) + (m [ i +2] < <2) + (m [ i +1] < <1) + (m [ i ]); namely, 7 data are taken from the i position of m, calculated according to a formula and given to c;
b11, clearing the highest bit of c to 0;
b12, substituting the character c into the table track1cset, and if the position indicated by c is not 0, executing B14; if not, execute B13;
b13, adding 1 to the value of i, and jumping to execute A8;
b14, assigning the data of the position c in the table to the j bit of the out array, recording the value of c to the m _ bit array of the array, and adding 1 to j;
b15, judging whether the value i is smaller than the difference value of len-5, if yes, executing B16; if not, B21 is executed.
B16, calculation
c is (m [ i +4] < <4) + (m [ i +3] < <3) + (m [ i +2] < <2) + (m [ i +1] < <1) + (m [ i ]), namely 5 data are taken from the i position of m, calculated according to a formula and given to c;
b17, clearing the highest 3 bits of c to 0;
b18, substituting c into the table track3cset, judging whether the data of the c position in the table is not 0, if yes, executing B19; if not, execute B20;
b19, assigning the value of the position c in the table to the j bit in the out array, recording the value of c in the m _ bit array of the array, and adding 1 to j;
b20, i is added with 1, and the jump is executed B15;
b21, assigning the value of the j-1 position in the out array to be 0;
b22, returning the value of j and exiting the first analytical function;
wherein m is an m array; len is the data length decoded from binary data; ch is the track number; start is the track valid data position; c is the result of the current decoding; i is a count value in the m array; j is the count value in the out array.
In this embodiment, the processor in step S8 performs a verification process on the decoded data and the corresponding data, specifically,
and C1, substituting the m _ bit array, the size and the ch of the parameters into a second analytic function.
C2, definition lrc, and assigned a value of 0; definition lrc _ p, assigned a value of 0; defining a code length value bits and defining counting values i and j;
c3, judging whether ch is 0, namely judging whether the current track is 0; if yes, go to C5; if not, go to C4;
c4, startb assigned 0x0 b; endb is assigned a value of 0x1 f; bits is assigned a value of 4; namely, the start flag bit 0x0b and the end flag bit 0x1f of the data length of 4 are determined, and C6 is performed;
c5, startb assigned 0x 45; endb is assigned a value of 0x1 f; the bits is assigned a value of 6; namely, the start bit flag 0x45 and the end bit flag 0x1f of the judgment data are 6 in data length;
c6, judging whether m _ bit [0] is equal to startb, namely judging whether the data head is correct; if yes, go to C7; if not, go to C23;
c7, assigning the count value i to be 0;
c8, judging whether i is smaller than size, if yes, executing C9; if not, go to C12;
c9, calculating lrc according to a formula, wherein lrc is lrc ^ m _ bit [ i ]; computing lrc exclusive or sum of valid data;
c10, judging whether the value of the i bit in the m _ bit array is equal to endb, namely judging whether an ending mark is found; if yes, go to C13; if not, go to C11;
c11, adding 1 to the value of i; jump execution C8;
c12, judging whether the value of the i bit in the m _ bit array is equal to endb, namely judging whether an ending mark is found; if yes, execute B13; if not, executing C22;
c13, assigning j to 0;
c14, judging whether j is smaller than bits, if so, executing B15; if not, go to C17;
c15, calculating lrc _ p ^ (lrc & (1< < j)) > > j according to a formula;
c16, j value plus 1; jump execution C14;
c17, calculating lrc _ p ^ 1 according to a formula;
c18, calculating lrc & (1< < bits) -1 according to a formula; lrc ═ lrc | (lrc _ p < < bits);
c19, determine whether m _ bit [ i +1] is equal to lrc, i.e., determine lrc is correct; if yes, go to C20; if not, go to C21;
c20, return data value 0;
c21, return data value 3;
c22, return data value 2;
c23, return data value 1;
wherein, size is data length; ch is track data; startb is track start data; endb is track end data; lrc is a check byte; lrc _ p is the parity bit of the check byte; bits is a data coding length mark; i is the count value of the m _ bit array; j is the count value of the second analytical function.
By adopting the technical scheme disclosed by the invention, the following beneficial effects are obtained:
the invention provides a decoding method for a magnetic stripe card swiping terminal, which increases the success rate of decoding, reduces the probability of reporting error codes, reduces the design cost and improves the use experience of users.
The foregoing is only a preferred embodiment of the present invention, and it should be noted that, for those skilled in the art, various modifications and improvements can be made without departing from the principle of the present invention, and such modifications and improvements should also be considered within the scope of the present invention.

Claims (3)

1. A magnetic stripe card is provided with a magnetic card chip, and a card swiping terminal is internally provided with a processor; the method is characterized in that: the decoding method comprises the steps of, after decoding,
s1, when the card is swiped, the magnetic card chip is connected with the processor, and whether the monitoring of the processor is interrupted or not is judged; if yes, the processor closes the interrupt, starts the timeout timer and executes the step S2; if not, exiting the interruption;
s2, updating the timing count;
s3, the processor reads the level states of three external IOs, judges whether the IO has level jump or not, if so, records the IO with level jump and the time interval of the last jump of the IO into an array corresponding to the IO, each IO corresponds to one magnetic track, each magnetic track corresponds to one T array, and executes S4; if not, directly executing S4;
s4, the processor judges whether the overtime exceeds the preset time length, if yes, the step S5 is executed; if not, returning to the step S2;
s5, copying the T array content of one track into the p array by the processor;
s6, the processor decodes the time interval data in the p array into binary data, and the binary data is stored in the m array;
s7, the processor decodes the binary data according to the coding format to obtain decoded data, stores the decoded data in an m _ bit array, finds the corresponding ASCII code of the decoded data according to a table look-up mode to obtain corresponding data, and stores the corresponding data in an out array;
s8, the processor checks the decoded data and the corresponding data, if the check is passed, the step S9 is executed; if the verification fails, go to step S10;
s9, the processor transfers the corresponding data to the global data, the processor sets the successful flag of the magnetic track card swiping, and executes the step S11;
s10, the processor sets the failure flag of the magnetic track card swiping, and executes the step S11;
s11, repeating the steps S5 to S10; judging whether the T arrays corresponding to the three magnetic tracks are completely analyzed, and if so, exiting the interruption; if not, returning to the step S5;
in step S6, the processor decodes the time interval data in the p array into binary data, specifically,
a1, acquiring an array pointer p of the p array, and setting the length of time interval data to be decoded to len and the initial reference value to bitlen;
a2, defining the count value as i, j, and endowing both i and j with an initial value of 0; defining a first skip and a second skip of the zone bits, and endowing the first skip and the second skip with an initial value of 0;
a3, judging whether i is less than len-1, if yes, executing step A4; if not, executing the step A13;
a4, judging whether the first skip is equal to 0, if yes, executing A7, and if no, executing A5;
a5, assigning the first skip as 0;
adding 1 to the value of A6 and i, and returning to A3;
a7, judging p [ i ] < bitlen 0.7, namely judging whether the ith bit of p is less than 0.7 times of a reference value bitlen; if yes, A8 is executed; if not, executing A11;
a8, judging p [ i +1] < bitlen 0.7, namely judging whether the i +1 th bit of p is less than 0.7 times of a reference value bitlen; if yes, A9 is executed; if not, executing A11;
a9, judging whether the sum of the data of the ith bit and the i +1 bit of p is less than 1.4 times of a reference value or not, namely judging whether the sum of the data of the ith bit and the i +1 bit of p is less than 1.4 times of the reference value; if yes, A10 is executed; if not, executing A11;
a10, updating bitlen, and calculating bitlen ═ bitlen × 0.8+ (p [ i ] + p [ i +1]) × 0.2; taking the weight of 80% of the original reference value plus the weight of 20% of the sum of the ith bit and the (i + 1) th bit of p as a new reference value; executing m [ j + + ] -1, and a second skip-1, namely, the decoding result is 1, recording the data at the j position of the m array, and simultaneously adding 1 to the value of j, and setting the second skip to be 1; and jumps to A6;
a11, judging p [ i ] < bitlen 0.8, namely judging whether the ith data of p is less than 0.8 times of a reference value bitlen; if yes, A12 is executed; if not, executing A13;
a12, executing p [ i +1] ═ p [ i +1] - ((Bitlen-p [ i ]) 0.8), namely, updating the i +1 th bit data of p into the i +1 th bit data of p minus the 80% weight of the difference value between the reference value and the i-th bit data of p;
a13, executing BItlen 0.8+ p [ i ] 0.2m [ j + + ] -0, namely, the decoding result is 0, recording the result to j bits of the m arrays, and increasing the count value j by 1; jumping to execute A6;
wherein, p represents an array pointer of a p array; m represents an m array; len is the data length of the time interval to be decoded; bitlen is an initial reference value; i is a count value of a p array; j is the count value of the m array; the first skip is a zone bit of a p array, and the second skip is a zone bit of an m array; skip indicates whether the current flag bit is skipped.
2. The magnetic stripe card swiping terminal decoding method according to claim 1, characterized in that: the process of converting the binary data into ASCII code in step S7, specifically,
b1, substituting the parameters m, len, ch and out into a first analytical function;
b2, taking i, j as a count value, and respectively recording the position of binary data to be decoded and the position of storing an ASCII code; assigning initial values of i, j, start and c as 0;
b3, judging whether i is smaller than len, if so, adding 1 to i; if not, adding 1 to i and then executing B6;
b4, judging whether the ith bit in m is not 0, if yes, executing B5; if not, execute B3;
b5, assigning the data i to start, and indicating that the current position is assigned to start;
b6, judging whether ch is 0, namely judging whether the current magnetic track is a1 magnetic track; if yes, execute B7; if not, execute B9;
b7, updating the count value i to be the record value of start;
b8, judging whether i is smaller than the difference value of len-5, if yes, executing B10; if not, execute B9;
b9, updating the record value with the count value i as the start, and executing B15;
b10, calculation
c ═ c (m [ i +6] < <6) + (m [ i +5] < <5) + (m [ i +4] < <4) + (m [ i +3] < <3) + (m [ i +2] < <2) + (m [ i +1] < <1) + (m [ i ]); namely, 7 data are taken from the i position of m, calculated according to a formula and given to c;
b11, clearing the highest bit of c to 0;
b12, substituting the character c into the table track1cset, and if the position indicated by c is not 0, executing B14; if not, execute B13;
b13, adding 1 to the value of i, jumping to execute B8;
b14, assigning the data of the position c in the table to the j bit of the out array, recording the value of c to the m _ bit array of the array, and adding 1 to j;
b15, judging whether the value i is smaller than the difference value of len-5, if yes, executing B16; if not, execute B21;
b16, calculation
c is (m [ i +4] < <4) + (m [ i +3] < <3) + (m [ i +2] < <2) + (m [ i +1] < <1) + (m [ i ]), namely 5 data are taken from the i position of m, calculated according to a formula and given to c;
b17, clearing the highest 3 bits of c to 0;
b18, substituting c into the table track3cset, judging whether the data of the c position in the table is not 0, if yes, executing B19; if not, execute B20;
b19, assigning the value of the position c in the table to the j-th bit in the out array, recording the value of c in the array m _ bit array, and adding 1 to j;
b20, i is added with 1, and the jump is executed B15;
b21, assigning the value of the j-1 th position in the out array as 0;
b22, returning the value of j and exiting the first analytical function;
wherein m is an m array; len is the data length decoded from binary data; ch is the track number; start is the track valid data position; c is the result of the current decoding; i is a count value in the m array; j is the count value in the out array.
3. The magnetic stripe card swiping terminal decoding method according to claim 1, characterized in that: in step S8, the processor performs a verification process on the decoded data and the corresponding data, specifically,
c1, substituting the m _ bit array, the size and the ch of the parameters into a second analytic function;
c2, definition lrc, and assigned a value of 0; definition lrc _ p, assigned a value of 0; defining a code length value bits and defining counting values i and j;
c3, judging whether ch is 0, namely judging whether the current track is 0; if yes, go to C5; if not, go to C4;
c4, startb assigned 0x0 b; endb is assigned a value of 0x1 f; bits is assigned a value of 4; namely, the start flag bit 0x0b and the end flag bit 0x1f of the data length of 4 are determined, and C6 is performed;
c5, startb assigned 0x 45; endb is assigned a value of 0x1 f; the bits is assigned a value of 6; namely, the start bit flag 0x45 and the end bit flag 0x1f of the judgment data are 6 in data length;
c6, judging whether m _ bit [0] is equal to startb, namely judging whether the data head is correct; if yes, go to C7; if not, go to C23;
c7, assigning the count value i to be 0;
c8, judging whether i is smaller than size, if yes, executing C9; if not, go to C12;
c9, calculating lrc according to a formula, wherein lrc is lrc ^ m _ bit [ i ]; computing lrc exclusive or sum of valid data;
c10, judging whether the value of the ith bit in the m _ bit array is equal to endb or not, namely judging whether an ending mark is found or not; if yes, go to C13; if not, go to C11;
c11, adding 1 to the value of i; jump execution C8;
c12, judging whether the value of the ith bit in the m _ bit array is equal to endb or not, namely judging whether an ending mark is found or not; if yes, go to C13; if not, executing C22;
c13, assigning j to 0;
c14, judging whether j is smaller than bits, if so, executing C15; if not, go to C17;
c15, calculating lrc _ p ^ (lrc & (1< < j)) > > j according to a formula;
c16, j value plus 1; jump execution C14;
c17, calculating lrc _ p ^ 1 according to a formula;
c18, calculating lrc & (1< < bits) -1 according to a formula; lrc ═ lrc | (lrc _ p < < bits);
c19, determine whether m _ bit [ i +1] is equal to lrc, i.e., determine lrc is correct; if yes, go to C20; if not, go to C21;
c20, return data value 0;
c21, return data value 3;
c22, return data value 2;
c23, return data value 1;
wherein, size is data length; ch is track data; startb is track start data; endb is track end data; lrc is a check byte; lrc _ p is the parity bit of the check byte; bits is a data coding length mark; i is the count value of the m _ bit array; j is the count value of the second analytical function.
CN201911070639.6A 2019-11-05 2019-11-05 Decoding method for magnetic stripe card swiping terminal Active CN110838204B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911070639.6A CN110838204B (en) 2019-11-05 2019-11-05 Decoding method for magnetic stripe card swiping terminal

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911070639.6A CN110838204B (en) 2019-11-05 2019-11-05 Decoding method for magnetic stripe card swiping terminal

Publications (2)

Publication Number Publication Date
CN110838204A CN110838204A (en) 2020-02-25
CN110838204B true CN110838204B (en) 2021-04-13

Family

ID=69576093

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911070639.6A Active CN110838204B (en) 2019-11-05 2019-11-05 Decoding method for magnetic stripe card swiping terminal

Country Status (1)

Country Link
CN (1) CN110838204B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109726604B (en) * 2018-12-27 2022-04-15 艾体威尔电子技术(北京)有限公司 Data exchange communication method between contact card and terminal
CN114299676B (en) * 2021-12-31 2023-12-01 福建新大陆支付技术有限公司 Method for improving correct identification and swiping of POS terminal magnetic card

Family Cites Families (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7163148B2 (en) * 2004-03-31 2007-01-16 Silicon Labs Cp, Inc. Magnetic stripe reader
CN100376084C (en) * 2006-05-19 2008-03-19 宁波中科集成电路设计中心有限公司 Manchester code decoding method and application apparatus therefor
CN102368076B (en) * 2011-10-19 2012-11-28 福建联迪商用设备有限公司 Card feeding speed testing method and device
CN102930238B (en) * 2012-10-31 2015-12-02 深圳市新国都技术股份有限公司 A kind of decoding for magnetic card and error correction method
CN103034829A (en) * 2012-12-19 2013-04-10 福建升腾资讯有限公司 Soft decoding method of magcard
US8794517B1 (en) * 2013-08-07 2014-08-05 Square, Inc. Encoding data in multiple formats
CN103679239B (en) * 2013-12-31 2017-04-26 深圳市吉芯微半导体有限公司 Radio frequency reader-writer and radio frequency identification system
CN104463057B (en) * 2014-12-30 2017-09-29 福建联迪商用设备有限公司 A kind of magnetic card coding/decoding method and device
CN104868921B (en) * 2015-05-26 2018-05-18 浙江中控技术股份有限公司 A kind of coding/decoding method and device
CN106682553A (en) * 2016-12-21 2017-05-17 福建升腾资讯有限公司 Strip-card software decoding method
CN106874811B (en) * 2016-12-27 2020-05-01 东软集团股份有限公司 Magnetic stripe card data reading method and device
CN109726604B (en) * 2018-12-27 2022-04-15 艾体威尔电子技术(北京)有限公司 Data exchange communication method between contact card and terminal
CN109902519B (en) * 2019-02-28 2023-01-17 苏州国芯科技股份有限公司 Magnetic stripe decoding method, system and related device

Also Published As

Publication number Publication date
CN110838204A (en) 2020-02-25

Similar Documents

Publication Publication Date Title
CN110838204B (en) Decoding method for magnetic stripe card swiping terminal
CN109510686B (en) Universal binary stream data conversion processing method
CN106374933A (en) Data compression device and method
CN101263502B (en) Detection of faults during a long perturbation
CN104025094A (en) Apparatus And Method For Detecting Abnormal Account
CN106682553A (en) Strip-card software decoding method
CN106033574B (en) Method and device for identifying cheating behaviors
CN102222211B (en) Magcard decoding method and magcard reading device
CN108388547A (en) Character string parsing method, apparatus, equipment and computer readable storage medium
CN106095910B (en) Label information analytic method, device and the terminal of a kind of audio file
CN111063098A (en) Method and system for realizing Bluetooth recharging
CN110647776B (en) Magnetic stripe card decoding method
CN110633588B (en) Noise identification method for magnetic stripe card reader
CN111582600B (en) Behavior period determination method and device
CN111055725B (en) Electric vehicle battery aging identification method and device, terminal equipment and storage medium
CN109902519B (en) Magnetic stripe decoding method, system and related device
US20160173204A1 (en) Optical signal recognition method and apparatus
CN113689945A (en) Big data business analysis method and system applied to intelligent medical treatment
CN109308182B (en) Function compiling method, compiling system and storage medium
CN110569304A (en) question and answer data processing method and device based on block chain
CN110515652A (en) Generation method, device and the storage medium of code abstract
CN110688864B (en) Differential decoding method for magnetic stripe card reader
CN114448968B (en) Pushed amount checking method and device, electronic equipment and storage medium
CN114299676B (en) Method for improving correct identification and swiping of POS terminal magnetic card
CN110443597B (en) Reminding method and device for balance transfer of IC card

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant