I have a function encrypt() which encrypts data from a file in 16 bytes till end of file which in turn calls other 4 functions...and i need to measure the time it encrypts the data consecutively for all the 4 functions till end of file...
I am fwding you the codes...Please help me out...
Expand|Select|Wrap|Line Numbers
- int Encrypt (word8 a[4][MAXBC], word8 rk[MAXROUNDS+1][4][MAXBC])
- { // Encryption of one blockl
- int r;
- sec_init();
- start_time = sec();
- AddRoundKey(a, rk[0]);
- stop_time = sec();
- Add1 = (stop_time - start_time);
- for ( r=1; r < ROUNDS; r++)
- {
- sec_init();
- start_time = sec();
- SubBytes (a,S);
- stop_time = sec();
- sub1 = (stop_time - start_time);
- sec_init();
- start_time = sec();
- ShiftRows(a);
- stop_time = sec();
- sft1 = (stop_time - start_time);
- sec_init();
- start_time = sec();
- MixColumns(a);
- stop_time = sec();
- mix1 = (stop_time - start_time);
- sec_init();
- start_time = sec();
- AddRoundKey(a,rk[r]);
- stop_time = sec();
- Add2 = (stop_time - start_time);
- }
- /* Last round is special; there is no MixColumns
- */
- sec_init();
- start_time = sec();
- SubBytes (a,S);
- stop_time = sec();
- sub2 = (stop_time - start_time);
- sec_init();
- start_time = sec();
- ShiftRows(a);
- stop_time = sec();
- sft2 = (stop_time - start_time);
- sec_init();
- start_time = sec();
- AddRoundKey(a,rk[ROUNDS]);
- stop_time = sec();
- Add3 = (stop_time - start_time);
- return 0;
- }
// opens up a file plaintext.txt
Expand|Select|Wrap|Line Numbers
- char d;
- ifstream myfile1 ("Plaintext.txt");
- ofstream myfile3 ("Ciphertext.txt");
- myfile1.get(d); //priming read
- while(!myfile1.eof())
- {
- for ( j=0; j<BC; j++)
- for ( i=0; i < 4; i++)
- {
- a[i][j] = d; // plaintext
- //cout<<a[i][j]; // to chk how many plaintext is copied
- myfile1.get(d); //reads first element of next block
- }
- //sec_init();
- //start_time = sec();
- Encrypt(a, rk);
- //stop_time = sec();
- //enTime = (stop_time - start_time);
- //sum2+=enTime;
- if (myfile3.is_open())
- {
- for(j=0; j< BC; j ++)
- for ( i=0; i<4; i++)
- myfile3<<a[i][j];
- }
- else
- cout << "Unable to open file";
- }
- myfile3.close();
- myfile1.close();
Expand|Select|Wrap|Line Numbers
- Add = Add1 + Add2*(ROUNDS-1) + Add3;
- sub = sub1*(ROUNDS-1) + sub2;
- sft = sft1*(ROUNDS-1) + sft2;
- mix = mix1*(ROUNDS-1);
- encryptTime = Add + sub + sft + mix;
please help me out..