Magnetic card decoding method based on AMR sensor and storage medium
The method improves magnetic card decoding accuracy by traversing and decoding feature points, initializing and updating a model buffer, addressing errors from unstable signals in AMR sensors.
Patent Information
- Application Number
- CN202411644721.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-18
- Publication Date
- 2024-12-27
AI Technical Summary
Existing magnetic card decoding methods using anisotropic magnetoresistive (AMR) sensors suffer from errors due to unstable magnetic signals, leading to decoding inaccuracies.
A method involving traversing feature points, decoding them to generate feature codes, comparing with preset starting characters, initializing a model buffer (model buff) when matching, and updating it during decoding to improve accuracy.
Enhances decoding success rate by using an updated model buffer for real-time decoding, reducing errors from unstable signals.
Smart Images

Figure CN119206937A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the field of magnetic card decoding, and in particular to a magnetic card decoding method and a storage medium based on an AMR sensor. Background Art
[0002] The current solutions for decoding the magnetic stripe of bank cards on POS machines can be divided into pure hardware decoding solutions and software-hardware combined decoding solutions. The pure hardware solution means that the entire decoding process (including the collection and decoding of magnetic information on the magnetic stripe card) is completed entirely by hardware. The software-hardware combined solution means that the magnetic information is converted into an electrical signal that can be processed by software through a magnetoelectric sensor, and then decoded by the MCU on the POS machine using software processing methods. The pure hardware solution has a fast decoding speed, but it is expensive and difficult to modify. In comparison, the software-hardware combined solution has lower costs, greater flexibility, and is easy to transplant and adapt. The mainstream solution on the market is the software-hardware combined method.
[0003] At present, anisotropic magnetoresistive elements (AMR) are widely used as magnetoelectric sensing elements on POS machines due to their low cost and relatively simple process. However, due to the characteristics of AMR, when decoding feature points, errors may occur due to unstable magnetic signals and other reasons. Summary of the invention
[0004] To achieve the above-mentioned purpose and other related purposes, the present invention discloses a magnetic card decoding method based on an AMR sensor, comprising: S1: traverse the acquired feature points and decode the feature points to generate feature codes, compare the feature codes with the preset starting characters, and when the feature codes are the same as the starting characters, initialize the model buff and enter the character decoding stage, wherein the feature points include the data points collected by the AMR sensor in the card swiping stage; S2: Taking the feature point corresponding to the starting character as the starting point, the feature points after the starting point are decoded in sequence according to the model buff, and the model buff is updated during the decoding process; S3: When the characteristic code is the same as the end character, the encoding is ended and the lrc check is performed. If the lrc check passes, the decoding is deemed successful.
[0005] Furthermore, the traversing the acquired feature points and decoding the feature points to generate feature codes includes: S11: Start from the 0th extreme point and traverse backward until the Nth extreme point is found that meets the following requirements: Set the Nth extreme point subscript to P n , the N+1th extreme point is subscripted as P n+1 , the N+2th extreme point is subscripted as P n+2 , the N+3th extreme point is subscripted as Pn+3 , V n =P n+1 –P n , V n+1 =P n+2 –P n+1 , V n+2 =P n+3 –P n+2 , if V n 、V n+1 、V n+2 If the error is within 50%, it is determined that the Nth extreme point meets the starting requirements, and the cycle P=(P n+3 –P n ) / 3; Otherwise, repeat S11 and continue to traverse the next extreme point until an extreme point that meets the requirements is found; S12: According to the extreme point P that meets the starting requirements in step S11 a And period P predicts the next extreme point P r :P r =P a +P; S13: P a The extreme point after that and P r The nearest extreme point is taken as the newly located extreme point P b ; S14: According to P a and P b To decode: If P a and P b If the polarity is the same, the corresponding code is decoded as 1, otherwise it is decoded as 0; S15: Update the period P, P=P×2 / 3+(P b –P a ) / 3, and use the same method as S12-S15 to locate the next extreme point and decode it; S16: Compare the code with the preset starting character. If they are the same as the starting character, initialize the model buff and enter the character decoding phase. Otherwise, repeat S12-S16.
[0006] Furthermore, the initialization of the model buff includes: The model buff includes X array and Y array. The i-th data in the X array is X i , set the i-th data in the Y array to Y i , the starting characters are [a0, a1, a2, ..., a m ], m is the total length of the starting character bit, and the extreme point corresponding to the first bit a0 is subscripted as P0; The X array can be filled in the following ways: X0 is initialized to 0; Set the nth value in the X array to X n , start filling from X1, start from a0, if a i is 0, then: X n =X n-1 +2, X n+1 =X n +2, n=n+2, i=i+1; If a i If it is not 0, then: X n =X n-1 +1, X n+1 =X n +1, X n+2 =X n+1 +1, X n+3 =X n+2 +1, n=n+4, i=i+1; Repeat the above steps until the starting character is traversed; The Y array can be filled in the following ways: Y0 is the subscript P0 of the first extreme point among all extreme points that make up the starting character; After determining the total length of the X array, the subscripts of the consecutive n feature points after P0 are filled into Y1, Y2, Y3...Y in sequence. n middle.
[0007] Furthermore, the decoding of the feature points after the starting point in sequence according to the model buff includes: S21: Calculate the theoretical character period P and the subscript P of the theoretical next extreme point based on the initial model buff data i And the actual subscript T i ,include: ; Where P L is the extreme point of the previous cycle saved; S22: Among all the extreme feature points extracted, the subscript value is the same as P i The actual subscript value of the closest feature point is P n1 , similarly, the subscript value is the same as T i The actual subscript value of the closest feature point is P n2 ; S23: If P n1 and P n2 If the same, then P n1As a periodic characteristic point, determine the next extreme point after the extreme point; If the next extreme point has the same polarity as the current extreme point, it is encoded as 1, otherwise it is encoded as 0, and the model buff is updated; If P n1 and P n2 If they are not the same, then P n1 and P n2 Perform discrimination processing and decode according to the discrimination result.
[0008] Furthermore, the n1 and P n2 The discrimination processing includes: If the bit being decoded is the last bit of the character, set P n1 The code corresponding to the feature point of the previous cycle is r, P n2 The code corresponding to the feature point of the previous cycle is s. If r passes the parity check as the last bit of the character, P is taken. n1 As the periodic characteristic point, otherwise take P n2 As a periodic characteristic point, and determine the next extreme point after the extreme point; If the next extreme point has the same polarity as the current extreme point, it is encoded as 1, otherwise it is encoded as 0; If the bit being decoded is not the last bit, then get the number num of bits where the bit being decoded is located, and loop through all the preset characters whose first num bits are the same as the decoded bit; Substitute the character into the model buff and calculate the corresponding mean square error; The mean square error is calculated as: ; Where Len is the total amount of data filled in the X array corresponding to the character; Traverse all characters. If the mean square errors corresponding to all characters are greater than the preset threshold, the character decoding is deemed to have failed. Otherwise, the character corresponding to the minimum mean square error is used as the decoded character, and then the model buff is updated and the next character is decoded.
[0009] Furthermore, the updating of the model buff includes: S201: Find the data with a value of 4 in the X array and set it as the jth data in the X array; S202: Remove the 0th to j-1th data in the X array and the Y array, and update the data arrangement in the X array and the Y array; S203: Subtract 4 from the value of each data in the X array; S204: All feature points between the feature points newly located in this cycle and the feature points located in the previous cycle are filled to the end of the Y array in descending order according to the subscripts; S205: Assume that the value of the last valid data in the X array after the update is V. If the bit corresponding to this cycle is "1", V+1, V+2, V+3, and V+4 are sequentially filled into the tail of the X array. If the bit corresponding to this cycle is "0", V+2 and V+4 are sequentially filled into the tail of the X array.
[0010] On the other hand, the present invention further provides a computer-readable storage medium having a computer program stored thereon, wherein the program implements the above method when executed by a processor.
[0011] By adopting the above technical solution, the acquired feature points are first traversed and the feature points are decoded to generate feature codes, and the feature codes are compared with the preset starting characters. When the feature codes are the same as the starting characters, the model buff is initialized and the character decoding stage is entered. After that, the feature points corresponding to the starting characters are taken as the starting points, and the feature points after the starting points are decoded in sequence according to the model buff, and the model buff is updated during the decoding process. The model buff can be updated according to the real-time decoding process, and the updated model buff is used for decoding, thereby improving the decoding success rate. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure. In the accompanying drawings, the same or similar reference numerals represent the same or similar elements, among which:
[0013] Figure 1 The figure is a flow chart of a magnetic card decoding method based on an AMR sensor. DETAILED DESCRIPTION
[0014] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0015] Reference Figure 1 The embodiment of the present invention provides a magnetic card decoding method based on an AMR sensor, comprising the following steps: S1: traverse the acquired feature points and decode the feature points to generate feature codes, compare the feature codes with the preset starting characters, and when the feature codes are the same as the starting characters, initialize the model buff and enter the character decoding stage, wherein the feature points include the data points collected by the AMR sensor in the card swiping stage.
[0016] S2: Taking the feature point corresponding to the starting character as the starting point, the feature points after the starting point are decoded in sequence according to the model buff, and the model buff is updated during the decoding process.
[0017] S3: When the characteristic code is the same as the end character, the encoding is ended and the lrc check is performed. If the lrc check passes, the decoding is deemed successful.
[0018] Specifically, S1 includes: S11: Start from the 0th extreme point and traverse backward until the Nth extreme point is found that meets the following requirements: Set the Nth extreme point subscript to P n , the N+1th extreme point is subscripted as P n+1 , the N+2th extreme point is subscripted as P n+2 , the N+3th extreme point is subscripted as P n+3 , V n =P n+1 –P n , V n+1 =P n+2 –P n+1 , V n+2 =P n+3 –P n+2 , if V n 、V n+1 、V n+2 If the error is within 50%, it is determined that the Nth extreme point meets the starting requirements, and the cycle P=(P n+3 –P n ) / 3; Otherwise, repeat S11 and continue to traverse the next extreme point until an extreme point that meets the requirements is found; S12: According to the extreme point P that meets the starting requirements in step S11 a And period P predicts the next extreme point P r :P r =P a +P; S13: P a The extreme point after that and P r The nearest extreme point is taken as the newly located extreme point P b ; S14: According to P a and P bTo decode: If P a and P b If the polarity is the same, the corresponding code is decoded as 1, otherwise it is decoded as 0; S15: Update the period P, P=P×2 / 3+(P b –P a ) / 3, and use the same method as S12-S15 to locate the next extreme point and decode it; S16: Compare the code with the preset starting character. If they are the same as the starting character, initialize the model buff and enter the character decoding phase. Otherwise, repeat S12-S16.
[0019] In the above description, the same polarity means that both are local maximum values or local minimum values.
[0020] The initialization of the model buff includes: The model buff includes X array and Y array. The i-th data in the X array is X i , set the i-th data in the Y array to Y i , the starting characters are [a0, a1, a2, ..., a m ], m is the total length of the starting character bit, and the extreme point corresponding to the first bit a0 is subscripted as P0; The X array can be filled in the following ways: X0 is initialized to 0; Set the nth value in the X array to X n , start filling from X1, start from a0, if a i is 0, then: X n =X n-1 +2, X n+1 =X n +2, n=n+2, i=i+1; If a i If it is not 0, then: X n =X n-1 +1, X n+1 =X n +1, X n+2 =X n+1 +1, X n+3 =X n+2 +1, n=n+4, i=i+1; Repeat the above steps until the starting character is traversed; The Y array can be filled in the following ways: Y0 is the subscript P0 of the first extreme point among all extreme points that make up the starting character; After determining the total length of the X array, the subscripts of the consecutive n feature points after P0 are filled into Y1, Y2, Y3...Y in sequence. n middle.
[0021] The decoding of the feature points after the starting point in sequence according to the model buff includes: S21: Calculate the theoretical character period P and the subscript P of the theoretical next extreme point based on the initial model buff data i And the actual subscript T i ,include: ; Where P L is the extreme point of the previous cycle saved; Among them, after finding the starting character, the present invention uses the last 6 bits of the starting character, so P i =(6+1)×4b+a, if k bits are used, then P i =(k+1)×4b+a.
[0022] S22: Among all the extreme feature points extracted, the subscript value is the same as P i The actual subscript value of the closest feature point is P n1 , similarly, the subscript value is the same as T i The actual subscript value of the closest feature point is P n2 ; S23: If P n1 and P n2 If the same, then P n1 As a periodic characteristic point, determine the next extreme point after the extreme point; If the next extreme point has the same polarity as the current extreme point, it is encoded as 1, otherwise it is encoded as 0, and the model buff is updated; If P n1 and P n2 If they are not the same, then P n1 and P n2 Perform discrimination processing and decode according to the discrimination result.
[0023] The pair P n1 and P n2 The discrimination processing includes: If the bit being decoded is the last bit of the character, set P n1 The code corresponding to the feature point of the previous cycle is r, P n2 The code corresponding to the feature point of the previous cycle is s. If r passes the parity check as the last bit of the character, P is taken. n1 As the periodic characteristic point, otherwise take P n2As a periodic characteristic point, and determine the next extreme point after the extreme point; If the next extreme point has the same polarity as the current extreme point, it is encoded as 1, otherwise it is encoded as 0; If the bit being decoded is not the last bit, then get the number num of bits where the bit being decoded is located, and loop through all the preset characters whose first num bits are the same as the decoded bit; Substitute the character into the model buff and calculate the corresponding mean square error; The mean square error is calculated as: ; Where Len is the total amount of data filled in the X array corresponding to the character; Traverse all characters. If the mean square errors corresponding to all characters are greater than the preset threshold, the character decoding is deemed to have failed. Otherwise, the character corresponding to the minimum mean square error is used as the decoded character, and then the model buff is updated and the next character is decoded.
[0024] Substituting the character into the model buff specifically includes: The numerical filling of the X array of the model corresponding to this character is the same as the filling of the start character, except that the 0 and 1 bit streams of the start character are replaced by the 0 and 1 bit streams of this character. Let the total amount of data filled in the X array corresponding to this character be Len, then the subscript of the starting feature point corresponding to this character is taken as the first data, and then the X array is filled in the same way, and the subscript data of the Len feature points are filled into the Y array of the model buff in sequence.
[0025] The updating of the model buff includes: S201: Find the data with a value of 4 in the X array and set it as the jth data in the X array; S202: Remove the 0th to j-1th data in the X array and the Y array, and update the data arrangement in the X array and the Y array; S203: Subtract 4 from the value of each data in the X array; S204: All feature points between the feature points newly located in this cycle and the feature points located in the previous cycle are filled to the end of the Y array in descending order according to the subscripts; S205: Assume that the value of the last valid data in the X array after the update is V. If the bit corresponding to this cycle is "1", V+1, V+2, V+3, and V+4 are sequentially filled into the tail of the X array. If the bit corresponding to this cycle is "0", V+2 and V+4 are sequentially filled into the tail of the X array.
[0026] The embodiment of the present invention provides a magnetic card decoding method based on an AMR sensor. First, the acquired feature points are traversed and the feature points are decoded to generate feature codes. The feature codes are compared with a preset starting character. When the feature code is the same as the starting character, the model buff is initialized and the character decoding stage is entered. After that, the feature point corresponding to the starting character is used as the starting point, and the feature points after the starting point are decoded in sequence according to the model buff. The model buff is updated during the decoding process. The model buff can be updated according to the real-time decoding process, and the updated model buff is used for decoding, thereby improving the decoding success rate.
[0027] The present invention also provides a computer-readable storage medium on which a computer program is stored, characterized in that the program implements the above method when executed by a processor.
[0028] Those skilled in the art will appreciate that, unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as those generally understood by those skilled in the art in the art to which the present invention belongs. It should also be understood that terms such as those defined in general dictionaries should be understood to have meanings consistent with the meanings in the context of the prior art, and will not be interpreted with idealized or overly formal meanings unless specifically defined.
[0029] For the method embodiments, for the sake of simplicity, they are all described as a series of action combinations, but those skilled in the art should know that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.
[0030] It can be known from the description of the above implementation modes that those skilled in the art can clearly understand that the present application can be implemented by means of software plus a necessary general hardware platform. Based on such an understanding, the technical solution of the present application can be essentially or partly contributed to the prior art in the form of a software product, which can be stored in a storage medium such as ROM / RAM, a magnetic disk, an optical disk, etc., and includes several instructions for enabling a computer device (which can be a personal computer, a server or a network device, etc.) to execute the methods described in the various implementation modes of the present application or certain parts of the implementation modes.
[0031] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A magnetic card decoding method based on AMR sensor, characterized in that: include: S1: traverse the acquired feature points and decode the feature points to generate feature codes, compare the feature codes with the preset starting characters, and when the feature codes are the same as the starting characters, initialize the model buff and enter the character decoding stage, wherein the feature points include the data points collected by the AMR sensor in the card swiping stage; S2: Taking the feature point corresponding to the starting character as the starting point, the feature points after the starting point are decoded in sequence according to the model buff, and the model buff is continuously updated during the decoding process; S3: When the characteristic code is the same as the end character, the encoding is ended and the lrc check is performed. If the lrc check passes, the decoding is deemed successful.
2. The method according to claim 1, characterized in that The traversing of the acquired feature points and decoding the feature points to generate feature codes comprises: S11: Start from the 0th extreme point and traverse backward until the Nth extreme point is found that meets the following requirements: Set the Nth extreme point subscript to P n , the N+1th extreme point is subscripted as P n+1 , the N+2th extreme point is subscripted as P n+2 , the N+3th extreme point is subscripted as P n+3 , V n =P n+1 –P n , V n+1 =P n+2 –P n+1 , V n+2 =P n+3 –P n+2 , if V n 、V n+1 、V n+2 If the error is within 50%, it is determined that the Nth extreme point meets the starting requirements, and the cycle P=(P n+3 –P n ) / 3; Otherwise, repeat S11 and continue to traverse the next extreme point until an extreme point that meets the requirements is found; S12: According to the extreme point P that meets the starting requirements in step S11 a And period P predicts the next extreme point P r :P r =P a +P; S13: P a After the extreme point and P r The nearest extreme point is taken as the newly located extreme point P b ; S14: According to P a and P b To decode: If P a and P b If the polarity is the same, the corresponding code is decoded as 1, otherwise it is decoded as 0; S15: Update the period P, P=P×2 / 3+(P b –P a ) / 3, and use the same method as S12-S15 to locate the next extreme point and decode it; S16: Compare the code with the preset starting character. If they are the same as the starting character, initialize the model buff and enter the character decoding phase. Otherwise, repeat S12-S16.
3. The method according to claim 1, characterized in that The initialization of the model buff includes: The model buff includes X array and Y array. The i-th data in the X array is X i , set the i-th data in the Y array to Y i , the starting characters are [a0, a1, a2, ..., a m ], m is the total length of the starting character bit, and the extreme point corresponding to the first bit a0 is subscripted as P0; The X array can be filled in the following ways: X0 is initialized to 0; Set the nth value in the X array to X n , start filling from X1, start from a0, if a i is 0, then: X n =X n-1 +2,X n+1 =X n +2,n=n+2,i=i+1; If a i If it is not 0, then: X n =X n-1 +1,X n+1 =X n +1,X n+2 =X n+1 +1,X n+3 =X n+2 +1,n=n+4,i=i+1; Repeat the above steps until the starting character is traversed; The Y array can be filled in the following ways: Y0 is the subscript P0 of the first extreme point among all extreme points that make up the starting character; After determining the total length of the X array, the subscripts of the consecutive n feature points after P0 are filled into Y1, Y2, Y3...Y in sequence. n middle.
4. The method according to claim 1, characterized in that: The decoding of the feature points after the starting point in sequence according to the model buff includes: S21: Calculate the theoretical character period P and the subscript P of the theoretical next extreme point based on the initial model buff data i And the actual subscript T i ,include: ; Where P L is the extreme point of the previous cycle saved; S22: Among all the extreme feature points extracted, the subscript value is the same as P i The actual subscript value of the closest feature point is P n1 , similarly, the subscript value is the same as T i The actual subscript value of the closest feature point is P n2 ; S23: If P n1 and P n2 If the same, then P n1 As a periodic characteristic point, determine the next extreme point after the extreme point; If the next extreme point has the same polarity as the current extreme point, it is encoded as 1, otherwise it is encoded as 0, and the model buff is updated; If P n1 and P n2 If they are not the same, then P n1 and P n2 Perform discrimination processing and decode according to the discrimination result.
5. The method according to claim 4, characterized in that The pair P n1 and P n2 The discrimination processing includes: If the bit being decoded is the last bit of the character, set P n1 The code corresponding to the feature point of the previous cycle is r, P n2 The code corresponding to the feature point of the previous cycle is s. If r passes the parity check as the last bit of the character, P is taken. n1 As the periodic characteristic point, otherwise take P n2 As a periodic characteristic point, and determine the next extreme point after the extreme point; If the next extreme point has the same polarity as the current extreme point, it is encoded as 1, otherwise it is encoded as 0; If the bit being decoded is not the last bit, then get the number num of bits where the bit being decoded is located, and loop through all the preset characters whose first num bits are the same as the decoded bit; Substitute the character into the model buff and calculate the corresponding mean square error; The mean square error is calculated as: ; Where Len is the total amount of data filled in the X array corresponding to the character; Traverse all characters. If the mean square errors corresponding to all characters are greater than the preset threshold, the character decoding is deemed to have failed. Otherwise, the character corresponding to the minimum mean square error is used as the decoded character, and then the model buff is updated and the next character is decoded.
6. The method according to claim 4, characterized in that The updating of the model buff includes: S201: Find the data with a value of 4 in the X array and set it as the jth data in the X array; S202: Remove the 0th to j-1th data in the X array and the Y array, and update the data arrangement in the X array and the Y array; S203: Subtract 4 from the value of each data in the X array; S204: All feature points between the feature points newly located in this cycle and the feature points located in the previous cycle are filled to the end of the Y array in descending order according to the subscripts; S205: Assume that the value of the last valid data in the X array after the update is V. If the bit corresponding to this cycle is "1", V+1, V+2, V+3, and V+4 are sequentially filled into the tail of the X array. If the bit corresponding to this cycle is "0", V+2 and V+4 are sequentially filled into the tail of the X array.
7. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method described in any one of claims 1 to 6 is implemented.
