#include"stdio.h"
#include"string.h"
#define poly 0x1021
char original[1000];
char verified[1000];
unsigned short original_crc;
unsigned short verified_crc;
unsigned short original_text_length;
unsigned short verified_text_length;
int main()
{
void update_original_crc(unsigned short);
void update_verified_crc(unsigned short);
void augment_original_crc();
void augment_verified_crc();
unsigned short ch,i=0;
original_crc=0xffff;
verified_crc=0xffff;
original_text_length=0;
verified_text_length=0;
printf("enter original text:\n");
scanf("%s",original);
printf("enter verified text:\n");
scanf("%s",verified);
while((ch=original[i])!=0)
{
update_original_crc(ch);
i++;
original_text_length++;
}
i=0;
while((ch=verified[i])!=0)
{
update_verified_crc(ch);
i++;
verified_text_length++;
}
augment_original_crc();
augment_verified_crc();
printf("\n crc original text=%04x\n",original_crc);
printf("length of originaltext=%u\n",original_text_length);
printf("\n crc verified text=%04x\n",verified_crc);
printf("length of verified text=%u\n",verified_text_length);
if(original_crc!=verified_crc)
printf("data(crc)mismatched!\n");
else
printf("data(crc)matched!\n");
}
void update_original_crc(unsigned short ch)
{
unsigned short i,v,xor_flag;
v=0x80;
for(i=0;i<8;i++)
{
if(original_crc & 0x8000)
{
xor_flag=1;
}
else
{
xor_flag=0;
}
original_crc=original_crc<<1;
if(ch & v)
{
original_crc=original_crc^poly;
}
if(xor_flag)
{
original_crc=original_crc^poly;
}
v=v>>1;
}
}
void update_verified_crc(unsigned short ch)
{
unsigned short i,v,xor_flag;
v=0x80;
for(i=0;i<8;i++)
{
if(verified_crc & 0x8000)
{
xor_flag=1;
}
else
{
xor_flag=0;
}
verified_crc=verified_crc<<1;
if(ch & v)
{
verified_crc=verified_crc^poly;
}
if(xor_flag)
{
verified_crc=verified_crc^poly;
}
v=v>>1;
}
}
void augment_original_crc()
{
unsigned short i,xor_flag;
for(i=0;i<16;i++)
{
if(original_crc & 0x8000)
{
xor_flag=1;
}
else
{
xor_flag=0;
}
original_crc=original_crc<<1;
if(xor_flag)
{
original_crc=original_crc^poly;
}
}
}
void augment_verified_crc()
{
unsigned short i,xor_flag;
for(i=0;i<16;i++)
{
if(verified_crc & 0x8000)
{
xor_flag=1;
}
else
{
xor_flag=0;
}
verified_crc=verified_crc<<1;
if(xor_flag)
{
verified_crc=verified_crc^poly;
}
}
}
This entry was posted
at 4:43 AM
and is filed under
Networks-programs
. You can follow any responses to this entry through the
comments feed
.
Reverse Engineering :Subscribe Now
Zts - ZTS
DISCLAIMER
This Blog is ONLY for educational purposes,
and any such codes/snippets provided are to be executed on
your sole discretion. The author is not responsible for the codes.
and any such codes/snippets provided are to be executed on
your sole discretion. The author is not responsible for the codes.
Categories
- Amazing Links (2)
- Ebooks (2)
- Games (1)
- Hacking (49)
- Hardware (2)
- Networks-programs (12)
- virus (4)
- Web Info (4)
- Xp-Tricks (19)
Subscribe Now
Page Hits
Provided by website design company directory. |