Destruction Productions


Make Games. Make Money. Make Friends.
 
HomeRegisterLog in

Share | 
 

 Encryption/Decryption of files

View previous topic View next topic Go down 
AuthorMessage
gullesnuffs

avatar

Number of posts : 252
Registration date : 2009-05-06
Age : 23
Location : Stockholm, Sweden

PostSubject: Encryption/Decryption of files   Wed Dec 09, 2009 10:56 pm

I have wrote two simple scripts for encryption and decryption of files. Feel free to use them for the game!

scr_save_file(filename, string)
Code:

//argument0=filename
//arguemnt1=string that will be encrypted
{
 var i, file, size;
 file=file_bin_open(argument0, 1);
 size=string_length(argument1);
 for(i=1; i <= size; i += 1)
 {
    file_bin_write_byte(file, ord(string_char_at(argument1, i))^(((7*i+6)*i*i+94*i+238) mod 256));
 }
 file_bin_close(file);
}

scr_open_file(filename)
Code:

//This script decrypts the file argument0 and returns the result as a string
//Argument0=the file that will be decrypted
{
 var str, file, j, i, char;
 file=file_bin_open(argument0, 0);
 str="";
 j=file_bin_size(file);
 for(i=1; i <= j; i += 1)
 {
    char=chr(file_bin_read_byte(file)^(((7*i+6)*i*i+94*i+238) mod 256));
    str += char;
 }
 file_bin_close(file);
return str;
}

The numbers that here are 7, 6, 94 and 238 are arbitary, they can and should be changed so that we don't use the same key for all of our file formats.
It's important that the key in the saving scipt is exactly the same as the key in the opening script.

__________________
My band's MySpace http://www.myspace.com/koostumus
My deviant art http://gullesnuffs.deviantart.com/


Last edited by gullesnuffs on Wed Dec 09, 2009 11:15 pm; edited 1 time in total
Back to top Go down
http://gullesnuffs.deviantart.com/
Hegemege
Moderator
avatar

Number of posts : 919
Registration date : 2009-02-21
Age : 25
Location : Helsinki, Finland

PostSubject: Re: Encryption/Decryption of files   Wed Dec 09, 2009 11:11 pm

Thank you very much! Could the second script return the string, it would be easier that way.

__________________
WTF = Welcome To Finland

"I'm a Finnish man. I eat iron and sh*t chains!"
Back to top Go down
gullesnuffs

avatar

Number of posts : 252
Registration date : 2009-05-06
Age : 23
Location : Stockholm, Sweden

PostSubject: Re: Encryption/Decryption of files   Wed Dec 09, 2009 11:15 pm

Oh, I forgot to add that line...

__________________
My band's MySpace http://www.myspace.com/koostumus
My deviant art http://gullesnuffs.deviantart.com/
Back to top Go down
http://gullesnuffs.deviantart.com/
bretboy129
Moderator
avatar

Number of posts : 357
Registration date : 2009-03-03
Age : 21
Location : Here and at Glitchy Games!

PostSubject: Re: Encryption/Decryption of files   Wed Dec 09, 2009 11:23 pm

wow!! thats coool
thx
-Bret

__________________
-Bretboy129 ~ Bret Hudson
Back to top Go down
http://glitchygames.forumotion.com/forum.htm
Commander~DEST
Admin
avatar

Number of posts : 1499
Registration date : 2009-01-16
Age : 22
Location : Quispamsis, New Brunswick, Canada

PostSubject: Re: Encryption/Decryption of files   Thu Dec 10, 2009 4:18 am

Yeah, it is very cool. I can't say I've actually seen the script before to do this type of thing.

I will add this to the resource pack. Thanks Gullesnuffs! You're doing great!

__________________
Commander~DEST | Admin of Destruction Productions

Making games is not a hobby, but a commitment.
Back to top Go down
http://dest.nice-board.com
bretboy129
Moderator
avatar

Number of posts : 357
Registration date : 2009-03-03
Age : 21
Location : Here and at Glitchy Games!

