Rem Project: File Encryption 2 - Encrypt
Rem Created: 09/02/2005 22:47:46
 
Rem ***** Main Source File *****
Rem Set the xoring thing (~~) to the keyword
#constant xor ~~
 
Rem Run the function taking the input, outputting to "encrypted.txt" using the key
en64("input.txt","encrypted.txt","key.txt")
 
Rem I love this command
end
 
Rem Define the function, it takes 3 files as strings
function en64(inputFile$ as string, outputFile$ as string, keyFile$ as string)
 
   Rem Open the files
   open to read 1,inputFile$
   open to write 2,outputFile$
   open to read 3,keyFile$
 
   Rem Sort the key file into an array
   dim key64(63) as integer
   read string 3,key$
   for a=0 to 63
      key64(a) = asc(mid$(key$,a))
   next a
 
      c=0
      Rem Begin the read|convert|write loop
      repeat
         Rem Clear the write var
         write$ = ""
         Rem Read
         read string 1,read$
         readLen = len(read$)
         b=0
 
         Rem Loop through the characters whole line
         for a=0 to readLen
 
            Rem get the ascii value for each char
            ascii = asc(mid$(read$,a))
            Rem get the key value to use
            key = key64(b)+c
            Rem xor the two..I added the key to the ascii value before the xor to make it even harder :)
            xord = (ascii + key) xor key
            char$ = chr$( xord )
 
            Rem this makes the key seed better :)
            inc b : if b >= 63 then b=0
            Rem add the new char to the string
            write$ = write$ + char$
         next a
 
         Rem even more wierd key seeding
         inc c : if c=10 then c=0
         Rem Write
         write string 2,write$
      until file end(1)=1
 
   Rem Close/Finalise the files
   close file 1 : close file 2 : close file 3
 
endfunction
 
 
Rem Project: File Encryption 2 - Decrypt
Rem Created: 09/02/2005 22:47:46
 
Rem ***** Main Source File *****
Rem xor needs to be ~~ for readability
#constant xor ~~
 
Rem same as last time
de64("encrypted.txt","decrypted.txt","key.txt")
 
Rem wooo
end
 
Rem Ok this one is the hard one, I had to change the middle bit only but it didn't go cleanly
Rem so its where the bugs are :P
function de64(inputFile$ as string, outputFile$ as string, keyFile$ as string)
 
   Rem Open the files
   open to read 1,inputFile$
   open to write 2,outputFile$
   open to read 3,keyFile$
 
   Rem Sort the key file into an array
   dim key64(63) as integer
   read string 3,key$
   for a=0 to 63
      key64(a) = asc(mid$(key$,a))
   next a
 
      c=0
      Rem Begin the read|convert|write loop
      repeat
         Rem Clear the write var
         write$ = ""
         Rem Read
         read string 1,read$
         readLen = len(read$)
 
         b=0
 
         for a=0 to readLen
 
            Rem Get the ascii value
            ascii = asc(mid$(read$,a))
            Rem Work out the key based on b and c
            key = key64(b)+c
            Rem xor it back
            xord = ascii xor key
            Rem Remove the key (remember, I added it) and convert at the same time
            char$ = chr$( xord - key )
 
            Rem The key stuff
            inc b : if b >= 63 then b=0
            write$ = write$ + char$
         next a
 
         Rem Wierd key crap
         inc c : if c=10 then c=0
         Rem Write
         write string 2,write$
      until file end(1)=1
 
   Rem Close/Finalise the files
   close file 1 : close file 2 : close file 3
 
endfunction
 
 
Rem Project: Key Generation
Rem Created: 16/03/2005 20:52:04
 
Rem ***** Main Source File *****
 
Rem If the file exists, nuke the bugger :D
if file exist("key.txt")=1 then delete file "key.txt"
 
Rem Open it to write on it
open to write 1,"key.txt"
 
Rem Randomise to the timer + a random number from the timer...pretty random
randomize (timer()+rnd(timer()))
 
Rem Loop
for a=1 to 64
   Rem Add a char to the string, the +50 makes it avoid annoying low ASCII value characters
   string$ = string$ + chr$(rnd(200)+50)
next a
 
Rem Write it and close
write string 1,string$
close file 1
 
Rem END: My favourite command
end