simple encryption

BlitzPlus Forums/BlitzPlus Programming/simple encryption

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Hi, I wrote this little snippet to encrypt a text file to mainly prevent "normal" prying eyes.
Ive tried entering many paragraphs (200k characters)for the string and it seems to work fine encrypting and decrypting.

Note: It wouldn't be too difficult to add a key or salt to this code.

Please give me your thoughts. Also its free to use if anyone wants. If its worthy of the codearchive, I'll post it there :)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; the following is to test the encryption
; 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;encrypt string
result$ = Enc_e$("Put your string to encrypt here!")
Print result$

;decrypt string
result$ = Enc_d$(result$)
Print result$

WaitKey()


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ENCRYPTION FUNCTIONS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Enc(ryption)_e(ncrypt)
;description: encrypts a string n$
;
Function Enc_e$(n$)
	l$ = Len(n$)
	For x  = 1 To l$
		t  = Asc(Mid(n$,x,1))
		r$ = r$ +  Chr$( (t-x) - f(x))		
	Next
	Return r$
End Function

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Enc(ryption)_d(ecrypt)
;description: decrypts an encrypted string n$
;
Function Enc_d$(n$)
	l$ = Len(n$)
	For x  = 1 To l$
		t  = Asc(Mid(n$,x,1))
		r$ = r$ +  Chr$( (t+x) + f(x) )		
	Next
	Return r$
End Function

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;f(n) 
;description: used to aid encryption
;
Function f%(n)
	r = n Shl 1
	r = (r Mod 256)
	Return r%
End Function