Hello i am using AES to encrypt/decrypt data/ pixel values.. saved in a file myfile.txt and the AES encrypts tha data and writes the ciphertext in a file ciphertext.txt
When decrypting the data i am getting some of the pixel values decrypted correctly followed by garbage..
Code to open myfile.txt and save ciphertext to Ciphertext.txt file
char d;
ifstream myfile1 ("myfile.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
}
Encrypt(a, rk);
counter1();
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();
Code to open Ciphertext.txt and save decrypted data to text.txt file
char buffer[4][4];
char dxc;
ifstream myfile4 ("Ciphertext.txt");
ofstream myfile5 ("Text.txt");
myfile4.get(dxc); //priming read
while(!myfile4.eof())
{
for ( j=0; j<BC; j++)
for ( i=0; i < 4; i++)
{
buffer[i][j]=dxc;
//a[i][j] = dxc; // plaintext
//cout<<a[i][j]; // to chk how many plaintext is copied
myfile4.get(dxc); //reads first element of next block
}
for ( j=0; j<BC; j++)
for ( i=0; i < 4; i++)
{
a[i][j] = buffer[i][j];
}
Decrypt(a, rk);
counter2();
if (myfile5.is_open())
{
for(j=0; j<BC; j ++)
for ( i=0; i<4; i++)
myfile5<<a[i][j];
}
else
cout << "Unable to open file";
}
myfile5.close();
myfile4.close();
E.g:- pixel values im myfile.txt
-13224404 -14211046 -14605042 -13682410 -12298975 -11245015 -10322644 -9532112 -8609993 -7490750 -6240432 -5516455 -4990625 -4332695 -3675534 -3412107 -3082376 -2753413 -2687618 -2884997 -3082374 -3082628 -3345799 -3740555 -3675016 -3675013 -3675267 -3609474 -3412093 -3214714 -3017333 -2885749 -2557300 -2425716 -2622326 -2885500 -3082625 -3345797 -4069263 -4727191 -5319066 -6108833 -6766499 -7424678 -8609203 -9333176 -9925051 -10714820 -11240648 -11503818 -11635406 -11437774 -11437776 -11634903 -11503318 -11239892 -11503066 -11503066 -11503064 -11503318 -11503317 -11503317 -11503315 -11503315 -11109329 -11109329 -10978000 -10978000 -10912461 -10912461 -10715850 -10715850 -10847949 -10847949 -10782667 -10848460 -10914252 -10914252 -10849229 -10849227 -10782918 -10782916 -10848709 -10914502 -11046088 -11111881 -11177674 -11177674 -11506639 -11506639 -11506639 -11506639 -11440846 -11440846 -11440846 -11440846
-13158611 -14276582 -14670578 -13682410 -12364768 -11245015
Pixel values in text.txt
-13224404 -14211046 -14605042 -13682410 -12298975 -11245015 -10322644 -9532112 \Ó¶¬6Ewƒ›SÆû53yè
However, some of the encrypted text is the same as EOF and thus i cant read the text
that after it. What should i do?
How to remove the EOF character from the encrypted text...