Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Simple Image Encryption  (Read 11994 times)

0 Members and 1 Guest are viewing this topic.

Mindful

  • Newbie
  • *
  • Posts: 6
    • View Profile
Simple Image Encryption
« on: March 18, 2012, 08:37:51 pm »
I'm in the process of writing a reasonably basic game, and for the sake of plot integrity, I don't want curious players to be able to simply open any of the image resources I'm using. As such, I'm looking for a very simple way to encrypt the images I'm using. Unfortunately, I'm pretty new to C++ and SFML, so I'm not sure where to start.

A couple of important notes: first, I know images can be stored in the .exe, but I don't think that's a very good idea in this case. The project will use a lot of high-quality images and the .exe would end up being enormous. Secondly, I know that anyone who really wants to see these image files is going to be able to, so I'm not worried about using a complex form of encryption. I just don't want it to be as easy as opening a resource folder. Lastly, I realize this is likely going to be complicated to do. I'm certainly not asking anyone to write the code for me, I'd just like to know what the best way to go about this is. Should I just convert the images into binary files, or something similar? Is there a simpler way? I've looked around for tutorials but most of them use a more complicated form of encryption than I'd need, and I couldn't find any in context of SFML (I'm using 2.0 so I figure InputStream is going to play a part in loading the encrypted images).

The files will be mostly .png files, and it's very important that whatever encryption process I use doesn't damage their quality. Any input would be appreciated; I'm totally at a loss here.

TheEnigmist

  • Full Member
  • ***
  • Posts: 119
    • View Profile
Simple Image Encryption
« Reply #1 on: March 18, 2012, 09:39:20 pm »

nietaki

  • Newbie
  • *
  • Posts: 30
    • View Profile
    • http://almost-done.net
Simple Image Encryption
« Reply #2 on: March 18, 2012, 09:43:18 pm »
My best (simple) idea would be to use a XOR Cipher with the key contained in the code. This way you could easily convert the encrypted files whether it's by xoring the data you read to the memory or writing your own neat InputStream :)

Make sure to share the implementation (without the key of course), it might be a neat tool to have and a good thing to learn from for people like me if you wrote it well using InputStream :)

Mjonir

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Simple Image Encryption
« Reply #3 on: March 18, 2012, 10:29:12 pm »
If you want something REALLY simple, why not just remove the headers + extension, and store them in your .exe? You can even just remove the mandatory "89 PNG" at the start of the file, most tools will refuse to open it, and you don't have anything to encrypt/store  :)

nietaki

  • Newbie
  • *
  • Posts: 30
    • View Profile
    • http://almost-done.net
Simple Image Encryption
« Reply #4 on: March 18, 2012, 10:54:43 pm »
Quote from: "Mjonir"
If you want something REALLY simple, why not just remove the headers + extension, and store them in your .exe? You can even just remove the mandatory "89 PNG" at the start of the file, most tools will refuse to open it, and you don't have anything to encrypt/store  :)


It's also a good idea if you don't think your target audience will be persistant and read this thread. With a (long enough) key with XOR encryption you're more or less safe even if people know how you encoded the files ;)

(purely academic argument ;))

Mjonir

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Simple Image Encryption
« Reply #5 on: March 18, 2012, 10:56:19 pm »
Quote from: "nietaki"
It's also a good idea if you don't think your target audience will be persistant and read this thread.


On that subject, don't hesitate to PM me, if you want the idea to disappear, I'll gladly edit my previous message ;)

Mindful

  • Newbie
  • *
  • Posts: 6
    • View Profile
Simple Image Encryption
« Reply #6 on: March 18, 2012, 11:04:40 pm »
Quote from: "nietaki"
My best (simple) idea would be to use a XOR Cipher with the key contained in the code. This way you could easily convert the encrypted files whether it's by xoring the data you read to the memory or writing your own neat InputStream :)

Make sure to share the implementation (without the key of course), it might be a neat tool to have and a good thing to learn from for people like me if you wrote it well using InputStream :)


