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 InitialPermcustomByte byte;
customByte ReversecustomByte byte;
char getCharcustomByte byte;
customByte functionFcustomByte byte, customByte key;
customByte ExpansioncustomByte byte;
customByte XORcustomByte first, customByte second;
customByte SBoxescustomByte byte;
int conversionToIntint one, int two;
customByte conversionToBinint num;
customByte PcustomByte halfByte;
customByte LRSwapedcustomByte byte, customByte right;
customByte XORcustomByte first, customByte second;
customByte FinalPermcustomByte byte;
int binaryToIntcustomByte binary;
void printBytecustomByte byte;
void parseKeyconst char keyString, int key
for int i ; i ; i
keyi keyStringi;
int mainint argc, char argv
bool decrypt false;
char fileName NULL;
char outputName "cypher.bmp;
char dOrE NULL;
char tempKey NULL;
char key;
int keyArray;
ifargc
fileName argv;
else if argc
fileName argv;
outputName argv;
else if argc
fileName argv;
outputName argv;
dOrE argv;
decrypt strcmpdOrEd;
else if argc
fileName argv;
outputName argv;
dOrE argv;
decrypt strcmpdOrEd;
strncpykey argv;
key;
parseKeykey keyArray;
else
fileName "normal.bmp;
char mode;
do
printfEnter mode ECB CBC CTR: ;
if fgetsmode sizeofmode stdin NULL
Remove the newline character if present
modestrcspnmode
;
Verify the mode is valid
if strcmpmode "ECB" strcmpmodeCBC strcmpmodeCTR
printfValid mode: s
mode;
break;
else
printfInvalid mode. Please choose ECB, CBC or CTR
;
else
printfError reading input
;
while ;
if decrypt
printf
Decrypting s
fileName;
else
printf
Encrypting s
fileName;
FILE picture;
FILE cypher;
cypher fopenoutputNamewb;
if picture fopenfileNamerb
printfs is missing, program will now exit
fileName;
return ;
unsigned char header;
Read the header
freadheader sizeofunsigned char picture;
fwriteheader sizeofunsigned char cypher;
Get picture stats
int width int&header;
int height int&header;
short int bitPerPixel short int&header;
int multiplier bitPerPixel ;
Dealing with Padding Rules
if width
width width ;
int size multiplier width height;
printfSIZE: d
size;
unsigned char pixelData unsigned charmallocsize;
Reading Pixel Data
freadpixelData sizeofunsigned char size, picture;
fclosepicture;
Generate keys
keygenerationkeyArray;
Decide which mode to implement
if strcmpmode "ECB"
for int i; i j & ;
customByte processedData;
ifdecrypt
processedData decryptionplaintext;
else
processedData encryptionplaintext;
unsigned char processedByte ;
for int j; j; j
processedByte processedDataj j;
fwrite&processedByte, sizeofunsigned char cypher;
else if strcmpmodeCBC
customByte iv;
customByte previousCiphertext;
for int i ; i size; i
customByte plaintext;
unsigned char
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
