Results 1 to 13 of 13

Thread: urgent help needed if possible

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    urgent help needed if possible

    I use the following function to encrypt data and save it to the registry
    VB Code:
    1. Public Function EncryptPassword(strPass As String) As String
    2.   Dim XOR_String As String
    3.   Dim i As Integer
    4.  
    5.   For i = 1 To Len(strPass)
    6.     XOR_String = XOR_String & Chr(Asc(Mid(strPass, i, 1)) Xor ((i * 5) Mod 256))
    7.   Next i
    8.  
    9.   EncryptPassword = XOR_String
    10. End Function
    I know it is not secure, but the point was not to secure the data, just to really not make it readable and deter a user from editing the values themselves...

    anyway our product has a CD key that is validated in the app using a simple algorithm. A problem was realized when a customer was able to activate with the key but then the internal function that validates it failed. Long story short, i found out that the encryption function produces odd results when certain characters are in certain locations in the string

    XXXX-XXXX-7XXX-XXXX
    XXXX-XXXX-XXAX-XXXX
    XXXX-XXXX-XXXF-XXXX
    XXXX-XXXX-XXXX-PXXX
    XXXX-XXXX-XXXX-XUXX
    XXXX-XXXX-XXXX-XXZX

    I found this out by writing a quick program that encrypted and then decrypted each possible value and compaired it to the original string. So when the above keys have the certain char in a certain position this error occurs. I think the conversion may make it a carrage return or some unreadable character which is causing the error....

    any ideas?

    To test this out... pass "XXXX-XXXX-XXXF-XXXX" to the function to encrypt it and then decrypt it and compare to the original string.. it is cut off at the bad character...

  2. #2

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    further testing indicates that it is producing a character 0 for some of the encrypted values which is of course null which would explain the problem...

    perhaps this function is just no good to use....

  3. #3

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    i found if i change the multiplication factor of the xor value to 2 instead of 5 it does not produce any bad keys.. going to test it with all values to see if it will work though

    VB Code:
    1. Public Function EncryptPassword(strPass As String) As String
    2.   Dim XOR_String As String
    3.   Dim i As Integer
    4.   For i = 1 To Len(strPass)
    5.     XOR_String = XOR_String & Chr(Asc(Mid(strPass, i, 1)) Xor ((i * 2) Mod 256))
    6.   Next i
    7.  
    8.   EncryptPassword = XOR_String
    9. End Function

  4. #4
    Frenzied Member
    Join Date
    May 2003
    Location
    So Cal
    Posts
    1,564
    You know they put people away for talking to themselves right?

  5. #5
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Concur. Any value higher than 2 produces decimal values less than 33 (outside the range of a valid Ascii character)

    This line (in the For Next) demonstrates it well:

    Debug.Print Asc(Mid(strPass, i, 1)) Xor ((i * 5) Mod 256)




    Bruce.

  6. #6

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    BrainS thanks for nothing

    Bruce, yeah I found that it will work fine changing it to 2 except the problem will still be present when using longer strings. Do you know of any way I can modify the function to only work with valid ASCII characters?

  7. #7
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Moding with 16 seems to work with the limited testing I did.

  8. #8
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Actually 32 seems to be fine aswell.

    Xor ((i * 5) Mod 32)

  9. #9
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    I have no solution to it sorry...but have you seen the basic encryption example at Lucky's???


    Havn't looked at it my self. But I remember I saw it here...

    http://rookscape.com/vbgaming/encrypt.zip

  10. #10

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    Originally posted by Bruce Fox
    Actually 32 seems to be fine aswell.

    Xor ((i * 5) Mod 32)
    thanks, I was able to modify the function and fix the problem (i hope )

  11. #11
    Frenzied Member
    Join Date
    May 2003
    Location
    So Cal
    Posts
    1,564
    Not in a good mood? Learn to take a joke once in awhile, you'll live longer.

    Originally posted by kleinma
    BrainS thanks for nothing


  12. #12

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    Originally posted by BrianS
    Not in a good mood? Learn to take a joke once in awhile, you'll live longer.
    When someone posts a request for urgent help and all you can do is drop a lame joke, it is annoying. I am all for fun, but just not in a situation like this where I need to find a fix for software that is being used by customers... sorry

  13. #13
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    Not sure if you still need this but lf you do then look at this sample by Randy Birch.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width