News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

Image compression.

Started by LemonWizard, December 06, 2010, 08:45:18 AM

Previous topic - Next topic

LemonWizard

Hey.. I was reading some interesting things. I don't know exactly where to put this post.
Anyways. I was reading about how RSA compression works. That's for wifi 802.11 standard.

The encryption and de encryptions use two keys, A private key and a public key.
It starts out pretty simple though I don't understand it fully yet.
You pick two prime numbers, preferably very different ones.

Q and P

Q=61 for example
p=79 *Assuming 79 is a prime
well anyways.. the algorithm continues

N=QP or N=QXP QxP

You end up with a four digit number.. now what if..

you used an encryption key, and laced your images with it, and rewrote the files as binary data files which. used a different "key" for each file. that way there is no generic de encryption method unless you know the key, and since the first part of the key which later gets decrypted anyways, is public and is randomized into the image file, it would even differentiate through out different distributions.
There's only one issue there. the files would not be entirely the same.

So you couldn't replace a broken file with another one because the individual version's key wouldn't be compatible with the return key in the file.


But anyways.

The simple code is to create a header file. Psuedo header file which contains specific key information, which is further encrypted into maybe a 128 bit Hexadecimal key for each image.
Then. An Internal ID which must match the randomized id of the program version...of course
any exploiter would find these values and step through them ignoring them but..

Provided you can do a check in the program that loads the compressed file to make sure that no tinkering has been done to the file. your golden.

And then.. the next part. Of my idea.

;for compression
Load the image, however large it is.
Switch it to a virtual screen.
Switch the rendering surface to a virtual screen
create an rgb array that is 2 dimensional.
get the ink colour of the pixels, and step through in a double for loop from xx to yy
destroy the image "free it" in memory. and keep the array.

Randomize a table array. Which index is 0-FF, make it 2 dimensional. First dimension is Index, second is value.
Convert the rgb values to hex.
randomize the values in the table.
Convert the rgb values, of array data, into randomly offset values.

Make the "key" the offset interpreter value, and multiply, divide, subtract, or add, the value of the key to the changed hex values.

When de encrypting.
Do all the same math to find the steps, and get the values back to their original form, then read in the data, as rgb data, and create the images in memory. Then close the files.

Even better.. is to do all this then make them into raw data structures within the code itself so the images compile with your code... though it's a bit more difficult to do it that way...


I could work on a working example that does all this maybe.. when I'm not dead tired.

If anyone's curious about this let me know.. it is realistic and I could pull it off.
I managed to create an image creation program that used a pallette and the raw image binary's at 32*32 pixels in 32 bit colours, were only 8 KB each.
Due to the really poor interface, and personal reasons I haven't made it public.

The image compression thing.. if you used all of those things together you could attain optimal security.. I think. because there is no way somone is going to know what the key is you used to change the hex values.. even better. If you subtracted the values of every first hex rgb value, by the random key, and added to the second. After modifying them....



Here's a table showing what I mean :


Array holding Hex table up to FF

Index 00: Randomized to value of 23
Index 01: Randomized to value of 48
etc..


First 3 pixels of image array: myarray(1, 1) original value: 00
                                       myarray(1, 2) original value: 01
                                       myarray(1, 3) original value: 00 ;where these are assumed rgb colors

Step 1 after randomizing Hex table

Conversion: Convert array values to their scrambled hex values:

myarray(1, 1) is now equal to 23
myarray(1, 2) is now equal to 48
myarray(1, 3) is now equal to 23

Step 2: Mod by key value

Let's assume our hex key is 33
myarray(1, 1)=23+33 in hex
myarray(1, 2)=48+33 in hex
myarray(1, 3)=23=33 in hex

now.. it's all scrambled. it seems simple to start but.
What if you're using values like

54339101A2F3
then.... the entire rgb value is going to be effected.

The header should appear at the end of the file instead of the start because everyone always looks in the start of it or..
you know. Start the file reading index at EOF and read up.

A good way to throw people off is the read and write order..

Another thing...

Get the size of the image from the header. then.. tinker around. I bet if you scrambled around with Random file access.. you could create a table that told the compiler what the next address was to read from the file from.. and then keep a table inside that file which is loaded into an array that has the information needed to read the file back in the proper order.


So header structure:

Filesize: 32*32 ;for 2d tiles duh
Interpretation list: 1-32*32 (2d array stored as writeint) to file.. since that doesnt' come up as legible in text reading tools
and then
read the interpretation list, into your array so it's safe.

Jump to the first line in the file where the interpretation list says that the first color value is stored

Get all color values.
Then proceed with the interpreting them back into their former forms.

De encryption:
So then you take your hex key which you should somehow have..
make your array for the image your loading
make it re usable so your always re using the same array once you have it created back to an image that way memory hacking tools aren't as efficient >.>
and then. read it all in and voila.

The process should be pretty fast...except for the non command line parts IE loading the image back into video memory or object memory. :P


Happy experimenting :D I'll try to make a working example when I'm not tired.
I hope I get some feedback on these ideas, because I put alot of effort into my post.