📄 repvir.cpp
字号:
# include "dos.h"
# include "dir.h"
# include "stdlib.h"
# include "iostream.h"
# include "fstream.h"
# include "conio.h"
# define OK 0
# define Cancel 255
unsigned int ChkCRC(char * filename,unsigned int FileCRC);
void main(void)
{
ifstream Result("CRCSUM.DAT");
char FileName[13];
unsigned int FileCRC;
unsigned int CRC;
if(Result)//The file crcsum.dat exist.
{
Result>>FileName>>FileCRC;
while(!Result.eof())
{
CRC=ChkCRC(FileName,FileCRC);
switch(CRC)
{
case OK:
cout<<FileName<<" Ok!"<<endl;
break;
case Cancel:
cout<<FileName<<" Not Found! Press any key to continue..."<<endl;
getch();
break;
default:
cout<<FileName<<" CRC Error! Press any key to continue..."<<endl;
getch();
break;
}
Result>>FileName>>FileCRC;
}
}
}
unsigned int ChkCRC(char * filename,unsigned int FileCRC)
{
static unsigned long Gx=0x18005;//The IBM generate polynomial
static unsigned long ChkSum=0;
static unsigned int CRC=0xaa;
static unsigned int TmpCRC;
unsigned char tmp;
struct ffblk Fblk;
int i;
ifstream ChkFile;
Gx=0x18005;
ChkSum=0;
CRC=0;
TmpCRC=FileCRC;
if(!findfirst(filename,&Fblk,FA_ARCH|FA_RDONLY))
{
ChkFile.open(filename,ios::binary);
if(Fblk.ff_fsize>=3)
{
tmp=ChkFile.get();
ChkSum|=tmp;
ChkSum<<=8;
tmp=ChkFile.get();
ChkSum|=tmp; //Read 2 byte for deviding soon
tmp=ChkFile.get();
do
{
for(i=0;i<8;i++)//move the next bits to value ChkSum
{
ChkSum<<=1;
if(tmp&0x80)
ChkSum|=1;
tmp<<=1;
if(ChkSum & 0x10000)
{
CRC=ChkSum^Gx;
ChkSum=CRC;
}
}
tmp=ChkFile.get();
}while(!ChkFile.eof());
TmpCRC>>=8;
tmp=TmpCRC;//get the high 8 bits of FileCRC
for(i=0;i<8;i++)//Calculate the CRC
{
ChkSum<<=1;
if(tmp&0x80)
ChkSum|=1;
tmp<<=1;
if(ChkSum & 0x10000)
{
CRC=ChkSum^Gx;
ChkSum=CRC;
}
}
TmpCRC=FileCRC;
TmpCRC&=0xff;
tmp=TmpCRC;//get the low 8 bits of FileCRC
for(i=0;i<8;i++)//Calculate the CRC
{
ChkSum<<=1;
if(tmp&0x80)
ChkSum|=1;
tmp<<=1;
if(ChkSum & 0x10000)
{
CRC=ChkSum^Gx;
ChkSum=CRC;
}
}
CRC=ChkSum;
return(CRC);
}
else //the length of file >=2
{
for(i=0;i<Fblk.ff_fsize;i++)
{
ChkSum<<=8*i;
tmp=ChkFile.get();
ChkSum|=tmp;
}
TmpCRC=FileCRC;
TmpCRC>>=8;
tmp=TmpCRC;//get the high 8 bits of FileCRC
for(i=0;i<8;i++)//Calculate the CRC
{
ChkSum<<=1;
if(tmp&0x80)
ChkSum|=1;
tmp<<=1;
if(ChkSum & 0x10000)
{
CRC=ChkSum^Gx;
ChkSum=CRC;
}
}
TmpCRC=FileCRC;
TmpCRC&=0xff;
tmp=TmpCRC;//get the low 8 bits of FileCRC
for(i=0;i<8;i++)//Calculate the CRC
{
ChkSum<<=1;
if(tmp&0x80)
ChkSum|=1;
tmp<<=1;
if(ChkSum & 0x10000)
{
CRC=ChkSum^Gx;
ChkSum=CRC;
}
}
CRC=ChkSum;
return(CRC);
}
}
else
return(Cancel);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -