# Cyclic Redundancy Check Simulation

## WHAT IS IT?

This model demonstrates sending a message using Cyclic Redundancy Check (CRC). CRC is a commonly used error detection technique.

## HOW IT WORKS

A generator is chosen randomly from a list of allowed generators, and a random message created. The message is padded with zeroes (one less than the number of bits in the generator). This new message is divided by the generator by using modulo 2 arithmetic, which is the same as XOR. If the remainder is more than one digit less than the generator, then the front of it is padded with zeroes so that it is exactly one digit less than the generator. The new remainder is added onto the end of the original message and this is the packet to be sent.

## HOW TO USE IT

The setup button generates a random message and selects a random generator.

The slow-motion slider is an easy way to adjust the speed of the display. Set it to zero if you want to just see the answer quickly. 0.2 is a good setting for most purposes.

The step button does whatever step comes next, and then stops so you can take notes.

The go button finishes the entire problem, at a speed set by the slow-motion slider.

The show-again button starts the exact problem from the beginning. You may then click either the step button or the go button to see the same demonstration.

The quiz button generates a random problem and then asks you to determine the answer. Please note that you can use the show-again button after a quiz to see all the steps in getting the correct answer.

## THINGS TO NOTICE

When the orignal message is all zeroes, the CRC remainder added is also all zeroes.

The CRC remainder will always be on fewer bit than the generator.

When you bring down the generator, it moves over until its leftmost 1 is under the leftmost one on the line above. Enough bits on the right are brought down so that the line above extends to the same column as the rightmost 1 of the generator.

All generators begin and end with a 1. That is because leading zeroes are stripped, and the mathematical theory behind how CRC works insists that generators be odd, and prefers them to be prime. With a prime generator, a generator of length n can detect all burst errors of length (n - 1) and will detect many errors of longer lengths. If an even generator is used, then we can not be certain to detect all burst errors of length (n - 1).

## THINGS TO TRY

Set the slow-motion slider to about .2 seconds (or slower) and press the step button several times. Watch the demonstration of each step.

Set the slow-motion slider to about .2 seconds and press the go button. Watch the entire demonstration.

Do each step by hand, then press step to check your work.

## EXTENDING THE MODEL

Allow the user to input the beginning message.

Allow the user to input the generator.

## NETLOGO FEATURES

"min-one-of" reports the agent in the agentset that reports the lowest value for the given reporter.

"max-one-of" reports the agent in the agentset that reports the highest value for the given reporter.

"count" reports the number of agents in the given agentset.

## CREDITS AND REFERENCES

This model was written by Crystal Barchet and Teresa Carrigan, 2004.

Permission to use, modify or redistribute this model is hereby granted, provided that both of the following requirements are followed:

1. this copyright notice is included.
2. this model will not be redistributed for profit without permission from Teresa Carrigan.
Contact Teresa Carrigan for appropriate licenses for redistribution for profit.

To refer to this model in academic publications, please use: Barchet, C. and Carrigan, T. (2004). Cyclic Redundancy Check Simulation Blackburn College, Carlinville, IL.