Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Xor Encryption
#2
Code:
Public Function Encryption(CodeKey As String, DataIn As String) As String
Dim lonDataPtr As Long
Dim strDataOut As String
Dim intXOrValue1 As Integer
Dim intXOrValue2 As Integer

    For lonDataPtr = 1 To Len(DataIn)
    
        intXOrValue1 = Asc(Mid$(DataIn, lonDataPtr, 1))
        intXOrValue2 = Asc(Mid$(CodeKey, ((lonDataPtr Mod Len(CodeKey)) + 1), 1))
        
        strDataOut = strDataOut + Chr$(intXOrValue1 Xor intXOrValue2)
    
    Next
    
    Encryption = strDataOut
  
End Function

Something like this:

To encrypt

Encryption("key", "somebodyspassword")

To decrypt

Encryption("key", Encryption("key", "somebodyspassword"))

To explain it better, you encrypt once to encrypt, encrypt twice to decrypt.

When the string first goes in, it encrypts it to something like 22dfs432f mixing in some ASCII characters and what-not. If the key is not right when it gets unencrypted, it will still be jumbled up and won't come out the same way it came in. For example saving a password you would have the normal string password, which you encrypt, save it, then when you load you would encrypt again (double encryption = decryption), if the password doesn't match then you know the key for the encryption was wrong or they just got the password wrong.

Any questions? I'm trying to explain this.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)