Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Xor Encryption
#1
Can someone please explain this to me? I've been screwing around w/ it, and I managed to get:

Code:
Private Sub Form_Load()
    Dim Test 1 As String
    Dim Test As String
    Test1 = 0
    Test = 1
    lblLabel1.Caption = Chr(Asc(Test)) Xor Chr(Asc(Test1))
End Sub

But I still don't really get it. How can Xor be used practically? Etc, etc. Like lets say I wanted to encrypt a password with Xor, how would I do this?
Reply
#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
#3
http://en.wikipedia.org/wiki/XOR_cipher
Reply
#4
Thanks for the help guys. I think I can manage this. I just need to look over the function and dissect it so that I can get a better understanding, if I need any more help I'll just post here again. Smile
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)