Didn't really plan to post this (since there are enough stuff like this laying around). But maybe someone likes it, at least it's more secure than the "simple ones", and it's damn easy to use. Feel free to customize.
Code: Select all
Procedure XOrCrypt(*Buffer,Len.l,Key$)
;just some weird xor encryption algorithm by JLC
Protected i, Byte.b, KeyByte.b
Protected KeyLength = Len(Key$), KeyPos
For i=0 To Len-1
Byte = PeekB(*Buffer+i)
KeyByte = PeekB(@Key$+KeyPos)
;PeekB(*Buffer+i) ! PeekB(@Key$+KeyPos) ! Len ! i
Byte ! KeyByte ! Len ! i ! KeyLength ;xor the shit
PokeB(*Buffer+i,Byte)
KeyPos + 1
If KeyPos > KeyLength
KeyPos = 0
EndIf
Next
EndProcedure
String$ = "the string to be encrypted"
Length = Len(String$)
XOrCrypt(@String$,Length,"key of whatever length") ;encrypt
Debug String$ ;if it looks cut that's because a null-char. terminates it
XOrCrypt(@String$,Length,"key of whatever length") ;decrypt
Debug String$