Selling [VB6] Basic Encryption with XOR in VB6

Discussion in 'Guides for Sale - Buy & Sell' started by Games, 7/29/15.

Thread Status:
Not open for further replies.
  1. Games

    Games
    Expand Collapse
    Bot Status (Automated): Handles automated general support inquiries

    Offline
    Joined:
    9/20/13
    Posts:
    525,068
    Likes Received:
    61
    For those of you not familiar with XOR in Visual Basic 6, I'll give you a little lesson. XOR is supposed to mean "exclusive OR". It is so called because it only returns True if one and only one of the expressions it is passed is True. Wait, that sounds confusing An illustration is in order!

    True Xor True = False

    True Xor False = True

    False Xor True = True

    False Xor False = False

    See? Now, the logical operations of XOR (above) are less useful to us than the bitwise operations. Observe:

    1 Xor 1 = 0

    1 Xor 0 = 1

    0 Xor 1 = 1

    0 Xor 0 = 0

    This is pretty much the same as the logical operation, but watch, in VB6 we can perform it on a whole bunch of bits (say... a BYTE!) at a time:

    11111111

    XOR

    01010101 (Key)

    Result:

    10101010

    Here comes the magic.. if we XOR again, using the value I've marked Key and the result, we obtain the original!

    10101010 (Old Result)

    XOR

    01010101 (Key)

    Result:

    11111111 (!!!)

    This works in all situations when the key is held constant: XOR once, you have an encrypted result. XOR again with the same key, and you get the original value. Sounds cool, but how can we apply it practically? When storing data in a binary file, it is a simple matter to XOR each byte that is read or written in order to encrypt/decrypt it. To encrypt data under other circumstances can be a little trickier. You need to coerce that data into byte form, and then back again. We'll do it with strings here:

    Dim strResult As String

    Dim strChar1 As String * 1

    Dim strChar2 As String * 1

    strChar1 = "E"

    strChar2 = "z"

    strResult = Chr(Asc(strChar1) Xor Asc(strChar2))

    This code will XOR "E" with "z" by converting them to their ASCII values! Once converted to ASCII, they can be treated like bytes and XOR'ed. We can then convert back to string format using the Chr function. This method can be adapted using a For loop to encrypt complex strings using equally complex key values. I hope this visual basic tutorial was helpfull to you.

    thanks

    Xor is hard to explain,but you did it well

    Thanks people Im doing VB6 since some weeks and i thinking about to make more Tutorials
     
    • This user is inactive. Hasn't logged into their account in over 60 days.
Thread Status:
Not open for further replies.