Thread: Hw help

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    1
    Rep Power
    0

    Hw help


    Hi everyone, I need some helps in my security class.

    this is the project:
    Write a program that calculates the CRC-16 of a given file and appends it to the end of the same file. Your program must also be able to verify the correctness of a given file that already has CRC appended at the end. Use the CRC polynomial x^16 + x^10 + x^8 + x^7 + x^3 + 1.

    C language is the only programming language that I know (and I'm not really gud at it) this project is too hard for me, and I dont know where to start

    This is the sample:

    The input file (hex): AB1245
    The input file (bin):
    1010 1011 0001 0010 0100 0101
    The polynomial that was used (binary bit string): 1 1111 1011
    We will append eight zeros at the end of the binary input.

    The binary string answer at each XOR step of CRC calculation:
    1010 1011 0001 0010 0100 0101 0000 0000
    0101 0110 1001 0010 0100 0101 0000 0000
    0010 1000 0101 0010 0100 0101 0000 0000
    0001 0111 0011 0010 0100 0101 0000 0000
    0000 1000 1000 0010 0100 0101 0000 0000
    0000 0111 0101 1010 0100 0101 0000 0000
    0000 0000 1011 0110 0100 0101 0000 0000
    0000 0000 0100 1011 1100 0101 0000 0000
    0000 0000 0011 0101 0000 0101 0000 0000
    0000 0000 0000 1010 0110 0101 0000 0000
    0000 0000 0000 0101 1011 1101 0000 0000
    0000 0000 0000 0010 0101 0001 0000 0000
    0000 0000 0000 0001 1010 0111 0000 0000
    0000 0000 0000 0000 0101 1100 0000 0000
    0000 0000 0000 0000 0010 0010 1100 0000
    0000 0000 0000 0000 0001 1101 1010 0000
    0000 0000 0000 0000 0000 0010 0001 0000
    0000 0000 0000 0000 0000 0001 1110 0110
    0000 0000 0000 0000 0000 0000 0001 1101

    Thus, the CRC is 0001 1101 (bin) = 1D (hex)
    CRC has been appended to the end of the input file.
    Reading input file again: AB12451D
    Closing input file.

    Thanks
  2. #2
  3. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,075
    Rep Power
    1802
    I am not sure where the "hadware" component is in this question!?

    There are many example CRC implementations on the internet.

    Here for example you will find the following:

    Code:
    /* Calculating XMODEM CRC-16 in 'C'
       ================================ */
    
    #define poly 0x1021
    
    /* On entry, addr=>start of data
                 num = length of data
                 crc = incoming CRC     */
    int crc16(char *addr, int num, int crc)
    {
    int i;
    
    for (; num>0; num--)              /* Step through bytes in memory */
      {
      crc = crc ^ (*addr++ << 8);     /* Fetch byte from memory, XOR into CRC top byte*/
      for (i=0; i<8; i++)             /* Prepare to rotate 8 bits */
      {
        if (crc & 0x10000)            /* b15 is set... */
          crc = (crc << 1) ^ poly;    /* rotate and XOR with XMODEM polynomic */
        else                          /* b15 is clear... */
          crc <<= 1;                  /* just rotate */
        }                             /* Loop for 8 bits */
      crc &= 0xFFFF;                  /* Ensure CRC remains 16-bit value */
      }                               /* Loop until num=0 */
      return(crc);                    /* Return updated CRC */
    }

    You will need to change the polynomial to suit your requirement, this example is the CCITT-16 polynomial:

    x^16+x^12+x^5+1 = (1) 0001 0000 0010 0001 = 0x1021

    Note that the x^16 component is implicit and not included in the constant. You need 0x02C5 in this case.
    Last edited by clifford; October 31st, 2012 at 04:59 AM.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    1
    Rep Power
    0

    Crc16 did u get it figured out yet ?


    any luck yet ?


    Originally Posted by emkhongleloi
    Hi everyone, I need some helps in my security class.
    hey did u get it figured out yet :)?
    this is the project:
    Write a program that calculates the CRC-16 of a given file and appends it to the end of the same file. Your program must also be able to verify the correctness of a given file that already has CRC appended at the end. Use the CRC polynomial x^16 + x^10 + x^8 + x^7 + x^3 + 1.

    C language is the only programming language that I know (and I'm not really gud at it) this project is too hard for me, and I dont know where to start

    This is the sample:

    The input file (hex): AB1245
    The input file (bin):
    1010 1011 0001 0010 0100 0101
    The polynomial that was used (binary bit string): 1 1111 1011
    We will append eight zeros at the end of the binary input.

    The binary string answer at each XOR step of CRC calculation:
    1010 1011 0001 0010 0100 0101 0000 0000
    0101 0110 1001 0010 0100 0101 0000 0000
    0010 1000 0101 0010 0100 0101 0000 0000
    0001 0111 0011 0010 0100 0101 0000 0000
    0000 1000 1000 0010 0100 0101 0000 0000
    0000 0111 0101 1010 0100 0101 0000 0000
    0000 0000 1011 0110 0100 0101 0000 0000
    0000 0000 0100 1011 1100 0101 0000 0000
    0000 0000 0011 0101 0000 0101 0000 0000
    0000 0000 0000 1010 0110 0101 0000 0000
    0000 0000 0000 0101 1011 1101 0000 0000
    0000 0000 0000 0010 0101 0001 0000 0000
    0000 0000 0000 0001 1010 0111 0000 0000
    0000 0000 0000 0000 0101 1100 0000 0000
    0000 0000 0000 0000 0010 0010 1100 0000
    0000 0000 0000 0000 0001 1101 1010 0000
    0000 0000 0000 0000 0000 0010 0001 0000
    0000 0000 0000 0000 0000 0001 1110 0110
    0000 0000 0000 0000 0000 0000 0001 1101

    Thus, the CRC is 0001 1101 (bin) = 1D (hex)
    CRC has been appended to the end of the input file.
    Reading input file again: AB12451D
    Closing input file.

    Thanks

    Comments on this post

    • clifford disagrees : You have the same assignment then!? Duplicating the OP in your post was entirely unnecessary. Did you try the answer already given?

IMN logo majestic logo threadwatch logo seochat tools logo