how can i crypt game assets and load ?

Everything related to 3D programming
User avatar
skinkairewalker
Enthusiast
Enthusiast
Posts: 634
Joined: Fri Dec 04, 2015 9:26 pm

how can i crypt game assets and load ?

Post by skinkairewalker »

hello everyone !

i am trying to crypt game assets 3d, sounds and texture .

is there any way to encrypt all assets and import into my game in pb?
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: how can i crypt game assets and load ?

Post by Mijikai »

U could use the AES Cipher

Here is some code i wrote (Unicode):

Code: Select all


EnableExplicit

Procedure.i CryptBuffer(*Buffer,Length.i,Key.s,Decrypt.i = #False)
  Protected *key
  Protected *block
  If Key And *Buffer And Length > 15
    *key = Ascii(Key + Space(8))
    If *key
      *block = AllocateMemory(Length)
      If *block
        If Decrypt
          If AESDecoder(*Buffer,*block,Length,*key,128,#Null,#PB_Cipher_ECB)
            FreeMemory(*key)
            ProcedureReturn *block
          EndIf
        Else
          If AESEncoder(*Buffer,*block,Length,*key,128,#Null,#PB_Cipher_ECB)
            FreeMemory(*key)
            ProcedureReturn *block
          EndIf
        EndIf
        FreeMemory(*block)
      EndIf
      FreeMemory(*key)
    EndIf
  EndIf
  ProcedureReturn #Null
EndProcedure

Procedure.i Main()
  Protected *encrypt
  Protected *decrypt
  Protected dummy.s
  dummy = "Hello World!"
  *encrypt = CryptBuffer(@dummy,StringByteLength(dummy) + 2,"Password")
  If *encrypt
    *decrypt = CryptBuffer(*encrypt,MemorySize(*encrypt),"Password",#True)
    If *decrypt
      ShowMemoryViewer(*decrypt ,MemorySize(*decrypt))
      FreeMemory(*decrypt)
    EndIf
    FreeMemory(*encrypt)
  EndIf
  ProcedureReturn
EndProcedure

Main()

End
Edit:
I dont know about the loading part.
Ogre is unable to load stuff from memory iirc.
User avatar
NicTheQuick
Addict
Addict
Posts: 1226
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: how can i crypt game assets and load ?

Post by NicTheQuick »

Why do you want to encrypt it? The key to decrypt the data would be in the app anyway.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: how can i crypt game assets and load ?

Post by Saki »

Well, for textures, as sam ple, you can just XOR randomize the image in memory.
For this you set RandomSeed() to a starting value and create as many randoms as you need.
Then you save it and load it the other way around.
Otherwise it is like Nick says.
The only way to get a handle this, is to dig very deep into the bag of tricks.
A Hint.
With AES you don't create a plain text password.
Also an Asccii password shortens the key with AES128 to 8 bytes.
But I think for a few textures or other this is little relevant.
地球上の平和
User avatar
NicTheQuick
Addict
Addict
Posts: 1226
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: how can i crypt game assets and load ?

Post by NicTheQuick »

Saki wrote:Well, for textures, as sam ple, you can just XOR randomize the image in memory.
For this you set RandomSeed() to a starting value and create as many randoms as you need.
Using a random seed is not encryption!
Saki wrote:Then you save it and load it the other way around.
Also randomizing the image's content and then saving it will result in a very bad image quality if you save it in a compressed format like JPG. That's because JPG is optimized for a reasonable image.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: how can i crypt game assets and load ?

Post by Saki »

Pre encrypted textures are never saved as JPEGs.
An encrypted or XOR-ed texture also successfully resists any compression.
A lossy compression destroys every encrypted image.
And if he puts the key in the code, he has no working encryption anyway.
Then he has no more than with the XOR, no matter how he does it.

Everything else you put in a structure, encrypt it using the address
of the first entry and sizeof and save it.
Included strings create as FixedString.
地球上の平和
Post Reply