This sample application will read a file called "test1.txt", encrypt it into a file called "test2.txt", and finally decrypt it back into a file called "test3.txt".
The commands can only encrypt and decrypt strings, so make sure you don't stick any null bytes in there.
`Encrypter:
encrypt_file("test1.txt","test2.txt","4g954yhbdb9u")
decrypt_file("test2.txt","test3.txt","4g954yhbdb9u")
wait key
function encrypt_string(str as string, key2 as string)
str2 as string
key3 as string
str3 as string
str4 as string
ascii_code as integer
For i = 1 to LEN(str)
key3=MID$(key2,1+(i mod LEN(key2)))
str3=MID$(str,i)
ascii_code=ASC(str3)+ASC(key3)
IF ascii_code>127 then ascii_code=ascii_code-96
IF ascii_code<32 then ascii_code=ascii_code+96
IF ascii_code>127 then ascii_code=ascii_code-96
IF ascii_code<32 then ascii_code=ascii_code+96
str4=CHR$(ascii_code)
str2=str2+str4
Next i
endfunction str2
function decrypt_string(str as string, key2 as string)
str2 as string
key3 as string
str3 as string
str4 as string
ascii_code as integer
For i = 1 to LEN(str)
key3=MID$(key2,1+(i mod LEN(key2)))
str3=MID$(str,i)
ascii_code=ASC(str3)-ASC(key3)
IF ascii_code>127 then ascii_code=ascii_code-96
IF ascii_code<32 then ascii_code=ascii_code+96
IF ascii_code>127 then ascii_code=ascii_code-96
IF ascii_code<32 then ascii_code=ascii_code+96
str4=CHR$(ascii_code)
str2=str2+str4
Next i
endfunction str2
function read_encrypted_string(key as string, filenum as integer)
str as string
If file end(filenum)=0
read string filenum,str
str=decrypt_string(str,key)
endif
endfunction str
function write_encrypted_string(str as string, key as string, filenum as integer)
If file end(filenum)=0
str=encrypt_string(str,key)
write string filenum,str
endif
endfunction
function encrypt_file(filename_in as string, filename_out as string, key as string)
str as string
filenum=0
Do
inc filenum
If file open(filenum)=0 then exit
Loop
open to read filenum,filename_in
filenum2=0
Do
inc filenum2
If file open(filenum2)=0 then exit
Loop
open to write filenum2,filename_out
Do
read string filenum,str
write_encrypted_string(str,key,filenum2)
IF file end(filenum) then exit
Loop
close file filenum : close file filenum2
endfunction
function decrypt_file(filename_in as string, filename_out as string, key as string)
str as string
filenum=0
Do
inc filenum
If file open(filenum)=0 then exit
Loop
open to read filenum,filename_in
filenum2=0
Do
inc filenum2
If file open(filenum2)=0 then exit
Loop
open to write filenum2,filename_out
Do
str=read_encrypted_string(key,filenum)
write string filenum2,str
IF file end(filenum) then exit
Loop
close file filenum : close file filenum2
endfunction
The optomist's right, The pessimist's right.