This is definitley not very powerful encryption. But I wrote it to protect game data from being easily edited. eg high score tables.
I'll probably increase it's security later. But i think it's sufficent for the purpose.
To use it simply put the 4 functions into your code.
and call:
encryptfile(filename$)
or
decryptfile(filename$)
I added some simple code to allow you to test the functions.
`File encrypter by Hummanoid Typhoon 2005
`Your welcome to use this code for any game project but please give
`credit if you do thanks
set display mode 800,600,16
`make a test file to encrypt
if file exist("test.txt")=1 then delete file "test.txt"
open to write 1,"test.txt"
write string 1,"Hello here are some letters:"
write string 1,"abcdefghijklmnopqrstuvwxyz"
write string 1,"0123456789"
write string 1,"¬!£$%^&*()_+-="
close file 1
encryptfile("test.txt")
open to read 1,"test.txt"
read string 1,a$
read string 1,b$
read string 1,c$
read string 1,d$
read string 1,e$
close file 1
`show encrypted data
print "Hit a key to decrypt--(Encrypted)= "+a$+b$+c$+d$+e$
wait key
decryptfile("test.txt")
open to read 1,"test.txt"
read string 1,a$
read string 1,b$
read string 1,c$
read string 1,d$
read string 1,e$
close file 1
`show decrypted data
print "Hit a key to Exit--(Decrypted)= "+a$+b$+c$+d$+e$
wait key
end
function decryptfile(file$)
if file exist(file$)=1
open to read 1,file$
if file exist("TEMP.ENC")=1 then delete file "TEMP.ENC"
open to write 2,"TEMP.ENC"
do
read string 1,tempstr$
write string 2,decrypt_string(tempstr$)
if FILE END(1)=1 then exit
loop
close file 1
close file 2
DELETE FILE file$
RENAME FILE "TEMP.ENC", file$
`else statment for error trap requires msgbox.dll avalible from `http://winch.pinkbile.com/msgbox.php
`delete else statment if you don't have msgbox.dll/ couldn't be
`bothered getting it.
else
msgbox "ERROR: No file to decrypt!"
endif
endfunction
function encryptfile(file$)
if file exist(file$)=1
open to read 1,file$
if file exist("TEMP.ENC")=1 then delete file "TEMP.ENC"
open to write 2,"TEMP.ENC"
do
read string 1,tempstr$
write string 2,encrypt_string(tempstr$)
if FILE END(1)=1 then exit
loop
close file 1
close file 2
DELETE FILE file$
RENAME FILE "TEMP.ENC", file$
`else statment for error trap requires msgbox.dll avalible from http://winch.pinkbile.com/msgbox.php
`delete else statment if you don't have msgbox.dll/ couldn't be
`bothered getting it.
else
msgbox "ERROR: No file to encrypt!"
endif
endfunction
function encrypt_string(string$)
i=1
for i=1 to len(string$)
encrypt=(asc(MID$(String$,i)))+40
returnstr$=returnstr$+chr$(encrypt)
next i
endfunction returnstr$
function decrypt_string(string$)
`just a precautionary value reset
i=1
for i=1 to len(string$)
encrypt=(asc(MID$(String$,i)))-40
returnstr$=returnstr$+chr$(encrypt)
next i
endfunction returnstr$
Clever code is fast code