views:

61

answers:

2

In the Wikipedia Article on Block Cipher Modes they have a neat little diagram of an unencrypted image, the same image encrypted using ECB mode and another version of the same image encrypted using another method.

Unencrypted ECB Mode CBC Mode

At university I have developed my own implementation of DES (you can find it here) and we must demo our implementation in a presentation.

I would like to display a similar example as shown above using our implementation. However most image files have header blocks associated with them, which when encrypting the file with our implementation, also get encrypted. So when you go to open them in an image viewer, they are assumed to be corrupted and can't be viewed.

I was wondering if anybody new of a simple header-less image format which we could use to display these? Or if anyone had any idea's as to how the original creator of the images above achieved the above result?

Any help would be appreciated,

Thanks

Note: I realise rolling your own cryptography library is stupid, and DES is considered broken, and ECB mode is very flawed for any useful cryptography, this was purely an academic exercise for school. So please, no lectures, I know the drill.

+3  A: 

If you are using a high-level language, like Java, python, etc, one thing you could do is load an image and read the pixel data into an array in memory. Then perform the encryption on those raw bytes, then save the image when you are done. Let all of the header data be handled by the libraries of whatever language you are using. In other words, don't treat the file as a raw sequence of bytes. Hope that helps.

YGL
+1 I was going to suggest the same thing.
Nick D
Yea, I have considered this. We developed it in C++, and we really arn't supposed to use any external libraries. Also our program is supposed to be general purpose to encrypt any file. Thanks for the answer though.
Brian Gianforcaro
@Brian, it's really trivial to load and save 32-bit (no palette) bitmap files. You don't need a 3rd party lib.
Nick D
It sounds like you only need the image files for your presentation - so you can simply use a modified, throw-away version of your encryption tool to generate them, right?
caf
If I was going to do it, this is the best answer in my opinion.
Brian Gianforcaro
+3  A: 

Just cut off the headers before you encrypt (save them somewhere). Then encrypt only the rest. Then add the headers in front of the result.

This is especially easy with the Netpbm format, because you only have to know, how many lines to cut off. The data is stored as decimal numbers, so you should probably take that into account when encrypting (convert them to binary first).

Chris Lercher
This would only work for some image formats, that store "plain" pixels values (perhaps BMP, TGA or PPM - not GIF, PNG, JPEG) - and even then, one should consider how many bytes per pixel/row are, and how does this relate with the coder block-size. Otherwise, the results would be meaningless
leonbloy
@leonboy: True, I was updating my answer while you wrote the comment.
Chris Lercher