Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse Credit Card input from Magnetic Stripe

Tags:

Does anyone know how to parse a credit card string input from a Magnetic Card Swiper?

I tried a JavaScript parser but never got it to work. This is what the input looks like.

%BNNNNNNNNNNNNNNNN^DOE/JOHN ^1210201901000101000100061000000?;NNNNNNNNNNNNNNNN=12102019010106111001? 

The N's are the credit card number.

like image 346
Chase Florell Avatar asked Jan 23 '10 02:01

Chase Florell


People also ask

What information is stored on a credit card magnetic stripe?

These tracks contain the credit card account number, name, expiration date, service code, and card verification code. Credit cards primarily or exclusively use the first two tracks. The third track sometimes contains additional information such as a country code or currency code.

How does the magnetic stripe on a credit card work?

Magnetic Stripe Cards This standard tape strip contains three magnetic tracks that are used to store the card's code data. The card is usually presented to the reader by swiping or inserting it into the reader, which obtains the card's code using a magnetic head that detects the magnetic field generated by its strip.

What is a device used to read magnet stripe reader for cards?

A magnetic stripe reader, also called a magstripe reader, is a hardware device that reads the information encoded in the magnetic stripe located on the back of a plastic badge.


2 Answers

See the Magnetic Stripe Card entry @ Wikipedia:


Track one, Format B:

  • Start sentinel — one character (generally '%')
  • Format code="B" — one character (alpha only)
  • Primary account number (PAN) — up to 19 characters. Usually, but not always, matches the credit card number printed on the front of the card.
  • Field Separator — one character (generally '^')
  • Name — two to 26 characters
  • Field Separator — one character (generally '^')
  • Expiration date — four characters in the form YYMM.
  • Service code — three characters
  • Discretionary data — may include Pin Verification Key Indicator (PVKI, 1 character), PIN Verification Value (PVV, 4 characters), Card Verification Value or Card Verification Code (CVV or CVK, 3 characters)
  • End sentinel — one character (generally '?')
  • Longitudinal redundancy check (LRC) — one character (Most reader devices do not return this value when the card is swiped to the presentation layer, and use it only to verify the input internally to the reader.)

I hope the data is fake, otherwise Anyone could get the:

  • Name
  • Expiration Date
  • CVV

And I'm not sure but I think the credit card number (or # of possibilities) can be computed using the LRC.

like image 108
Alix Axel Avatar answered Oct 07 '22 14:10

Alix Axel


I did you one better: I made a video showing how to do exactly this with ASP.Net/c#:

http://www.markhagan.me/Samples/CreditCardSwipeMagneticStripProcessing

Here is the section of code that you probably care about:

    protected void CardReader_OTC(object sender, EventArgs e)     {         bool CaretPresent = false;         bool EqualPresent = false;          CaretPresent = CardReader.Text.Contains("^");         EqualPresent = CardReader.Text.Contains("=");          if (CaretPresent)         {             string[] CardData = CardReader.Text.Split('^');             //B1234123412341234^CardUser/John^030510100000019301000000877000000?              PersonName.Text = FormatName(CardData[1]);             CardNumber.Text = FormatCardNumber(CardData[0]);             CardExpiration.Text = CardData[2].Substring(2, 2) + "/" + CardData[2].Substring(0, 2);         }         else if (EqualPresent)         {             string[] CardData = CardReader.Text.Split('=');             //1234123412341234=0305101193010877?              CardNumber.Text = FormatCardNumber(CardData[0]);             CardExpiration.Text = CardData[1].Substring(2, 2) + "/" + CardData[1].Substring(0, 2);         }     } 

The complete code is on that website I linked above.

like image 22
Mark Hagan Avatar answered Oct 07 '22 16:10

Mark Hagan