C program to implement Cyclic Redundancy Check(CRC)

Written by siddhartha. Posted in Computer Networks

Source Code

/*************************************************************************************/
/*  C program to implement Cyclic Redundency Check.*/
/*  Download more programs at http://sourcecode4u.com/ */
/*************************************************************************************/
#include <stdio.h>
#include <stdlib.h>
main()
{
  int i, j, n, g, a, ms[20], gen[20], b[20], q[20], s;
  printf("transmiter side");
  printf("enter no of data bits");
  scanf("%d", &n);
  printf("enter data");
  for (i = 0; i < n; i++)
    scanf("%d", &ms[i]);
  printf("enter size of generator");
  scanf("%d", &g);
  printf("enter generator");
  for (j = 0; j < g; j++)
    scanf("%d", &gen[j]);
  printf("\n \t the generated matrix");
  for (j = 0; j < g; j++)
    printf("%d", gen[j]);
  a = n + (g - 1);
  printf("\t \n the appended matrix is::");
  for (i = 0; i < j; i++)
    ms[n + i] = 0;
  for (i = 0; i < a; i++)
    printf("%d", ms[i]);
  for (i = 0; i < n; i++)
    q[i] = ms[i];
  for (i = 0; i < n; i++)
  {
    if (ms[i] == 0)
    {
      for (j = i; j < g + i; j++)
      {
        ms[j] = ms[j] ^ 0;
      }
    }
    else

    {
      ms[i] = ms[i] ^ gen[0];
      ms[i + 1] = ms[i + 1] ^ gen[1];
      ms[i + 2] = ms[i + 2] ^ gen[2];
      ms[i + 3] = ms[i + 3] ^ gen[3];
    }
  }
  printf("\n \t the crc is::");
  for (i = n; i < a; i++)
    printf("%d", ms[i]);
  s = n + a;
  for (i = n; i < s; i++)
    q[i] = ms[i];
  printf("\n");
  for (i = 0; i < a; i++)
    printf("%d", q[i]);
}

Out Put

BLOG COMMENTS POWERED BY DISQUS