Skip BMP header for DES encryption

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2007
Posts: 48
Reputation: weasel7711 is an unknown quantity at this point 
Solved Threads: 0
weasel7711 weasel7711 is offline Offline
Light Poster

Skip BMP header for DES encryption

 
0
  #1
Feb 19th, 2009
I am writing an implementation of a DES encryption with a 64 bit plaintext, taken from the pixel information in a BMP file. So I want to skip the header which is 54 bytes, but I am not sure how to do this. This will not be a dynamic project, in the sense that I will always use the same BMP file (as I am producing both a CBC and EBC mode BMP file at the program finish)
If you have no idea what I am talking about, check out this link.
http://www.giac.org/resources/whitep...ography/62.php

So I would like to open the bmp file, skip the first 54 bytes, then consecutively read 8 byte blocks and encrypt them. I just don't know very much about using files in C++.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 476
Reputation: nucleon has a spectacular aura about nucleon has a spectacular aura about 
Solved Threads: 91
nucleon's Avatar
nucleon nucleon is offline Offline
Posting Pro in Training

Re: Skip BMP header for DES encryption

 
1
  #2
Feb 19th, 2009
  1. char buffer[100];
  2. ifstream f;
  3.  
  4. f.open ("pic.bmp", ios::binary);
  5.  
  6. // skip header
  7. f.read (buffer, 54);
  8.  
  9. // read 8 bytes into buffer
  10. f.read (buffer, 8);
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 48
Reputation: weasel7711 is an unknown quantity at this point 
Solved Threads: 0
weasel7711 weasel7711 is offline Offline
Light Poster

Re: Skip BMP header for DES encryption

 
0
  #3
Feb 19th, 2009
Thank you. I do have one question though. What does the ios::binary do, does that translate the hex digits into binary when read into the buffer?
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 476
Reputation: nucleon has a spectacular aura about nucleon has a spectacular aura about 
Solved Threads: 91
nucleon's Avatar
nucleon nucleon is offline Offline
Posting Pro in Training

Re: Skip BMP header for DES encryption

 
0
  #4
Feb 19th, 2009
No. Binary mode simply ensures that all file bytes are put into the buffer as is, with no translation whatsoever. Text mode may, depending on the operating system, translate various bytes. For instance, in windows the usual end of line marker is ascii-13 followed by ascii-10. But when read in text mode, all your program sees is the ascii-10.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 48
Reputation: weasel7711 is an unknown quantity at this point 
Solved Threads: 0
weasel7711 weasel7711 is offline Offline
Light Poster

Re: Skip BMP header for DES encryption

 
0
  #5
Feb 20th, 2009
What I am planning on doing is bitwise operation on the 8 bytes read in from the file. I was thinking of converting the 8 bytes to an integer value, then I remembered ints in windows are 4 bytes. Is a long 8 bytes? And is there a way to convert the 8 bytes read in to the buffer into a long value I can manipulate?
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,864
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 301
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Roasting Maven

Re: Skip BMP header for DES encryption

 
0
  #6
Feb 20th, 2009
Why would you want to convert it to something of you can just manipulate it one byte at a time?
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 48
Reputation: weasel7711 is an unknown quantity at this point 
Solved Threads: 0
weasel7711 weasel7711 is offline Offline
Light Poster

Re: Skip BMP header for DES encryption

 
0
  #7
Feb 20th, 2009
How do I manipulate the bytes if they are stored as chars?
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 476
Reputation: nucleon has a spectacular aura about nucleon has a spectacular aura about 
Solved Threads: 91
nucleon's Avatar
nucleon nucleon is offline Offline
Posting Pro in Training

Re: Skip BMP header for DES encryption

 
0
  #8
Feb 20th, 2009
chars basically are bytes.
So you access them by subscripting the buffer: buffer[i]
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC