XorD

Encrypt or decrypt a string using a key
Similar to XorC, except you get to decide what to do, encrypt or decrypt
Will return the data encrypted (or decrypted depend on bProtect) using the sKey
bProtect = True to encrypt, false to decrypt

CodeFunctionName
What is this?

Public

Tested

Original Work
Function XorD(sData, sKey, bProtect)
' bProtect = true to encrypt = protect file or lock file
' = false to decrypt = unprotect or open file
Dim l, i, byIn(), byOut(), byKey()
If Len(sData) = 0 Or Len(sKey) = 0 Then XorC = "Invalid argument(s) used": Exit Function
bEncOrDec = bProtect 'encryption
byIn = sData
byOut = sData
byKey = sKey
l = LBound(byKey)
For i = LBound(byIn) To UBound(byIn) - 1 Step 2
byOut(i) = ((byIn(i) + Not bEncOrDec) Xor byKey(l)) - bEncOrDec 'avoid Chr$(0) by using bEncOrDec flag
l = l + 2
If l > UBound(byKey) Then l = LBound(byKey) 'ensure stay within bounds of Key
Next i
XorC = byOut
End Function

sData, sKey, bProtect

Views 1,470

Downloads 439

CodeID
DB ID