| Encryption/Decryption of files | |
|
|
Author | Message |
---|
gullesnuffs
Number of posts : 252 Registration date : 2009-05-06 Age : 30 Location : Stockholm, Sweden
| Subject: 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.
Last edited by gullesnuffs on Wed Dec 09, 2009 11:15 pm; edited 1 time in total | |
|
| |
Hegemege Moderator
Number of posts : 919 Registration date : 2009-02-21 Age : 31 Location : Helsinki, Finland
| Subject: 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. | |
|
| |
gullesnuffs
Number of posts : 252 Registration date : 2009-05-06 Age : 30 Location : Stockholm, Sweden
| Subject: Re: Encryption/Decryption of files Wed Dec 09, 2009 11:15 pm | |
| Oh, I forgot to add that line... | |
|
| |
bretboy129 Moderator
Number of posts : 357 Registration date : 2009-03-03 Age : 28 Location : Here and at Glitchy Games!
| Subject: Re: Encryption/Decryption of files Wed Dec 09, 2009 11:23 pm | |
| wow!! thats coool thx -Bret | |
|
| |
Commander~DEST Admin
Number of posts : 1499 Registration date : 2009-01-16 Age : 29 Location : Quispamsis, New Brunswick, Canada
| Subject: 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! | |
|
| |
bretboy129 Moderator
Number of posts : 357 Registration date : 2009-03-03 Age : 28 Location : Here and at Glitchy Games!
| Subject: 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 | |
|
| |
Commander~DEST Admin
Number of posts : 1499 Registration date : 2009-01-16 Age : 29 Location : Quispamsis, New Brunswick, Canada
| Subject: 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... | |
|
| |
bretboy129 Moderator
Number of posts : 357 Registration date : 2009-03-03 Age : 28 Location : Here and at Glitchy Games!
| Subject: 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 | |
|
| |
gullesnuffs
Number of posts : 252 Registration date : 2009-05-06 Age : 30 Location : Stockholm, Sweden
| Subject: 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. | |
|
| |
Commander~DEST Admin
Number of posts : 1499 Registration date : 2009-01-16 Age : 29 Location : Quispamsis, New Brunswick, Canada
| Subject: 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
Number of posts : 1499 Registration date : 2009-01-16 Age : 29 Location : Quispamsis, New Brunswick, Canada
| Subject: 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. | |
|
| |
bretboy129 Moderator
Number of posts : 357 Registration date : 2009-03-03 Age : 28 Location : Here and at Glitchy Games!
| Subject: Re: Encryption/Decryption of files Thu Dec 17, 2009 10:53 am | |
| ok what exactually do you need?? I'm confused... | |
|
| |
Commander~DEST Admin
Number of posts : 1499 Registration date : 2009-01-16 Age : 29 Location : Quispamsis, New Brunswick, Canada
| Subject: 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. | |
|
| |
Hegemege Moderator
Number of posts : 919 Registration date : 2009-02-21 Age : 31 Location : Helsinki, Finland
| Subject: 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. | |
|
| |
Commander~DEST Admin
Number of posts : 1499 Registration date : 2009-01-16 Age : 29 Location : Quispamsis, New Brunswick, Canada
| Subject: 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...? | |
|
| |
gullesnuffs
Number of posts : 252 Registration date : 2009-05-06 Age : 30 Location : Stockholm, Sweden
| Subject: 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 , 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]) + "|"); | |
|
| |
Commander~DEST Admin
Number of posts : 1499 Registration date : 2009-01-16 Age : 29 Location : Quispamsis, New Brunswick, Canada
| Subject: 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! | |
|
| |
Sponsored content
| Subject: Re: Encryption/Decryption of files | |
| |
|
| |
| Encryption/Decryption of files | |
|