In terms of the actual encryption applied, I was looking at a XOR cipher (just because it's so simple). Unfortunately, I think you're giving me a little too much credit here; I really only have basic experience with streams. If I manage to write something, I doubt it will be worth sharing.

Quote
If you want something REALLY simple, why not just remove the headers + extension, and store them in your .exe? You can even just remove the mandatory "89 PNG" at the start of the file, most tools will refuse to open it, and you don't have anything to encrypt/store

Like I said, I can't store them in the .exe (too many), but the idea of just removing the headers and extension sounds like something a little bit closer to my level. I'm sure I can find a tutorial on doing this to the files, but what would reading them afterwards look like? I take it I'd still have to use a custom InputStream to read them since they'd no longer have an obvious format?

Edit: I'm really not too concerned about secrecy. The game launch is a long ways off, I haven't used a name, and really, like I said, this is mostly about preventing the average Joe from opening the image files, as opposed to having impenetrable security.

Mjonir

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Simple Image Encryption
« Reply #7 on: March 18, 2012, 11:15:10 pm »
Quote from: "Mindful"

Like I said, I can't store them in the .exe (too many)


If was thinking on storing the headers in the .exe, not the whole picture. But you don't need that if you just remove a constant information ("89 PNG" which all PNG files start with).

Quote
but the idea of just removing the headers and extension sounds like something a little bit closer to my level. I'm sure I can find a tutorial on doing this to the files, but what would reading them afterwards look like? I take it I'd still have to use a custom InputStream?


To do that on the file, simply have a little program that open all ".png" files and remove the first 4 chars. (You can also test that it's not already removed, so you can just dump your images and run the same script without damaging images where the header is already removed.)

To read them, load the file in memory, add the little constant string at its beginning and then give it to SFML through loadFromMemory() methods. Can't give you the implementation, but that's the idea :)

Mindful

  • Newbie
  • *
  • Posts: 6
    • View Profile
Simple Image Encryption
« Reply #8 on: March 18, 2012, 11:27:15 pm »
Quote from: "Mjonir"
If was thinking on storing the headers in the .exe, not the whole picture. But you don't need that if you just remove a constant information ("89 PNG" which all PNG files start with).

To do that on the file, simply have a little program that open all ".png" files and remove the first 4 chars. (You can also test that it's not already removed, so you can just dump your images and run the same script without damaging images where the header is already removed.)

To read them, load the file in memory, add the little constant string at its beginning and then give it to SFML through loadFromMemory() methods. Can't give you the implementation, but that's the idea :)


Alright, I definitely don't know how to do all of this, but I'm sure I can learn. You've given me enough that I at least know where I'm going now, which is exactly what I wanted. Thank you. Also, thumbs up on your FSN avatar - I'm actually doing this for a visual novel.

N_K

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Simple Image Encryption
« Reply #9 on: March 19, 2012, 04:16:01 am »
Wow, so I'm not the only one who develops a visual novel engine (well, kind of, it's mixed with tile-based RPG).

But instead of removing the header of all the PNG files, why not store them in a custom binary format, based on Protocol Buffers, or EBML?

Also, take a look at the open source KiriKiri visual novel engine (FSN is built on this engine, by the way). It's plugin-based, and although I haven't tried it myself yet, I'm sure you can use its custom archive format with a little effort in your engine.

Mindful

  • Newbie
  • *
  • Posts: 6
    • View Profile
Simple Image Encryption
« Reply #10 on: March 19, 2012, 06:08:48 am »
Quote from: "N_K"
Wow, so I'm not the only one who develops a visual novel engine (well, kind of, it's mixed with tile-based RPG).

But instead of removing the header of all the PNG files, why not store them in a custom binary format, based on Protocol Buffers, or EBML?

Also, take a look at the open source KiriKiri visual novel engine (FSN is built on this engine, by the way). It's plugin-based, and although I haven't tried it myself yet, I'm sure you can use its custom archive format with a little effort in your engine.


I actually did look at KiriKiri, but it has no English documentation that I know of. As to why removing the headers is a good idea: I picked up C++ two weeks ago (although admittedly I'd logged enough time in various game editors/scripting languages to be familiar with some of the basics before starting). I think removing the headers is fine for now, because it's something I actually know how to do. I don't doubt that your method would likely be better in practice, but I'd have to understand it first, and removing the header files works well enough. I appreciate your suggestion, I just don't quite think I'm up to par.

Edit: Actually, now my curiosity is piqued. I'm doing this in C++ because I figured it would be a good way to learn, but I could just as easily have used Renpy. I haven't looked at specifics, but Renpy looks pretty robust. Does it not have enough support for the RPG elements you're looking for, or is there some other reason you chose not to use it?

N_K

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Simple Image Encryption
« Reply #11 on: March 19, 2012, 02:20:47 pm »
Quote from: "Mindful"
Does it not have enough support for the RPG elements you're looking for, or is there some other reason you chose not to use it?


There are two reasons:

-I want to learn C++ too.

-I can't stand Python.

Besides, Ren'py is nothing more than SDL's functions exposed to the Python interpreter, with a few helper scripts to more complicated operations, isn't it?

dydya-stepa

  • Jr. Member
  • **
  • Posts: 82
    • View Profile
Simple Image Encryption
« Reply #12 on: March 19, 2012, 02:34:24 pm »
i suggest you to finish your game first. anyway i don't think anyone will want to look into your images.

1) It's just crap - face it.
2) If you make angry birds or plans vs zombies. Nobody will even try to use your images as you'll sue them

Don't waste time and make your game. There's 1000s ways to learn c++ without that.

Because 1000s of people like you are wasting their time instead of making games - there are still almost no good games produced with sfml.

N_K

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Simple Image Encryption
« Reply #13 on: March 19, 2012, 03:37:49 pm »
Wow, looks like somebody has too much ego...

It's seriously not your business what people want to do with SFML.

dydya-stepa

  • Jr. Member
  • **
  • Posts: 82
    • View Profile
Simple Image Encryption
« Reply #14 on: March 19, 2012, 05:00:04 pm »
of course i's not mine. i'm not a game developer :-)

just an advice for all beginner game developers. most end up writing their own vector3 class and then throwing away the idea of becoming a game developer. whether it's just hobby or anything else.