@=PRoF=
I sure you would have fixed it quickly once you felt you had the time.
@BatVink
OMGossh, I've been modded. :LOL:
@Kevin Picone
Now as far as a veteran -- meaning a veteran of the boards -- you're definitely one of the earliest members I've seen. You've got 5 years on me.
Thanks for the optimization tips. They do work.
@Everyone who is interested
Here is the code that includes the optimization suggested by Kevin.
global code$ as string
global data$ as string
global lendata as integer
global lencodekey as integer
if file exist("log.txt")
delete file "log.txt"
endif
open to write 15, "log.txt"
Code$ = "password"
data$ = "Test Data"
lendata = len(data$)
lencodekey = len(code$)
strXOREncryption$ = xorencryption(code$,data$,lendata,lencodekey)
print strXOREncryption$
write string 15,strXOREncryption$
strXORDecryption$ = XORDecryption(code$,strXOREncryption$,lendata,lencodekey)
print strXORDecryption$
write string 15,strXORDecryption$
wait key
end
Function XOREncryption(CodeKey$ As String, DataIn$ As String, DataInSize as integer, CodeKeySize as integer)
local DataPtr As integer
local strDataOut$ As String
local temp As Integer
local tempstring As String
local intXOrValue1 As Integer
local intXOrValue2 As Integer
local strXOREncryption$ as string
For DataPtr = 1 to DataInSize
`The first value to be XOr-ed comes from the data to be encrypted
intXOrValue1 = Asc(Mid$(DataIn$, DataPtr))
`The second value comes from the code key
intXOrValue2 = Asc(Mid$(CodeKey$, (DataPtr Mod CodeKeySize) + 1))
temp = (intXOrValue1 xor intXOrValue2)
if temp<16
strDataOut$ = strDataOut$ + "0"+Hex$(temp)
else
strDataOut$ = strDataOut$ + Hex$(temp)
endif
Next DataPtr
EndFunction strDataOut$
Function XORDecryption(CodeKey$ As String, DataIn$ as string, DataInSize as integer, CodeKeySize as integer)
local DataPtr As integer
local strDataOut$ As String
local intXOrValue1 As Integer
local intXOrValue2 As Integer
local strxordecryption$ as string
local temp1$ as string
local temp as integer
local strXOREncryption$ as string
For DataPtr = 1 to DataInSize
`The first value to be XOr-ed comes from the data to be decrypted
temp1$ = Mid$(DataIn$, (2 * DataPtr) - 1)
temp1$ = temp1$ + Mid$(DataIn$, (2 * DataPtr))
temp = hex to decimal( temp1$ )
intXOrValue1 = temp
`The second value comes from the code key
temp1$ = Mid$(CodeKey$, (DataPtr Mod CodeKeySize) + 1)
intXOrValue2 = Asc(temp1$)
strDataOut$ = strDataOut$ + Chr$(intXOrValue1 xor intXOrValue2)
Next DataPtr
EndFunction strDataOut$

Terry