Home  Contents

magstripe.decode

Magstripe Core4 Lua Event System

SYNOPSIS

data, resultcode = magstripe.decode(tracknr, rawdata[, flags])

DESCRIPTION

This function takes the raw magnetic stripe bits rawdata and tries to decode them according to the ISO standard encoding for track tracknr.

If the trackdata is partially garbled, the function will still provide the data that could be decoded properly. In case of garbled data however, the LRC checksum cannot be checked.

Each character in the string flags controls the parsing direction of the bitstream:

  • 'F': Forward scan. Start with the first bit of rawdata and proceed forward.
  • 'R': Reverse scan. Start with the last bit of rawdata and proceed backward.
  • '7': First bit of trackdata is in bit 7 of the first byte. (Otherwise, first bit is in bit 0.)

When both 'F' and 'R' are given, the decoder runs both directions after another, forward first, reverse second. When using swipe readers, this allows the user to swipe the card in any direction.

The flags parameter defaults to 'F' when not specified.

This is the reverse function of magstripe.encode().

RETURN VALUE

Returns two values: data is a string with the decoded data, including the start, end and checksum characters. The second value, resultcode indicates how sucessful the decode was.

resultcode Description
0 Decode was successful
20 No start character seen
21 No end character seen
23 LRC checksum incorrect
24 Parity error

On error, the value data contains all characters that could be decoded up until the error position.

SEE ALSO