PostSubject: Re: Encryption/Decryption of files   Fri Dec 11, 2009 9:09 am

I tried putting this in teh game, and it told me it cannot find variable save_file.txt

What should I do to make it work correctly?
-Bret

__________________
-Bretboy129 ~ Bret Hudson
Back to top Go down
http://glitchygames.forumotion.com/forum.htm
Commander~DEST
Admin
avatar

Number of posts : 1499
Registration date : 2009-01-16
Age : 22
Location : Quispamsis, New Brunswick, Canada

PostSubject: Re: Encryption/Decryption of files   Fri Dec 11, 2009 10:17 am

Well, maybe you used a function that required having that specific file created. Try making a text document in that name and see how it works. Just a suggestion...

__________________
Commander~DEST | Admin of Destruction Productions

Making games is not a hobby, but a commitment.
Back to top Go down
http://dest.nice-board.com
bretboy129
Moderator
avatar

Number of posts : 357
Registration date : 2009-03-03
Age : 21
Location : Here and at Glitchy Games!

PostSubject: Re: Encryption/Decryption of files   Sat Dec 12, 2009 7:07 am

I tried that... how exactually do I put this in the game Gullesnuffs??
I'm rather retarded lately and i need step by step procedures, sadly : S
-Bret

__________________
-Bretboy129 ~ Bret Hudson
Back to top Go down
http://glitchygames.forumotion.com/forum.htm
gullesnuffs

avatar

Number of posts : 252
Registration date : 2009-05-06
Age : 23
Location : Stockholm, Sweden

PostSubject: Re: Encryption/Decryption of files   Sat Dec 12, 2009 8:25 pm

If it says that it couldn't find the variable save_file.txt that is because that's not a variable =P
Probably, the error you're doing is that you write:

Code:
scr_save_file(save_file.txt, string(score));

Instead of:

Code:
scr_save_file("save_file.txt", string(score));

You need "" to make Game Maker understand that it's a string, not a variable.

__________________
My band's MySpace http://www.myspace.com/koostumus
My deviant art http://gullesnuffs.deviantart.com/
Back to top Go down
http://gullesnuffs.deviantart.com/
Commander~DEST
Admin
avatar

Number of posts : 1499
Registration date : 2009-01-16
Age : 22
Location : Quispamsis, New Brunswick, Canada

PostSubject: Re: Encryption/Decryption of files   Tue Dec 15, 2009 11:29 am

Could some one provide me with these 2 scripts except that it looks on the second line for information? I want to combine the text files into one main one. Thanks in advance.

__________________
Commander~DEST | Admin of Destruction Productions

Making games is not a hobby, but a commitment.
Back to top Go down
http://dest.nice-board.com
Commander~DEST
Admin
avatar

Number of posts : 1499
Registration date : 2009-01-16
Age : 22
Location : Quispamsis, New Brunswick, Canada

PostSubject: Re: Encryption/Decryption of files   Thu Dec 17, 2009 10:18 am

Please?? I really need this if I want to finish the engine. I will attempt to find the functions if I don't get help by Friday (because that's the next time I'll be on the computer). The engine is coming great though. For the leveling, I am using arrays instead of variables.

__________________
Commander~DEST | Admin of Destruction Productions

Making games is not a hobby, but a commitment.
Back to top Go down
http://dest.nice-board.com
bretboy129
Moderator
avatar

Number of posts : 357
Registration date : 2009-03-03
Age : 21
Location : Here and at Glitchy Games!

PostSubject: Re: Encryption/Decryption of files   Thu Dec 17, 2009 10:53 am

ok what exactually do you need?? I'm confused...

__________________
-Bretboy129 ~ Bret Hudson
Back to top Go down
http://glitchygames.forumotion.com/forum.htm
Commander~DEST
Admin
avatar

Number of posts : 1499
Registration date : 2009-01-16
Age : 22
Location : Quispamsis, New Brunswick, Canada

PostSubject: Re: Encryption/Decryption of files   Thu Dec 17, 2009 7:27 pm

