Professional Documents
Culture Documents
CS609 Solution by Junaid
CS609 Solution by Junaid
JUNAID MALIK
0304-1659294
CS619-519
PROJECT+INTERNSHIP
AL-JUNAID TECH INSTITUTE
CS609 Assignment
#include <stdio.h>
#include <windows.h>
#include <wincrypt.h>
#include <stdbool.h>
#include <string.h>
#define AES_BLOCK_SIZE 16
void printUsage();
if (argc < 3) {
printUsage();
return 1;
char destFile[MAX_PATH];
char password[256];
if (strcmp(command, "encrypt") == 0) {
AL-JUNAID TECH INSTITUTE
printf("Enter encryption password: ");
scanf("%s", password);
printf("Enter destination file path (or press 's' for same path as source): ");
scanf("%s", destFile);
if (strcmp(destFile, "s") == 0) {
strcpy(destFile, sourceFile);
} else {
handleError("Encryption failed.");
scanf("%s", password);
printf("Enter destination file path (or press 's' for same path as source): ");
scanf("%s", destFile);
if (strcmp(destFile, "s") == 0) {
strcpy(destFile, sourceFile);
} else {
handleError("Decryption failed.");
}
AL-JUNAID TECH INSTITUTE
} else {
printUsage();
return 1;
return 0;
if (!source) {
return false;
if (!dest) {
fclose(source);
return false;
HCRYPTPROV hCryptProv;
HCRYPTKEY hKey;
fclose(source);
fclose(dest);
fclose(source);
fclose(dest);
CryptReleaseContext(hCryptProv, 0);
return false;
fclose(source);
fclose(dest);
CryptDestroyHash(hKey);
CryptReleaseContext(hCryptProv, 0);
return false;
BYTE buffer[1024];
BOOL success;
if (!success) {
fclose(source);
AL-JUNAID TECH INSTITUTE
fclose(dest);
CryptDestroyHash(hKey);
CryptReleaseContext(hCryptProv, 0);
handleError("Encryption failed.");
return false;
if (bytesWritten != bytesRead) {
fclose(source);
fclose(dest);
CryptDestroyHash(hKey);
CryptReleaseContext(hCryptProv, 0);
return false;
fclose(source);
fclose(dest);
CryptDestroyHash(hKey);
CryptReleaseContext(hCryptProv, 0);
return true;
}
AL-JUNAID TECH INSTITUTE
void handleError(const char *message) {
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
LocalFree(lpMsgBuf);
void printUsage() {