In my opinion, these are good functions! I created them in around 2 minutes (maybe 3-4), but the idea was thought of in a split second.
This is for DarkBASIC Pro
Here it is compressed (And doesnt work with 5.9, however is untested otherwise)
REM Project: 20-liner encode/decode functions
REM Created: 7/7/2006 4:31:56 PM
REM
REM ***** Main Source File *****
REM
`Muwahahaha! I have done this one in 8 lines ;P
`DO NOT USE THIS ON EXECUTABLE FILES! YOU ALSO MUST KNOW HOW MANY
`CHARACTERS ARE IN THE FILE.
`example
open to write 1,"test.txt" : write string 1,"This is a test encode/decode file." : write string 1,"This is meant to be encoded..." : close file 1 : print "Not messed with..." : open to read 1,"test.txt" : repeat : read string 1,text$ : print text$ : until file end(1)=1 : close file 1
encode("test.txt",0x5B,63) : print "Encoded." : open to read 1,"test.txt" : repeat : read string 1,text$ : print text$ : until file end(1)=1 : decode("test.txt",0x5B,63) : print "It has been decoded..." : suspend for key : end
function encode(file$,level#,amount#) : if file open(1)=1 : close file 1 : endif
if file exist("temp.bin")=1 : delete file "temp.bin" : endif : open to write 1,"temp.bin" : p#=0 : ready#=0 : repeat : byte#=read byte from file(file$,p#) : p#=p#+1 : write byte 1,byte#+level#
if p#=amount# : ready#=1 : endif : if p#>amount# : ready#=1 : endif : until ready#=1 : close file 1 : delete file file$ : rename file "temp.bin",file$ : endfunction
function decode(file$,level#,amount#) : if file open(1)=1 : close file 1 : endif : if file exist("temp.bin")=1 : delete file "temp.bin" : endif
open to write 1,"temp.bin" : p#=0 : ready#=0 : repeat : byte#=read byte from file(file$,p#) : p#=p#+1 : write byte 1,byte#-level# : if p#=amount# : ready#=1 : endif : if p#>amount# : ready#=1 : endif
until ready#=1 : close file 1 : delete file file$ : rename file "temp.bin",file$ : endfunction
`This has been created by dbuser2006+, for comments, email me at darktwilight@rock.com. This was made specifically for the
`20 line challenge (And for my games). You can use this however you like, though, if you use it in game, i would appreciate
`it if you mention my user name, or that it is not yours somewhere in the game. But it is not required. As for how you use it,
`uncompress this to make the programming a little easier to see, (For some reason 5.9 users can't run it like this, hopefully
`that has been fixed for 6.0, 6.1, or 6.2...), now you have yourself a program, go ahead and run it. The example allows you to
`easily understand how to use this. Now you just have to use encode(filename,levelofencoding,amountofencoding) or decode with
`the same syntax of encode. Now you can safely create your own saves! (and loads)
And uncompressed and working!
REM Project: 20-liner encode/decode functions
REM Created: 7/7/2006 4:31:56 PM
REM
REM ***** Main Source File *****
REM
`DO NOT USE THIS ON EXECUTABLE FILES! YOU ALSO MUST KNOW HOW MANY
`CHARACTERS ARE IN THE FILE.
`example
open to write 1,"test.txt"
write string 1,"This is a test encode/decode file."
write string 1,"This is meant to be encoded..."
close file 1
print "Not messed with..."
open to read 1,"test.txt"
repeat
read string 1,text$
print text$
until file end(1)=1
close file 1
encode("test.txt",0x5B,63)
print "Encoded."
open to read 1,"test.txt"
repeat
read string 1,text$
print text$
until file end(1)=1
decode("test.txt",0x5B,63)
print "It has been decoded..."
suspend for key
end
function encode(file$,level#,amount#)
if file open(1)=1 then close file 1
if file exist("temp.bin")=1 then delete file "temp.bin"
open to write 1,"temp.bin"
p#=0
ready#=0
repeat
byte#=read byte from file(file$,p#) : p#=p#+1
write byte 1,byte#+level#
if p#=amount# : ready#=1 : endif
if p#>amount# : ready#=1 : endif
until ready#=1
close file 1
delete file file$
rename file "temp.bin",file$
endfunction
function decode(file$,level#,amount#)
if file open(1)=1 then close file 1
if file exist("temp.bin")=1 then delete file "temp.bin"
open to write 1,"temp.bin"
p#=0
ready#=0
repeat
byte#=read byte from file(file$,p#) : p#=p#+1
write byte 1,byte#-level#
if p#=amount# : ready#=1 : endif
if p#>amount# : ready#=1 : endif
until ready#=1
close file 1
delete file file$
rename file "temp.bin",file$
endfunction
Because of the way I uncompressed the uncompressed version, some functions might be missing, but the concept remains the same!
Feel free to comment. Also I have created a file browser function, it will be released next edit...
[EDIT] I'm doing something for the fpsc level contest right now, so i'm not going to edit anything, instead, i will show what i think was my source code....
sync on
main:
perform checklist for files
max#=checklist quantity()
repeat
until scancode()=0
do
cls
b4$="" : b3$="" : b2$="" : b1$=""
a1$="" : a2$="" : a3$="" : a4$=""
if upkey()=1 : cur#=cur#-1 : wait 0100 : endif
if downkey()=1 : cur#=cur#+1 : wait 0100 : endif
if cur#<1 : cur#=1 : endif
if cur#>max# : cur#=max# : endif
b4#=cur#-4 : b3#=cur#-3 : b2#=cur#-2 : b1#=cur#-1
a1#=cur#+1 : a2#=cur#+2 : a3#=cur#+3 : a4#=cur#+4
if b4#<1 : else : b4$=checklist string$(b4#) : endif
if b3#<1 : else : b3$=checklist string$(b3#) : endif
if b2#<1 : else : b2$=checklist string$(b2#) : endif
if b1#<1 : else : b1$=checklist string$(b1#) : endif
if a1#>max# : else : a1$=checklist string$(a1#) : endif
if a2#>max# : else : a2$=checklist string$(a2#) : endif
if a3#>max# : else : a3$=checklist string$(a3#) : endif
if a4#>max# : else : a4$=checklist string$(a4#) : endif
cur$=checklist string$(cur#)
ink rgb(128,128,128),0
center text 320,20,b4$
center text 320,40,b3$
center text 320,60,b2$
center text 320,80,b1$
ink rgb(255,255,255),0
center text 320,100,cur$
ink rgb(128,128,128),0
center text 320,120,a1$
center text 320,140,a2$
center text 320,160,a3$
center text 320,180,a4$
sync
if returnkey()=1 then goto _select
if escapekey()=1 then end
loop
_select:
if cur#=1 then goto "C:"
if cur#=2 then goto ".."
if cur#>2
if file exist(cur$)=0 : set dir cur$ : endif
if file exist(cur$)=1 : execute file cur$ : endif
goto main
endif
`If for some reason that i can't think of, select has failed
`to goto main, it will goto mian
goto main
Edit of 5-05-07
What? You mean I cant sleep here???