Click here to Skip to main content
15,921,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Friends! I have downloaded a VB Source Code. In this source code I have found a Function. The Function is as follows

VB
Private Function XorPassword(Bytes As Variant) As String
    Dim XorBytes()      As Variant
    Dim strPassword     As String
    Dim intIndex        As Integer
    Dim CurrChar        As String * 1
    XorBytes = Array(&H86, &HFB, &HEC, &H37, &H5D, &H44, &H9C, &HFA, &HC6, &H5E, &H28,HE6, &H13, &HB6, &H8A, &H60, &H54, &H94)
    strPassword = vbNullString
    intIndex = 0
    Do
    'Get a character from the password by doing a XOR with the
    'appropriate value in XorBytes array.
        CurrChar = Chr$(Bytes(intIndex + &H42) Xor XorBytes(intIndex))
        'If we get a Null character, get out of the loop.
        If Asc(CurrChar) = 0 Then Exit Do
        'Add the password character to the accumulated password string.
        strPassword = strPassword & CurrChar
        intIndex = intIndex + 1
    Loop Until intIndex = 17
    XorPassword = strPassword
End Function


In this Function I could not understand the following array

XorBytes = Array(&H86, &HFB, &HEC, &H37, &H5D, &H44, &H9C, &HFA, &HC6, &H5E, &H28,HE6, &H13, &HB6, &H8A, &H60, &H54, &H94)


My Question is that Why he has used these Hex Values in this array and what is the logic behind that?

Plz Help me about this. I will be thankful to you.
Posted

If you're looking to use this code in your own application, don't. This is a very trivial "encryption" scheme, very easily broken, and with the encryption values hard coded into the code, if someone does break it, you can't change the key.
 
Share this answer
 
Comments
Manfred Rudolf Bihy 19-Nov-10 7:50am    
I agree with you Dave! The data should not be hardcoded into the application. But if a sufficiently random "One time pad" is used the encryption is unbreakable unless of course the enemy gets access to said pad
Hello Rashid,

this is a very trivial algorithm to encode acertain portion of an array of bytes. The encoded section of the array starts at position 66 dec. and can be at most 17 characters long. A zero byte terminates the encoding when the section does not extend 17 characters.

This kind of encoding works analog to the "one time pad" encryption scheme:
A xor B = C
C xor B = A

For every position in the string a different byte is used to encode and
when feeding the encoded string into the function the effect is that of decoding it into the original.

A is the input, C is the output and B is the special hex code from the array.

Hope this helps!

Cheers

Manfred
 
Share this answer
 
v2
Comments
rashidfarooq 18-Nov-10 8:36am    
Thanks for answering me.
But Is it necessary to use this sequence (H86, &HFB, &HEC, &H37, &H5D, &H44, &H9C, &HFA, &HC6, &H5E, &H28,HE6, &H13, &HB6, &H8A, &H60, &H54, &H94)?
If it is necessary then why?
Manfred Rudolf Bihy 18-Nov-10 8:46am    
If it really must be that sequence depends on how the encrypted string is used at a later time. Why don't you try out the function with a string of approriate length and see what the result is after you passed it to the function? You can also analyze your project to see where that XorPassword function is called and out of what contexts. What is the program doing with the encrypted string?
Manfred Rudolf Bihy 18-Nov-10 8:49am    
The way I see it for now is that the array contains a "One Time Pad" that is used in a very simplistic encryption scheme. If the function does both encrypting and decrypting, the content could be any random byte sequence of the appropriate length.
rashidfarooq 18-Nov-10 10:48am    
Thanks a lot for answering me briefly.
It looks (to me) an awkward way to encrypt (or decrypt) the passed Bytes .

The XorBytes array is the key for the encrypt (or decrypt) operation.
:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900