| | |
EOF problem
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
Hello,
I am able to locate the error... The code is reading from the file plaintext.txt in chunks of 16 bytes... but there are remaining last 3 bytes left therefore the code is not reading the remaining 3 last bytes for encryption that is why it is not displaying the last 3 bytes when decrypted...
So therefore I need to do a padding so that it can take the last 3 bytes + 13 spaces...
Can anyone help how we can do it...
I am able to locate the error... The code
•
•
•
•
while(myfile1.read( (char *)buff, 16 ))
So therefore I need to do a padding so that it can take the last 3 bytes + 13 spaces...
Can anyone help how we can do it...
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Hello,
Instead of using another program to grab the pixel values of the image and save it in a file ciphertxt.txt and then using AES to encrypt and decrypt it.... I opened the image directly in binary...
It is encrypting and decrypting the image correctly but it is not displaying the encrypted image
How can we display the encrypted image...
The image is correctly decrypted but i am unable to display the encrypted image...
How can we display it...
Instead of using another program to grab the pixel values of the image and save it in a file ciphertxt.txt and then using AES to encrypt and decrypt it.... I opened the image directly in binary...
It is encrypting and decrypting the image correctly but it is not displaying the encrypted image
How can we display the encrypted image...
c++ Syntax (Toggle Plain Text)
unsigned char buff[4][4]; ifstream myfile1 ("sel.jpg", ios::binary); ofstream myfile3 ("encrypt.jpg", ios::binary); while(myfile1.read( (char *)buff, 16 )) { for ( j=0; j<BC; j++) for ( i=0; i < 4; i++) { a[i][j] = buff[j][i]; // plaintext } Encrypt(a, rk); 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(); unsigned char buffer[4][4]; ifstream myfile4; myfile4.open( "encrypt.jpg", ios::binary); if( !myfile4 ) { cout << "error opening file, quitting" << endl; return -1; } ofstream myfile5 ("test.jpg", ios::binary); while(myfile4.read( (char *)buffer, 16 )) { for ( j=0; j<BC; j++) for ( i=0; i < 4; i++) { a[i][j] = buffer[j][i]; // plaintext } Decrypt(a, rk); 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();
The image is correctly decrypted but i am unable to display the encrypted image...
How can we display it...
>>how we can display the encrypted image
You can't, and that's the whole purpose of entrypting it
-- the message has to be decrypted first before you can display it so that it makes sense.
You can't, and that's the whole purpose of entrypting it
-- the message has to be decrypted first before you can display it so that it makes sense. Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Hello,
I am writing the code for padding....
The main idea is to get the file size..
If the size is not a multiple of 16 then the space is padded till it is a multiple of 16
The code is:-
Problem i can't get the file size... it is 0..
If i change I am getting the file size correct but then the code is not able to read from the file in chunks of 16 bytes since it is pointed @ the end of file...
Can anyone help how we can solve this problem...
I am writing the code for padding....
The main idea is to get the file size..
If the size is not a multiple of 16 then the space is padded till it is a multiple of 16
The code is:-
c++ Syntax (Toggle Plain Text)
long begin, end; begin = myfile1.tellg(); myfile1.seekg(0, ios::beg); end = myfile1.tellg(); cout<<end; while(((end)%16)!==0)) { char pad=" "; myfile1<<pad; }
Problem i can't get the file size... it is 0..
If i change
C++ Syntax (Toggle Plain Text)
myfile1.seekg(0, ios::end);
Can anyone help how we can solve this problem...
To get back to the beginning of the file for reading, after finding size:
Your padding code is a bit odd. Do you really want to modify the source file, or simply pad out the data that you're encrypting?
How about something like:
Where I think this will still cause you problems is that when the encrypted file is later decrypted, how do you know that last (up to) 15 bytes might be padding and not part of the original data? To simply include those bytes in the final output might give a corrupted image.
As to displaying the encrypted image - why? You can do a dump of the file contents, byte value by byte value, but that has no meaning. You cannot use an image display program, as almost all image formats include some header data to describe the image format type and image parameters, which is now encrypted.
C++ Syntax (Toggle Plain Text)
myfile1.seekg( 0, ios::beg );
Your padding code is a bit odd. Do you really want to modify the source file, or simply pad out the data that you're encrypting?
How about something like:
C++ Syntax (Toggle Plain Text)
//after reading all the data in, do padding int pad_num = 16 - (end % 16) ; //find how many to pad char pad = " "; for( i = 0; i < pad_num; i++ ) { arr[r][c] = pad; //assuming you're trying to fill the array out }
Where I think this will still cause you problems is that when the encrypted file is later decrypted, how do you know that last (up to) 15 bytes might be padding and not part of the original data? To simply include those bytes in the final output might give a corrupted image.
As to displaying the encrypted image - why? You can do a dump of the file contents, byte value by byte value, but that has no meaning. You cannot use an image display program, as almost all image formats include some header data to describe the image format type and image parameters, which is now encrypted.
"We Americans got so tired of being thought of as dumb by the rest of the world that we went to the polls last November and removed all doubt."
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.

Displaying the image is real easy if it is not encrypted ...
You can use glut + corona to easily display images.
http://www.daniweb.com/forums/thread63827.html#5
Also if you are having problems with leftover bytes at the end of the file smaller than your buffer, use the following bit of code to find the file size
C++ Syntax (Toggle Plain Text)
// obtaining file size #include <iostream> #include <fstream> using namespace std; int main () { long begin,end; ifstream myfile ("example.txt"); begin = myfile.tellg(); myfile.seekg (0, ios::end); end = myfile.tellg(); myfile.close(); cout << "size is: " << (end-begin) << " bytes.\n"; return 0; }
Divide the file size by your buffer size, run the loop with the number you get (the quotient) and read the remaining data using the remainder as the read size.
^^
Also, it possible to display encrypted data, just that it would look like a bunch of random pixels .... The standard format is RGB, so you can create a single color out of 3 bytes of data, 0-255, standard char. Read up an OpenGL tutorial on creating a texture ......
Last edited by FireNet; Mar 7th, 2008 at 1:55 pm.
Hello,
I need to show the encrypted image.. and using a software available freely on the internet i have to draw the histogram of the original and encrypted image...
Therefore to be able to draw the histogram i need to display the encrypted image..
I am sending a paper on aes image encryption... it has displayed the encrypted image and drawn the histogram for both original and encrypted image..
Can anyone help how we can display the encrypted image using either another language, software or whatever provided it has displayed the encrypted image...
I need to show the encrypted image.. and using a software available freely on the internet i have to draw the histogram of the original and encrypted image...
Therefore to be able to draw the histogram i need to display the encrypted image..
I am sending a paper on aes image encryption... it has displayed the encrypted image and drawn the histogram for both original and encrypted image..
Can anyone help how we can display the encrypted image using either another language, software or whatever provided it has displayed the encrypted image...
![]() |
Similar Threads
- read to end of line problem (C)
- amigious problem with fstream (C++)
- No idea how to do this problem... (C++)
- problem reading text file to struct (C++)
- File processing problem (C++)
- Stack Queue Fstream (C++)
- fread problem? (C)
Other Threads in the C++ Forum
- Previous Thread: Inheritance and composition
- Next Thread: Composition problem "'XXX' is not a base or member"
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






