Question: #include #include #include #include #include #include SDES.h / * customByte * InitialPerm ( customByte * byte ) ; customByte * Reverse ( customByte *

#include
#include
#include
#include
#include
#include "SDES.h"
/*customByte* InitialPerm(customByte* byte);
customByte* Reverse(customByte* byte);
char getChar(customByte* byte);
customByte* functionF(customByte* byte, customByte* key);
customByte* Expansion(customByte* byte);
customByte* XOR(customByte* first, customByte* second);
customByte* SBoxes(customByte* byte);
int conversionToInt(int one, int two);
customByte* conversionToBin(int num);
customByte* P4(customByte* halfByte);
customByte* LRSwaped(customByte* byte, customByte* right);
customByte* XOR4(customByte* first, customByte* second);
customByte* FinalPerm(customByte* byte);
int binaryToInt(customByte* binary);
void printByte(customByte* byte);*/
void parseKey(const char* keyString, int key[])
{
for (int i =0; i <10; i++){
key[i]= keyString[i]-'0';
}
}
int main(int argc, char *argv[])
{
bool decrypt = false;
char* fileName = NULL;
char* outputName = "cypher.bmp";
char* dOrE = NULL;
char* tempKey = NULL;
char key[11];
int keyArray[10]={1,0,1,0,1,0,1,0,1,0};
if(argc ==2){
fileName = argv[1];
}
else if (argc ==3){
fileName = argv[1];
outputName = argv[2];
}
else if (argc ==4){
fileName = argv[1];
outputName = argv[2];
dOrE = argv[3];
decrypt =(strcmp(dOrE,"d")==0);
}
else if (argc ==5){
fileName = argv[1];
outputName = argv[2];
dOrE = argv[3];
decrypt =(strcmp(dOrE,"d")==0);
strncpy(key, argv[4],10);
key[10]='\0';
parseKey(key, keyArray);
}
else {
fileName = "normal.bmp";
}
char mode[4];
do {
printf("Enter mode (ECB, CBC, CTR): ");
if (fgets(mode, sizeof(mode), stdin)!= NULL)
{
//Remove the newline character if present
mode[strcspn(mode,"
")]=0;
//Verify the mode is valid
if (strcmp(mode, "ECB")==0|| strcmp(mode,"CBC")==0|| strcmp(mode,"CTR")==0)
{
printf("Valid mode: %s
", mode);
break;
} else
{
printf("Invalid mode. Please choose ECB, CBC, or CTR.
");
}
}
else
{
printf("Error reading input
");
}
} while (1);
if (decrypt){
printf("
Decrypting %s
", fileName);
}
else {
printf("
Encrypting %s
", fileName);
}
FILE* picture;
FILE* cypher;
cypher = fopen(outputName,"wb");
if (!(picture = fopen(fileName,"rb")))
{
printf("%s is missing, program will now exit
", fileName);
return 1;
}
unsigned char header[54];
//Read the header
fread(header, sizeof(unsigned char),54, picture);
fwrite(header, sizeof(unsigned char),54, cypher);
//Get picture stats
int width =*(int*)&header[18];
int height =*(int*)&header[22];
short int bitPerPixel =*(short int*)&header[28];
int multiplier = bitPerPixel /8;
//Dealing with Padding Rules
if (width %4!=0)
{
width +=(4-(width %4));
}
int size = multiplier * width * height;
printf("SIZE: %d
", size);
unsigned char* pixelData =(unsigned char*)malloc(size);
//Reading Pixel Data
fread(pixelData, sizeof(unsigned char), size, picture);
fclose(picture);
//Generate keys
key_generation(keyArray);
//Decide which mode to implement
if (strcmp(mode, "ECB")==0)
{
for (int i=0; i>(7- j)) & 1;
}
customByte* processedData;
if(decrypt)
{
processedData = decryption(plaintext);
}
else
{
processedData = encryption(plaintext);
}
unsigned char processedByte =0;
for (int j=0; j<8; j++)
{
processedByte |=(processedData[j]<<(7- j));
}
fwrite(&processedByte, sizeof(unsigned char),1, cypher);
}
}
else if (strcmp(mode,"CBC")==0)
{
customByte iv[8]={1,1,1,0,1,1,0,1};
customByte previousCiphertext[8]={0};
for (int i =0; i < size; i++)//=8)
{
customByte plaintext[8];
unsigned char

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!