Question: Can I get a brief description of this C code to understand more. #include Decrypt.h #include #include #include #include #include #include #include #include static void

Can I get a brief description of this C code to understand more.

#include "Decrypt.h"

#include

#include

#include

#include

#include

#include

#include

#include

static void hex_print(const void* pv, size_t len)

{

const unsigned char * p = (const unsigned char*)pv;

if (NULL == pv)

printf("NULL");

else

{

size_t i = 0;

for (; i < len; ++i)

printf("%02X ", *p++);

}

printf(" ");

}

void generateDecryptInfor(char* &EncryptedInfor)

{

int keylength;

unsigned char iv_enc[AES_BLOCK_SIZE], iv_dec[AES_BLOCK_SIZE];

memcpy(iv_dec, iv_enc, AES_BLOCK_SIZE);

size_t inputslength = sizeof(USR_INFOR);

const size_t encslength = ((inputslength + AES_BLOCK_SIZE) / AES_BLOCK_SIZE) * AES_BLOCK_SIZE;

unsigned char* enc_out = new unsigned char[encslength];

unsigned char* dec_out = new unsigned char[inputslength];

AES_KEY enc_key, dec_key;

//read in the encrypted information.

char c1, c2;

c1 = EncryptedInfor[0];

c2 = EncryptedInfor[1];

if (c1=='6'&&c2=='9')

{

keylength = 128;

}

else if (c1 == '8'&&c2 == '2')

{

keylength = 192;

}

else if (c1 == '7'&&c2 == '5')

{

keylength = 256;

}

else

{

cout << "invalid information!" << endl;

}

unsigned char* aes_key = new unsigned char[keylength / 8];

for (int i = 0; i < strlen((char*)aes_key); i++)

{

aes_key[i] = EncryptedInfor[i+2];

}

for (int i = 0; i < strlen((char*)enc_out); i++)

{

enc_out[i] = EncryptedInfor[i + 2 + strlen((char*)aes_key)];

}

for (int i = 0; i < strlen((char*)iv_dec)-1; i++)// this part took about 2 weeks for debugging. we should take one off because there is a extra '\0'.

{

iv_dec[i] = EncryptedInfor[i + 2 + strlen((char*)aes_key) + strlen((char*)enc_out)];

}

// decrypt the information.

AES_set_decrypt_key(aes_key, keylength, &dec_key);

AES_cbc_encrypt(enc_out, dec_out, encslength, &dec_key, iv_dec, AES_DECRYPT);

//print out the encrypted and decrypted information in hexadecimal

cout<<"encrypt:"<

hex_print(enc_out, sizeof(enc_out));

cout << "decrypt:" << endl;

hex_print(dec_out, sizeof(dec_out));

//print out the decrypted information

USR_INFOR * dyc = (USR_INFOR *)dec_out;

cout<< "user name :"<username<

cout << "user Password :" << dyc->password << endl;

return ;

}

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 Databases Questions!