Code archives/File Utilities/File Encryption/Decryption

This code has been declared by its author to be Public Domain code.

Download source code

File Encryption/Decryption by fall_x2005
This is far from secure, but should be good enough for level data, save games, etc ...
; example :

key$="PutYourKeyHere"
EncryptFile("original.txt","encrypted.txt",key$)
DecryptFile("encrypted.txt","decrypted.txt",key$)

; functions :

Function EncryptFile(in$,out$,k$)
	filein = ReadFile(in$)
	fileout = writeFile(out$)
	s$=""
	while not eof(filein)
		s$=s$+chr(ReadByte( filein ))
	wend
	
	backwards=false
	for i%=1 to len (s$)
		c$=Mid(s$,i%,1)
		a%=asc(c$)
		j%=i%
		while j%>len(k$)
			j%=j%-len(k$)
		wend
		if backwards then j%=len(k$)-j%+1
		if j=1 then backwards=false
		if j=len(k) then backwards=true
		kc$=Mid(k$,j%,1)
		ka%=asc(kc$)
		enc%=ka%+a%
		
		writeshort(fileout,enc)
		
	next
	
	closefile filein
	closefile fileout
	
end function


function DecryptFile(in$,out$,k$)
	filein = ReadFile(in$)
	fileout = writeFile(out$)
	i=0
	backwards=false
	while not eof(filein)
		i=i+1
		;s$=s$+chr(ReadByte( filein ))
		enc%=readshort(filein)
		
		j%=i%
		while j%>len(k$)
			j%=j%-len(k$)
		wend
		if backwards then j%=len(k$)-j%+1
		if j=1 then backwards=false
		if j=len(k) then backwards=true
		kc$=Mid(k$,j%,1)
		ka%=asc(kc$)
		a%=enc%-ka%
		writebyte fileout,a%
	wend
	
	closefile filein
	closefile fileout

end function

Comments

BlackD2005
.


Rook Zimbabwe2005
Looks good!
RZ


mv3332013
This didn't work when i tried a large text file (1488 kb). I didn't have this problem with another encrypter from the code archives (Simple Encrypter/Decrypter).


Code Archives Forum