doubt in Block cipher encryption and decryption

Jun 11, 2011 at 10:32am
hi my assignment is to make a block cipher encryption and decryption. And made the codings with mode ECB. It is encryption part works correctly for all blocks but the decryption part fails at the last block. Plz tell me if i had made any mistake in encryption and decryption part.
Encryption part :
bufferlen = filesize;
buffer = new BYTE [ bufferlen ];
feof = false;
do {
count = fread(buffer, 1, 16, filepointer);
if ( count < 16 ) {
feof = true;
}
cout << count;
result = CryptEncrypt(hGenKey,NULL,feof,0,buffer,&count,bufferlen);
if ( result == 0 ) {
cout << "\nencrypt failed";
}
else {
cout << "encrypt passed";
}
if(fwrite(buffer, 1, count , filepointer1)!=count) {
cout << "\nwrite failed";
}
} while (feof != true);

Decryption part:
bufferlen = filesize;
buffer = new BYTE [ bufferlen ];
feof = false;
do {
count = fread(buffer, 1, 16, filepointer);
if ( count < 16 || (ftell( filepointer ) == filesize) ) {
feof = true;
}
cout << count;
result = CryptDecrypt(hGenKey,NULL,feof,0,buffer,&count);
if ( result == 0 ) {
cout << "\ndecrypt failed";
}
else {
cout << "decrypt passed";
}
if(fwrite(buffer, 1, count , filepointer1)!=count) {
cout << "\nwrite failed";
}
} while ( feof != true );
Last edited on Jun 11, 2011 at 10:33am
Topic archived. No new replies allowed.