Simple encryption

Ok, if you thought by title this is really 'simple' encryption, like XOR, you were wrong.

What do I want?

Spoiler
A 'simple' AES encryption/decryption methods.
Similar to OpenSSL::Cipher::AES in the standard Ruby library.
That means, I input a string and a key, and maybe some additional parameters, and it returns encrypted string.
Same thing for decryption
Why would you write this?
Spoiler
Well, many people could use this, not only in RGSS3, also in RGSS2 and RGSS.
I personally would like to use encryption to encrypt Saves with some strong encryption.
Maps also.
Why don't I write it myself?
Spoiler
I was trying to do something related to openssl.so to require it in my project, but it just won't work.
So where Ruby standard library failed, you guys from forums may succeed.
Anyway, thanks for reading this.
And many thanks if you have the solution.
And sorry if the solution already exists.
If i remember correctly, FenixFyrex has a way of loading .SO into the game by hooking a DLL and use it as a loader.

Since you know how those works, just check some of his treads/demos for it, and i am sure you can continue from where you left with his examples.
Just a note:


That SO loader is made by Wanabe originally, not by FenixFyreX. Fenix maintained it (whatever that means - I honestly don't know 😀 ), but it's not his creation.
@MeowFace : I already tried that 🙂

Didn't work, throws "Runtime error : 127 The specified procedure could not be found"

I tried :

require 'openssl'# andrequire 'openssl.so'# andload_so('openssl.so', 'Init_openssl')# andload_so('openssl','Init_openssl')# and evenDL.dlopen('openssl.so')# andDL.dlopen('openssl')# andDL::Handle.new('openssl.so')# andDL::Handle.new('openssl')And yes, it's Wanabe's creation : https://github.com/wanabe/LoadSo

What am I doing wrong?
whose version of msvcrt-ruby191.dll are you using?
Are there two versions of the DLL?

In Wanabe's repo I don't see any DLLs, so I suppose FenixFyreX just compiled the code to get the DLL.

I'm using the FenixFyreX's DLL, I suppose.

And I don't think FenixFyreX will give any support for LoadSo right now, because he hasn't been active, I think, in a while... (Last Active Mar 13 2015 06:48 AM)
Watanabe is using the default ruby interpreter dll i guess.

FenixFyreX mentioned something about modifying it.

So whose loadso code are you using? Fyx or Wanabe?

Well, try both for results.

Wanabe's version of loadso seems shorter and support both "require" and "load"  to load a file.

Fyx version seems a bit messy to me, discouraged to read through all that.. lol!

And without reading into his version of the dll i can hardly tell what he did with it. have you tried renaming his files and modify the code to load those renamed .dll and .so? that might give a hint of why it's not working, he might code either or both to look for each other.

Umm.. further reading seems like wanabe has the source code of that dll posted somewhere.

The instructions on that page says something about building your own using a C compiler.

https://github.com/wanabe/LoadSo/blob/master/load_so.c

Edit:

And you need to put this code "infront" of the script editor. So i assume it needs to be on the top of the script list?

https://github.com/wanabe/LoadSo/blob/master/load_so.rb
Yeah, it needs that LoadSo script, and that script needs to be above any "require 'stuff.so'" calls.

If it is, there is still the possibility of this:

Code:
#  A lot of the default Ruby extensions (*.so files) aren't load-able yet, I   ##  am working on full compatibility of all the default files, and am trying to ##  setup compatibility for gems as well. In time, this will be possible.
Yes, I know how to paste that script.

But I'm not sure how to compile it.

I have Dev-C++ 5.10 on my computer, and it was throwing some errors, even when I had all files from the repo.

I suppose openssl.so is unsupported currently.

Anyways, I was trying literally everything I could before I posted this.

That's why I posted it in Script Requests, and not on Stack Overflow.

If somebody would be kind to make a Ruby script for AES encryption from scratch, it would be nice.

Else, this topic can be closed, and I'll post this on Stack Overflow, where there are more experienced programmers.

And thank you both.

EDIT : 
@MeowFace : Now tested with default Ruby msvcrt-ruby191.dll. Nope. Does not work.

I give up on SO's and DLL's.
Why use AES? (AES is not simple btw)

You might as well use XOR or compress the save file using DEFLATE before changing a couple of characters here and there.

Doesn't really matter symmetric encryption you use. The attack vector is going to be using the game's routines to do the decryption for them. No need to play around with cryptoanalysis.

If you are still interested I found something called Nettle: http://www.lysator.liu.se/~nisse/nettle/

Haven't tried playing around with it myself, but it seems to contain a bunch of encryption schemes. (Check possible licensing if you do end up using it)

*hugs*
@Zeriab

Yes, I know AES is not simple, I noted that in the first post.

But XOR is just TOO simple!

And yes, I know how to use DEFLATE.

I'm going to mess something with Nettle, to see if it works...
Seems like you are confusing the simplicity of an API with the simplicity of the encryption algorithm itself.

XOR is not really too simple either. Even if you had a monoalphabetic substitution cipher I bet you'd be fine.

What is your use-case? Why do you want to encrypt your save files with AES? Brand value?

Is it just for normal save files?

For online transactions you'd typically use an asymmetric encryption scheme such as RSA to exchange an AES encryption key which is used afterwards. Is it something like that?

Sorry for all the questions. I just get the feeling that you are about to apply an encryption technique wrongly.

Btw. I mentioned DEFLATE because Zlib is included in RGSS3

Zlib:😀eflate.deflate(string)Zlib::Inflate.inflate(string)
*hugs*

 - Zeriab
"Well, many people could use this, not only in RGSS3, also in RGSS2 and RGSS."


--> Making a script that is compatible for all RGSS isn't simple


"I personally would like to use encryption to encrypt Saves with some strong encryption.


Maps also."


Why would you want to encrypt saves and maps?


If for the maps it's about preventing people from getting the map data after hacking the encrypted archive of Ace, then since ur using a script to encrypt the map then the hacker would also have access to your encryption and decryption method so it becomes actually useless. Remember that even if you don't supply the encryption code, you'd still need the decryption code since you'd still decrypt the files before your game can use them.


Anyway, why maps and saves? (I'd understand better if you want to encrypt the whole game)
@Zeriab

Yes, I know that AES is not simple to make, and, again, THAT'S the reason

I was trying to ask somebody to MAKE that encrypter, but, instead,

everybody is just saying : "Why don't you use the default API" when

nobody actually tried to LOAD that default API.

Making

And XOR is not simple if you want to read the XOR-ed text, because

XOR-ed sentences make no sense, but if you want to crack it, then...

OK, you know what happened to RGSS3A?

I think I saw somewhere that RGSS3A files use XOR encryption, and because XOR is too

strong that's why today there are about a bilion RGSS3A/RGSS2A/RGSSAD decrypters.

So I gave up on RGSSXX encryption.

Second, no, I don't want to use online transactions, and I know what RSA is.

Third, I know what Zlib is. I recently discovered it here : http://forums.rpgmakerweb.com/index.php?/topic/43805-some-questions/

And I know I can do complex operations, like, deflate it, XOR it, XOR it again, deflate it again, add random characters at every 5th position in the file, XOR it again, place 100 characters from the beginning to the end, XOR it again, deflate it, zip it, rar it, split it into two files, merge those two files with another two files, XOR them again, shift all character codes by one ( A becomes B ), and so on...

@Engr. Adiktuzmiko

Making a script for all makers is not easy.

But what about RGSS WebKit?

It is just an API that has no connection to any of RGSS functions, since it's just a

script that uses Win32API and a DLL.

I'm not asking here for making a script that encrypts all data with AES, since it's

NOT what I really need. I need literally the copied Ruby API implementation of AES,

and since OpenSSL part of the Ruby API hasn't really changed through Ruby versions,

I suppose, you can still make an algorithm implementation that has no connection to

RGSSX. If you know what I mean.

Second, I'll do something about scripts also.

It's absurd to encrypt saves and maps, when people can just open Scripts.rvdata2

with RPGMVXA and literally READ the encryption key and the algorithm.

@Both of you

Now the final part.

Both of you asked "Why do you need it for?"

First, I don't like the RGSS3A encryption.

When I see a good game encrypted with RGSS3A, I just think that anybody with no skills can decrypt it and use it's maps and everything for it's own

purposes, and it makes me sad.

(To be clear, I never cracked a RPGM game, but I know how to do so)

Second, let's think a bit about my skills.

Let's suppose I make a decent game.

Should I protect my graphics and my music?

What makes my graphics and my music so special?

The answer is, nothing.

Literally anybody can find that music online for free (because I don't pay for music

and graphics). I don't have any resources that I made (actually I do, but those are

just too... strange to share them, although I would do so otherwise), so I have no

graphics and no music to protect.

So, hey player! Did you like music and graphics in the game? Well, here you go, you

can find them in the Graphics and Music folders!

But things I (would) want to protect are maps, and other self-made data.

Imagine this:

A serial killer has entered a house with a mother and a baby.

Other (RGSS3A) encrypted games protect their baby along with jars of baby food, even

though they don't care about baby food, they care about the baby.

In my opinion, serial killer can have all the baby food he can find, as long as he

doesn't touch the baby.

Last, I'm protecting saves because I don't want player to hack the game that way.

If the player is stuck, I'll make some in-game 'cheats' (similar to 'Goodie Caves'

in Aveyond), and I don't want him to cheat on any other way (Cheat Engine, Save

Editor, RPG Maker...)

And yes, I know protecting BAD games is irrational.

I know the reaction will be :

"Make the game first, and if it's good, protect it. Nobody will attempt to crack a

ty game"

I'm trying to make my games as good as possible.

And also, I'm doing those encryption things more from curiosity than from obligation

to encrypt my games.

And I know I used too much "I know" sentences, and that it sounds too egotistical.

Maybe I just think I know.

I'm not sure.

Thank you anyways.
So basically, you're just like me, you're curious. I've also developed some ways to encrypt the graphics and audio of RM and also a way such that scripts aren't easily readable by someone who has totally no idea or just an inkling of how scripting works...


IMHO, a simple encryption that isn't the default RGSSA archive is enough to shy away most of your players, anything a bit hardcore would just be a waste of time...


But anyway I'm curious if someone will actually do this.
OK, you know what happened to RGSS3A?

I think I saw somewhere that RGSS3A files use XOR encryption, and because XOR is too

strong that's why today there are about a bilion RGSS3A/RGSS2A/RGSSAD decrypters.

So I gave up on RGSSXX encryption.
A common misconception is indeed. XOR, like AES, is not designed prevent people from reading the encrypted information when also in possession of the key.

Consider the use case. The game must be able to decrypt the encrypted data, so it must have access to the key, or be able to generate the key. While the game must be able to decrypt we do not want users to decrypt outside of the game.

Now let's assume I am an attacker. I have following options

  • Analyze the encrypted data and try and see if attacks like the couple shown at https://en.wikipedia.org/wiki/Stream_cipher_attack works
  • Investigate the Game.exe and see how it does the decryption as well as what key it uses. (The "key" you may have heard of in RGSSx is just the first of a stream of keys. I.e. keys are permutated with a start key)
I will be really surprised if anyone actually did the first thing. As for the latter? I'll copy whatever algorithm you are using. Use that to implement my decrypter, steal your keys and done. Of course actually implementing a more complex algorithm may take some more time, but overall swapping XOR with AES does not secure the system. You mentioned that you will start making it harder to see the algorithm. The technical word is obfuscation. I am not sure what sort of automated obfuscators are available for Ruby, but manual obfuscation will always be a possibility. I suggest you search for security through obscurity.

Attackers may be delayed, and some may even be deterred. Switching to another encryption system such as AES does help a bit there. Do not kid yourself though, and believe that applying AES somehow magically creates a secure cryptosystem for the save and map files.

If you are playing around with it for fun or for interested, then by all means go ahead. Encryption can be lots of fun 😀
@Zeriab

Well, if somebody REALLY wants to get the data, then he can have it in no time at all.

I heard about "Security through obscurity", Tsukihime posted that somewhere, I think in Anti-RGSS Decrypter thread.

(And in the nearly next post, Andar said the "Security through obscurity" just does not work, as if you don't know the algorithm you will decrypt that even harder.)

When I said: "Start making it harder to read", I ment that I'll do something with Scripts.rvdata2

That means, maybe add a script that calls the DLL, and in the DLL is the key or something...

But I know somebody can actually 'extract' the key from the DLL.

I am just trying to make an encryption that cannot be cracked by random guys that just use some program like RGSSXX Decrypter or by people that think they know something about hacking. And to laugh at the noobs trying to use RGSSXX Decrypter and failing (insert devil smiley here).

But for you, and many people on this forum such as Tsukihime it would take a very small amount of time to figure the algorithm out.

And I'm not quite sure how you ment "Investigate the Game.exe" part. Did you mean : "Open the Game.exe through OllyDbg, scroll through zillion lines of

nonsense and at the end find out the key"? Would that be considered as an "easy" way?

I'll search for some obusfucators, and see if anything can be done with them.

Thanks for suggesting.

(And I think I'll add in some map an event that says : "Congratulations! You have successfully cracked the game!" 🙂 )
I am just trying to make an encryption that cannot be cracked by random guys that just use some program like RGSSXX Decrypter
Which can be done even by utilizing the methods available at RGSSx, no need to go all the way to use something like AES.
I am just trying to make an encryption that cannot be cracked by random guys that just use some program like RGSSXX Decrypter or by people that think they know something about hacking. And to laugh at the noobs trying to use RGSSXX Decrypter and failing (insert devil smiley here).
In that case XOR would work just as well. Someone's going to drop that over the unpacker and it will fail and they will probably go to a reverse engineering community and request a new tool or something.


I don't know how to use a disassembler to find decryption routines, so I'd probably do just that.

Original thread: https://forums.rpgmakerweb.com/threads/simple-encryption.44624/