Question: Help with a c programming assignment: Project: The objective of this program is to decode a bit-stream of ones and zeros from the output of

Help with a c programming assignment:

Project:

The objective of this program is to decode a bit-stream of ones and zeros from the output of a magnetic stripe. These magnetic stripes may be found on charge cards, or other cards that contain information regarding the user embedded in the stripe. Normally an electronic device would scan the given card and provide this bit-stream to another system to allow for its decoding. This goal of this program is to decode this bit-stream into two numeric strings.

Details:

The Mag-Stripe Decoding program will accept a string of ones and zeros (ASCII ones and zeros, not binary). The program will decode this string into two values. One is the account number, which is 10 digits in length, and the other value, is additional data, which is also a numeric string (ASCII numbers). Each digit contains five bits. The format of the input strings is as follows:

Noise

SS

Primary Account Number

FS

Additional Data

ES

LRC

Noise

Where:

Noise: This fields contains 1 or more digits of noise (skip through this area while looking for the SS token)

SS: This field is the Start Sentinel. It indicates the start of the Mag-Stripe data. If the Mag-Stripe data does not begin with a Start Sentinel, it must be rejected.

Primary Account Number: This field must contain 10 digits, which is the account number. If it does not contain exactly 10 digits, the Mag-Stripe data must be rejected.

FS: This field or Token is known as the Field Separator. It separates the Primary Account Number from the Additional Data field. If this token does not separate these two data fields, the Mag-Stripe data must be rejected.

Additional Data: This field contains additional data regarding the user. It must contain between six to 12 digits. If it does not, the Mag-Stripe data must be rejected.

ES: This field or Token is known as the End Sentinel. It indicates the end of the Mag-Stripe data. If this field is not present at the end of the Mag-Stripe data, it must be rejected.

LRC: This field is known as the Longitudinal Redundancy Check. It is used for error detection. It is just an exclusive Oring of all the fields with the exception of the LRC field. If the calculated LRC does not match the LRC field, the MagStripe data must be rejected.

The following Table describes how to decode each digit.

Character

Binary Value

Digit

Parity

B4

B3

B2

B1

0

0

1

0

0

0

0

1

1

0

0

0

0

1

2

2

0

0

0

1

0

3

3

1

0

0

1

1

4

4

0

0

1

0

0

5

5

1

0

1

0

1

6

6

1

0

1

1

0

7

7

0

0

1

1

1

8

8

0

1

0

0

0

9

9

1

1

0

0

1

Not Used

10

1

1

0

1

0

Start

Sentinel

11

0

1

0

1

1

Not Used

12

1

1

1

0

0

Field

Separator

13

0

1

1

0

1

Not Used

14

0

1

1

1

0

End

Sentinel

15

1

1

1

1

1

Each digit or token is 5 bits in length. A bit is either a 1 or a 0. The MagStripe data will be given as a character string of 1s and 0s. As the program extracts each digit, it may be easier to convert the digit string into a binary value.

for example:

Note the order of the decoding table; the bit B1 is the first bit to the left. The Bit B2 is the second to the left, and so on. For decoding the digit 8 would be:

00010.

0

0

0

1

0

B1

B2

B3

B4

Parity

Example decoding the Start Sentinel:

11010.

1

1

0

1

0

B1

B2

B3

B4

Parity

The LRC is calculated by Exclusive oring all of the bits using a byte (eight bit value). The Exclusive or operation will set each bit position to a one if the two bits compared are different, or a zero if they are the same. For Example:

01010101 (Exclusive Or these two values)

00010011

------------

01000110 (Result)

Sample Code:

unsigned char CalcLRC(unsigned char * buff, int len)

{ unsigned char LrcValue;

int i;

LrcValue = *buff; buff++;

for(i = 1; i < len; i++)

{

LrcValue ^= *buff; buff++;

}

return(LrcValue);

}

Sample Data:

Account = "0123456789";

AddData ="012345678901";

BitStream:

"11010000011000001000110010010010101011011110000010100111011000001100000 10001100100100101010110111100000101001100001100001111100010";

The specifics of the program implementation are up to the student. The only required function is the decodeStripe()

bool decodeStripe(char *stripe)

The decodeStripe() function will actually decode the magstripe. It will accept a single parameter the magstripe data string (NULL terminated). If the Mag-Stripe data string is not decoded correctly, it will return 0, otherwise 1 is return for success. This function will also print out the primary number and additional data.

Requirements:

Write your own main for testing your code. I will use my main for testing your code. Please test your code thoroughly.

Implement the decodeStripe() function as specified above.

The Mag-Stripe Data needs to be correctly decoded and checked for errors. Verify all tokens are present and in their correct location, verify parity on all digits and tokens, and verify that the LRC field matches the LRC calculated on the Mag-Stripe data. Also verify that the correct number of digits for the two data fields AccountNumber and Additional Data are correct.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!