C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 29th, 2012, 09:23 PM
emkhongleloi emkhongleloi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 1 emkhongleloi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 58 sec
Reputation 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

Reply With Quote
  #2  
Old October 31st, 2012, 04:15 AM
clifford's Avatar
clifford clifford is offline
Contributing User
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Aug 2003
Location: UK
Posts: 4,824 clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Days 21 h 1 m
Reputation Power: 1800
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.

Reply With Quote
  #3  
Old November 9th, 2012, 04:10 PM
alex10 alex10 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 1 alex10 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 14 sec
Reputation Power: 0
Crc16 did u get it figured out yet ?

any luck yet ?


Quote:
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?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Hw help

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap