Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / Media contents encryption and decryption use memblocks from file

Author
Message
damothegreat
2
Years of Service
User Offline
Joined: 18th Sep 2016
Location:
Posted: 18th Oct 2016 13:54 Edited at: 29th Jan 2017 20:17
damothegreat
2
Years of Service
User Offline
Joined: 18th Sep 2016
Location:
Posted: 18th Oct 2016 16:02 Edited at: 29th Jan 2017 20:18
damothegreat
2
Years of Service
User Offline
Joined: 18th Sep 2016
Location:
Posted: 18th Oct 2016 16:02 Edited at: 29th Jan 2017 20:18
damothegreat
2
Years of Service
User Offline
Joined: 18th Sep 2016
Location:
Posted: 18th Oct 2016 16:04 Edited at: 29th Jan 2017 20:18
damothegreat
2
Years of Service
User Offline
Joined: 18th Sep 2016
Location:
Posted: 18th Oct 2016 16:07 Edited at: 29th Jan 2017 20:18
damothegreat
2
Years of Service
User Offline
Joined: 18th Sep 2016
Location:
Posted: 18th Oct 2016 16:47 Edited at: 29th Jan 2017 20:19

Attachments

Login to view attachments
damothegreat
2
Years of Service
User Offline
Joined: 18th Sep 2016
Location:
Posted: 18th Oct 2016 18:44

//Try this bit of code


sprites as integer[100]
spritefiles as string[100]

// App to encrypt all your assets and then put into 1 ZIP
// Assets.zip
// bytecode.byc - compiler process file
// Contents stored in .\media

// Encrypt all PNG images in Media folder
count=0
fn$=GetFirstFile()
while fn$<>""

// print (fn$ + " = " + mid(fn$,len(fn$)-2,3))

if mid(fn$,len(fn$)-2,3)="png"
encrypt(fn$,fn$+"enc",100,1)
//backspr=encrypt("\media\background.png","\media\background_enc",100,1)
count=count+1
spritefiles[count]=fn$+"enc"

endif

fn$=GetNextFile()
endwhile
sync()


for a=1 to count

//Decrypted
sprites[a]=decrypt(spritefiles[a],100,1)
setspritescale(sprites[a],1,1)
SetSpritePosition(sprites[a],random(0,width),random(0,height))

next


Print( ScreenFPS())
sync()


----------------------------------
You can now put as many PNG pics in the media folder,
This will
- Identify them -> MediaFiles.png
- Encrypt them -> MediaFilesAfter.png
- Decrypt and use them -> result from code.png

Sorry, if I'm really boring you all

I found this really great to do and lots more to come

Damo
Using Tier 1 AppGameKit V2
Started coding with AMOS

Attachments

Login to view attachments
Phaelax
DBPro Master
16
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 18th Oct 2016 23:31
Use code tags.

[ c o d e]
put code here
[ / c o d e]

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Kevin Picone
16
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 19th Oct 2016 04:54
Exclusive oring the bytes will keep out a few people of the media, but it's well known method. The attacker can find a key by running through the file and xor'ing with all byte values 0 to 255, as there's only 256 possible combinations which is easy for modern system to chew through.

Another method is to not actually alter the bytes, but change the order in what they appear, which is called a transposition cipher from memory. So you'd build a table on startup (from some private routine), then use the table to reorder the bytes in the mem block. You can xor them, shift whatever during the same process.



PlayBASIC To HTML5/WEB - Convert PlayBASIC To Machine Code
DavidAGK
5
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 19th Oct 2016 08:32
This has been raised so many times that I am hoping that TGC will build encryption into the system. Ideally I'd like everything to be compiled into a single .exe that houses all the assets encrypted and then relevant commands (loadimage etc) just decrypt as necessary.
Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)
BatVink
Moderator
16
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 19th Oct 2016 08:44
You could use my encryption tutorial as a starting point. To start, it will turn your 255 possible keys into billions of possible keys, using industry-standard encryption techniques.

http://tutcity.devink.co.uk/encryption/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
damothegreat
2
Years of Service
User Offline
Joined: 18th Sep 2016
Location:
Posted: 19th Oct 2016 15:24
Thanks all for your input.

Yeah would be good to house all the assets into one exe - splendid idea.

Shall continue working on this and indeed look into your tutorial for better encryption

Maybe perhaps take a loaded image into memblock and then do a swapping technique with a certain amount of chunks - lets say 8 and then 4 and then 2

eg.... say for example this below is file of bytes just to give an idea using 8 byte chunk swaps.


file= [ a b c d e f g h I j k l m n o p q r s t u v w x ]..........etc

8 byte chunks [ 1 2 3 4 5 6 7 8 ][ 1 2 3 4 5 6 7 8 ][ 1 2 3 4 5 6 7 8 ]..........etc
first pass 8 bytes = [ h g f e d c b a ][ p o n m l k j I ][ x w v u t s r q ]..........etc

4 byte chunks [ 1 2 3 4 ][ 1 2 3 4 ][ 1 2 3 4 ][ 1 2 3 4 ][ 1 2 3 4 ][ 1 2 3 4 ]..........etc
2nd pass 4 bytes= [ e f g h ][ a b c d ][ m n o p ][ l j k I ][ u v w x ][ q r s t ]..........etc

2 byte chunks [ 1 2 ][ 1 2 ][ 1 2 ][ 1 2 ][ 1 2 ][ 1 2 ][ 1 2 ][ 1 2 ][ 1 2 ][ 1 2 ][ 1 2 ][ 1 2 ]..........etc
3rd pass 2 bytes= [ f e ][ h g ][ b a ][ d c ][ n m ][ p o ][ j I ][ l k ][ v u ][ x w ][ r q ][ s t ]..........etc


Result From file a b c d e f g h I j k l m n o p q r s t u v w x
To result f e h g b a d c n m p o j I l k v u x w r q s t

Somewhat heavily scrambled

Ill work on it and see the performance value to doing this

Damo
Using Tier 1 AppGameKit V2
Started coding with AMOS
DavidAGK
5
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 19th Oct 2016 15:37
Hi BatVink,

Yes, definitely and I really appreciate the work you put into that. I'm going to be looking at it again when I get to that stage on my game. I do feel however that given it is such a repeated theme that TGC might look into creating a robust system "out of the box" that helps everyone.
Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)
damothegreat
2
Years of Service
User Offline
Joined: 18th Sep 2016
Location:
Posted: 19th Oct 2016 19:24

Hello

I have done more on this

Now you can encrypt a file, which accepts a filename, amount of maxchunks to do various swapping (maximum 1024 bits), but the more you have, the more performance degrading game might
become.

What it does is.

- Loads a file into memory
- Goes through the file from memory according to the "maxchunks" you specify
---------swaps them around
---------XOR the chunk by the maxchunk you specify in the parameter
---------saves the chunk back into memory
---------Repeats this until processed all the file
---------Creates a new file (encrypted) into your media folder in the Appdata area.





Decrypt code for the encryption is




Here is a bit of code to see them in action, use at beginning of your main file



Once an image has been through the encrypted function, it places it into the project media folder in the Appdata area called "filename.pngenc"

This is when you can Exclude the original image files now from the main game project area and let the decrypt function do its work to decrypt
and load them normally as a sprite.

Good luck and hope it works out for some of you who wishes to have your assets encrypted someway

Any probs, give me a shout

Damo

Using Tier 1 AppGameKit V2
Started coding with AMOS
Carharttguy
2
Years of Service
User Offline
Joined: 8th Jul 2016
Location: Belgium
Posted: 24th Oct 2016 14:28
Hello

I get what you're doing, but you know that you're doing a lot of work for something you can't stop at all?
There are a lot of tools that can extract assets from the openGL or DirectX calls.

If someone wants your assets, is like 10 min work to get them. If someone really wants to play your game on another computer/without license, they're going to make a crack.

Login to post a reply

Server time is: 2019-06-19 23:06:14
Your offset time is: 2019-06-19 23:06:14