|
-
Mar 2nd, 2004, 05:21 PM
#1
urgent help needed if possible
I use the following function to encrypt data and save it to the registry
VB Code:
Public Function EncryptPassword(strPass As String) As String
Dim XOR_String As String
Dim i As Integer
For i = 1 To Len(strPass)
XOR_String = XOR_String & Chr(Asc(Mid(strPass, i, 1)) Xor ((i * 5) Mod 256))
Next i
EncryptPassword = XOR_String
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...
-
Mar 2nd, 2004, 05:32 PM
#2
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....
-
Mar 2nd, 2004, 05:39 PM
#3
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:
Public Function EncryptPassword(strPass As String) As String
Dim XOR_String As String
Dim i As Integer
For i = 1 To Len(strPass)
XOR_String = XOR_String & Chr(Asc(Mid(strPass, i, 1)) Xor ((i * 2) Mod 256))
Next i
EncryptPassword = XOR_String
End Function
-
Mar 2nd, 2004, 05:51 PM
#4
Frenzied Member
You know they put people away for talking to themselves right?
-
Mar 2nd, 2004, 06:14 PM
#5
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.
-
Mar 2nd, 2004, 06:20 PM
#6
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?
-
Mar 2nd, 2004, 06:34 PM
#7
Moding with 16 seems to work with the limited testing I did.
-
Mar 2nd, 2004, 06:37 PM
#8
Actually 32 seems to be fine aswell.
Xor ((i * 5) Mod 32)
-
Mar 2nd, 2004, 06:44 PM
#9
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
-
Mar 3rd, 2004, 10:36 AM
#10
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 )
-
Mar 3rd, 2004, 10:51 AM
#11
Frenzied Member
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
-
Mar 3rd, 2004, 11:25 AM
#12
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
-
Mar 11th, 2004, 02:51 PM
#13
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|