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


Public

Tested

My Own 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 329 Downloads 69

Classic ASP Protection
ANmarAmdeen
696
Attachments
Revisions

v1.0