本文整理汇总了C++中CheckSum类的典型用法代码示例。如果您正苦于以下问题:C++ CheckSum类的具体用法?C++ CheckSum怎么用?C++ CheckSum使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CheckSum类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setCheckSum
void IPHeader::setCheckSum()
{
CheckSum sum;
sum(vhl,tos,len,id,flags_offset,ttl,proto.get(),src.get(),dst.get());
check_sum=sum.complete();
}
示例2: testCheckSum
bool IPHeader::testCheckSum() const
{
CheckSum sum;
sum(vhl,tos,len,id,flags_offset,ttl,proto.get(),check_sum,src.get(),dst.get());
return sum.test();
}
示例3: assert
void FileVerifier::AddFileForVerification(char *filename, bool requiredFile)
{
CheckSum checkSum;
FILE *fp;
unsigned i;
char *fileData;
FileWithCheckSum *fwcs;
#ifndef WIN32
#define _stat stat
#endif
struct _stat fileInfo;
if (filename==0 || strlen(filename)>=256)
{
assert(0);
return;
}
if (_stat(filename, &fileInfo)==-1)
{
printf("File could not be opened: %s\n", filename);
return;
}
printf("File added to verify list: %s\n", filename);
fp = fopen(filename, "rb");
#ifdef _DEBUG
assert(fp);
#endif
if (fp==0)
return;
fileData = new char [fileInfo.st_size];
fread(fileData, 1, fileInfo.st_size, fp);
fclose(fp);
for (i=0; (int)i < fileInfo.st_size; i++)
checkSum.Add((unsigned char)(fileData[i]));
delete [] fileData;
fwcs=new FileWithCheckSum;
strcpy(fwcs->fileName, filename);
fwcs->fileIsRequired=requiredFile;
fwcs->checkSum=checkSum.Get();
fileList.Insert(fwcs);
}
示例4: main
int main(int argc, char *argv[])
{
PNMreader reader(argv[1]);
Crop crop;
crop.SetRegion(300, 1400, 50, 400);
crop.SetInput(reader.GetOutput());
Transpose t;
t.SetInput(crop.GetOutput());
Invert i;
i.SetInput(t.GetOutput());
Color color(50, 1101, 0, 0, 128);
LRConcat lr;
lr.SetInput(color.GetOutput());
lr.SetInput2(i.GetOutput());
Color white(401, 1101, 255, 255, 255);
Checkerboard cb;
cb.SetInput(lr.GetOutput());
cb.SetInput2(white.GetOutput());
cb.GetOutput()->Update();
PNMwriter writer;
writer.SetInput(cb.GetOutput());
writer.Write(argv[2]);
CheckSum cs;
cs.SetInput(cb.GetOutput());
cs.OutputCheckSum();
Logger::Finalize();
}
示例5: main
int main(int argc, char *argv[])
{
if (argc < 2)
{
cerr << "Usage: " << argv[0] << " <username>" << endl;
exit(EXIT_FAILURE);
}
char event[1024];
sprintf(event, "Entered program from %s\n", argv[1]);
Logger::LogEvent(event);
/* START STUDENT MODIFIABLE SECTION */
PNMreader reader("../images/puddles.pnm");
Shrinker shrinker1;
Shrinker shrinker2;
LRConcat lrconcat1;
LRConcat lrconcat2;
TBConcat tbconcat1;
TBConcat tbconcat2;
Checkerboard blender;
shrinker1.SetInput(reader.GetOutput());
shrinker2.SetInput2(shrinker1.GetOutput());
lrconcat1.SetInput(shrinker1.GetOutput());
lrconcat1.SetInput2(shrinker2.GetOutput());
tbconcat1.SetInput(shrinker1.GetOutput());
tbconcat2.SetInput2(shrinker2.GetOutput());
blender.SetInput(reader.GetOutput());
blender.SetInput2(tbconcat1.GetOutput());
/* Make the image "finalImage" be the image at
the bottom of your pipeline */
Image *finalImage = blender.GetOutput();
/* END STUDENT MODIFIABLE SECTION */
try
{
finalImage->Update();
}
catch (DataFlowException &)
{
ofstream ofile("my_exception");
if (ofile.fail())
{
cerr << "Something is wrong ... can't open my_exception"
<< " for opening" << endl;
exit(EXIT_FAILURE);
}
ofile << "Exception found!" << endl;
exit(EXIT_SUCCESS);
}
CheckSum cs;
cs.SetInput(finalImage);
cs.OutputCheckSum("my_checksum");
if (argc == 3)
{
PNMwriter writer;
writer.SetInput(finalImage);
writer.Write("3H.pnm");
}
Logger::Finalize();
}
示例6: Encrypt
void DataBlockEncryptor::Encrypt( unsigned char *input, int inputLength, unsigned char *output, int *outputLength )
{
unsigned index, byteIndex, lastBlock;
unsigned long checkSum;
unsigned char paddingBytes;
unsigned char encodedPad;
unsigned char randomChar;
CheckSum checkSumCalculator;
#ifdef _DEBUG
assert( keySet );
#endif
assert( input && inputLength );
// randomChar will randomize the data so the same data sent twice will not look the same
randomChar = ( unsigned char ) randomMT();
// 16-(((x-1) % 16)+1)
// # of padding bytes is 16 -(((input_length + extra_data -1) % 16)+1)
paddingBytes = ( unsigned char ) ( 16 - ( ( ( inputLength + sizeof( randomChar ) + sizeof( checkSum ) + sizeof( encodedPad ) - 1 ) % 16 ) + 1 ) );
// Randomize the pad size variable
encodedPad = ( unsigned char ) randomMT();
encodedPad <<= 4;
encodedPad |= paddingBytes;
*outputLength = inputLength + sizeof( randomChar ) + sizeof( checkSum ) + sizeof( encodedPad ) + paddingBytes;
// Write the data first, in case we are overwriting ourselves
if ( input == output )
memmove( output + sizeof( checkSum ) + sizeof( randomChar ) + sizeof( encodedPad ) + paddingBytes, input, inputLength );
else
memcpy( output + sizeof( checkSum ) + sizeof( randomChar ) + sizeof( encodedPad ) + paddingBytes, input, inputLength );
// Write the random char
memcpy( output + sizeof( checkSum ), ( char* ) & randomChar, sizeof( randomChar ) );
// Write the pad size variable
memcpy( output + sizeof( checkSum ) + sizeof( randomChar ), ( char* ) & encodedPad, sizeof( encodedPad ) );
// Write the padding
for ( index = 0; index < paddingBytes; index++ )
*( output + sizeof( checkSum ) + sizeof( randomChar ) + sizeof( encodedPad ) + index ) = ( unsigned char ) randomMT();
// Calculate the checksum on the data
checkSumCalculator.add( output + sizeof( checkSum ), inputLength + sizeof( randomChar ) + sizeof( encodedPad ) + paddingBytes );
checkSum = checkSumCalculator.get();
// Write checksum
memcpy( output, ( char* ) & checkSum, sizeof( checkSum ) );
// AES on the first block
secretKeyAES128.encrypt16( output );
lastBlock = 0;
// Now do AES on every other block from back to front
for ( index = *outputLength - 16; index >= 16; index -= 16 )
{
for ( byteIndex = 0; byteIndex < 16; byteIndex++ )
output[ index + byteIndex ] ^= output[ lastBlock + byteIndex ];
secretKeyAES128.encrypt16( output + index );
lastBlock = index;
}
}
示例7: Decrypt
bool DataBlockEncryptor::Decrypt( unsigned char *input, int inputLength, unsigned char *output, int *outputLength )
{
unsigned index, byteIndex, lastBlock;
unsigned long checkSum;
unsigned char paddingBytes;
unsigned char encodedPad;
unsigned char randomChar;
CheckSum checkSumCalculator;
#ifdef _DEBUG
assert( keySet );
#endif
if ( input == 0 || inputLength < 16 || ( inputLength % 16 ) != 0 )
{
return false;
}
// Unchain in reverse order
for ( index = 16; ( int ) index <= inputLength - 16;index += 16 )
{
secretKeyAES128.decrypt16( input + index );
for ( byteIndex = 0; byteIndex < 16; byteIndex++ )
{
if ( index + 16 == ( unsigned ) inputLength )
input[ index + byteIndex ] ^= input[ byteIndex ];
else
input[ index + byteIndex ] ^= input[ index + 16 + byteIndex ];
}
lastBlock = index;
};
// Decrypt the first block
secretKeyAES128.decrypt16( input );
// Read checksum
memcpy( ( char* ) & checkSum, input, sizeof( checkSum ) );
// Read the pad size variable
memcpy( ( char* ) & encodedPad, input + sizeof( randomChar ) + sizeof( checkSum ), sizeof( encodedPad ) );
// Ignore the high 4 bytes
paddingBytes = encodedPad & 0x0F;
// Get the data length
*outputLength = inputLength - sizeof( randomChar ) - sizeof( checkSum ) - sizeof( encodedPad ) - paddingBytes;
// Calculate the checksum on the data.
checkSumCalculator.add( input + sizeof( checkSum ), *outputLength + sizeof( randomChar ) + sizeof( encodedPad ) + paddingBytes );
if ( checkSum != checkSumCalculator.get() )
return false;
// Read the data
if ( input == output )
memmove( output, input + sizeof( randomChar ) + sizeof( checkSum ) + sizeof( encodedPad ) + paddingBytes, *outputLength );
else
memcpy( output, input + sizeof( randomChar ) + sizeof( checkSum ) + sizeof( encodedPad ) + paddingBytes, *outputLength );
return true;
}
示例8: memset
void DataCheck::BeginTurn(void)
{
CheckSum *check;
CivArchive *archive;
sint32 i, j;
clock_t start, finish;
for(i=CRC_TYPE_MIN; i<CRC_TYPE_MAX; i++)
for (j=0; j<CRC_ARRAY_MAX; j++)
m_old_crc[i][j] = m_crc[i][j];
memset(&m_time, 0, CRC_TYPE_MAX * sizeof(uint32));
start = clock();
archive = new CivArchive();
archive->SetStore();
check = new CheckSum() ;
// No idea what was serialized here
check->AddData(archive->GetStream(), archive->StreamLen());
check->Done(m_crc[CRC_TYPE_GLOBAL][CRC_ARRAY_0], m_crc[CRC_TYPE_GLOBAL][CRC_ARRAY_1], m_crc[CRC_TYPE_GLOBAL][CRC_ARRAY_2], m_crc[CRC_TYPE_GLOBAL][CRC_ARRAY_3]);
delete archive;
delete check;
finish = clock();
m_time[CRC_TYPE_GLOBAL] = finish - start;
// should be replaced by:
// CHECK_DB(???, CRC_TYPE_GLOBAL);
CHECK_DB(g_rand, CRC_TYPE_RAND);
start = clock();
archive = new CivArchive();
archive->SetStore();
check = new CheckSum();
// Fill in missing databases
g_theAdvanceDB->Serialize(*archive);
g_theAdvanceBranchDB->Serialize(*archive);
g_theAdvanceListDB->Serialize(*archive);
g_theAgeDB->Serialize(*archive);
g_theAgeCityStyleDB->Serialize(*archive);
g_theBuildListSequenceDB->Serialize(*archive);
g_theCitySizeDB->Serialize(*archive);
g_theCityStyleDB->Serialize(*archive);
g_theCivilisationDB->Serialize(*archive);
g_theConstDB->Serialize(*archive); // Old database
g_theDifficultyDB->Serialize(*archive);
g_theDiplomacyDB->Serialize(*archive);
g_theDiplomacyProposalDB->Serialize(*archive);
g_theDiplomacyThreatDB->Serialize(*archive);
g_theEndGameObjectDB->Serialize(*archive);
g_theGoalDB->Serialize(*archive);
g_theGovernmentDB->Serialize(*archive);
g_theIconDB->Serialize(*archive);
g_theImprovementListDB->Serialize(*archive);
g_theMapIconDB->Serialize(*archive);
g_theMapDB->Serialize(*archive);
g_theOrderDB->Serialize(*archive);
g_theUVDB->Serialize(*archive); // Old database
g_thePersonalityDB->Serialize(*archive);
g_thePollutionDB->Serialize(*archive);
g_thePopDB->Serialize(*archive);
g_theResourceDB->Serialize(*archive);
g_theRiskDB->Serialize(*archive);
g_theSoundDB->Serialize(*archive);
g_theSpecialAttackInfoDB->Serialize(*archive);
g_theSpecialEffectDB->Serialize(*archive);
g_theSpriteDB->Serialize(*archive);
g_theStrategyDB->Serialize(*archive);
g_theTerrainDB->Serialize(*archive);
g_theUnitDB->Serialize(*archive);
g_theUnitBuildListDB->Serialize(*archive);
g_theWonderDB->Serialize(*archive);
g_theWonderBuildListDB->Serialize(*archive);
check->AddData(archive->GetStream(), archive->StreamLen());
check->Done(m_crc[CRC_TYPE_DB][CRC_ARRAY_0], m_crc[CRC_TYPE_DB][CRC_ARRAY_1], m_crc[CRC_TYPE_DB][CRC_ARRAY_2], m_crc[CRC_TYPE_DB][CRC_ARRAY_3]);
delete archive;
delete check;
finish = clock();
m_time[CRC_TYPE_DB] = finish - start;
// Continue with single database check
start = clock();
archive = new CivArchive();
archive->SetStore();
check = new CheckSum();
// g_theProfileDB->Serialize(*archive);
check->AddData(archive->GetStream(), archive->StreamLen());
check->Done(m_crc[CRC_TYPE_PROFILE_DB][CRC_ARRAY_0], m_crc[CRC_TYPE_PROFILE_DB][CRC_ARRAY_1], m_crc[CRC_TYPE_PROFILE_DB][CRC_ARRAY_2], m_crc[CRC_TYPE_PROFILE_DB][CRC_ARRAY_3]);
delete archive;
delete check;
finish = clock();
m_time[CRC_TYPE_PROFILE_DB] = finish - start;
//.........这里部分代码省略.........