ads

Friday, December 7, 2007

XOR Encryption in VB


Public Function XOREncryption(CodeKey As String, DataIn As String) As String
Dim lonDataPtr As Long
Dim strDataOut As String
Dim intXOrValue1 As Integer, intXOrValue2 As Integer



For lonDataPtr = 1 To Len(DataIn)
'The first value to be XOr-ed comes from
' the data to be encrypted
intXOrValue1 = Asc(Mid$(DataIn, lonDataPtr, 1))
'The second value comes from the code ke
' y
intXOrValue2 = Asc(Mid$(CodeKey, ((lonDataPtr Mod Len(CodeKey)) + 1), 1))
strDataOut = strDataOut + chr(intXOrValue1 XOr intXOrValue2)
Next lonDataPtr
XOREncryption = strDataOut
End Function


'USAGE
Private Sub cmdEncryptdecrypt_Click()
Dim strCodeKey As String
strCodeKey = InputBox("Please enter your password", "XOr Encryption")
txtSource.Text = XOREncryption(strCodeKey, txtSource.Text)



End Sub


1 comment:

Steven said...

hi.im want to know why when my string = "a" code key = "HI" and my result is "(".isit possible to write down the workings? thanks

Google Search