The exact same scripts except they save and load information from the second line of a document instead of the first line.

__________________
Commander~DEST | Admin of Destruction Productions

Making games is not a hobby, but a commitment.
Back to top Go down
http://dest.nice-board.com
Hegemege
Moderator
avatar

Number of posts : 919
Registration date : 2009-02-21
Age : 25
Location : Helsinki, Finland

PostSubject: Re: Encryption/Decryption of files   Thu Dec 17, 2009 9:14 pm

but why? The data is saved on one line and it's up to your program what you use if it shows it as one or multi rows. Notepad shows everything on one line but Wordpad shows is on many lines.

__________________
WTF = Welcome To Finland

"I'm a Finnish man. I eat iron and sh*t chains!"
Back to top Go down
Commander~DEST
Admin
avatar

Number of posts : 1499
Registration date : 2009-01-16
Age : 22
Location : Quispamsis, New Brunswick, Canada

PostSubject: Re: Encryption/Decryption of files   Thu Dec 17, 2009 9:51 pm

Oh so I encrypt every variable the same way, and it will do all of the work? And it will decrypt the right information? Or do I have to decrypt the information in the same order that I encrypted it...?

__________________
Commander~DEST | Admin of Destruction Productions

Making games is not a hobby, but a commitment.
Back to top Go down
http://dest.nice-board.com
gullesnuffs

avatar

Number of posts : 252
Registration date : 2009-05-06
Age : 23
Location : Stockholm, Sweden

PostSubject: Re: Encryption/Decryption of files   Thu Dec 17, 2009 10:05 pm

If you need to save several variables, you can always create multiple files Razz, if you don't want to do that, however, you'll probably need to have some kind of seperator between the different data, like this:

Code:
//This script decrypts the file argument0 and returns the value as a string
//Argument0=the file that will be decrypted
{
 var str, file, j, i, char, k;
 file=file_bin_open(argument0, 0);
 str="";
 j=file_bin_size(file);
 k=0;
 for(i=1; i <= j; i += 1)
 {
    char=chr(file_bin_read_byte(file)^(((7*i+6)*i*i+94*i+238) mod 256));
    if(char == "|")
    {
        value[k]=str;
        str="";
        k += 1;
    }
    else
    {
        str += char;
    }
 }
 file_bin_close(file);
}

And for saving just use
Code:
scr_save_file("filename.xxx", string(value[0]) + "|" + string(value[1]) + "|" + string(value[2]) + "|" + string(value[3]) + "|");

__________________
My band's MySpace http://www.myspace.com/koostumus
My deviant art http://gullesnuffs.deviantart.com/
Back to top Go down
http://gullesnuffs.deviantart.com/
Commander~DEST
Admin
avatar

Number of posts : 1499
Registration date : 2009-01-16
Age : 22
Location : Quispamsis, New Brunswick, Canada

PostSubject: Re: Encryption/Decryption of files   Thu Dec 17, 2009 10:08 pm

Thanks! It is currently saving to multiple files, but that's but that's why I needed this script! This is exactly what I was looking for, I don't think I wouldn't have been able to make this!

__________________
Commander~DEST | Admin of Destruction Productions

Making games is not a hobby, but a commitment.
Back to top Go down
http://dest.nice-board.com
Sponsored content




PostSubject: Re: Encryption/Decryption of files   

Back to top Go down
 
Encryption/Decryption of files
View previous topic View next topic Back to top 
Page 1 of 1
 Similar topics
-
» Obama Files Federal Charges Against George Zimmerman Following Acquittal in Shooting Murder of Trayv
» Kodak files bankruptcy
» CVS files of CSE from April 9-11
» Kuwaiti Prime Minister confirms that his upcoming visit to Iraq will yield for resolving all files
» Britain reveals transfer some files Kuwait and Iraq from Chapter VII to Chapter VI

Permissions in this forum:You cannot reply to topics in this forum
Destruction Productions :: Archives-
Jump to: