|
-
November 6th, 2009, 12:19 PM
#8
Re: Xor on string--help me please
No, I'm getting a different result. Let me show you how I did it:
Code:
Private Sub XORTest()
'data Value Is "7CA674"
'key is "17767FA"
'time is "25127000"
'result is 376456
Dim dat$, key$, tim$ 'the strings
Dim ld%, lk%, lt%, lm1%, lmin% 'being the lengths and minimum
Dim i%, res$
dat = "7CA674"
key = "17767FA"
tim = "25127000"
ld = Len(dat)
lk = Len(key)
lt = Len(tim)
'get the minimum in 2 steps for better overview
lm1 = IIf(ld < lk, ld, lk)
lmin = IIf(lt < lm1, lt, lm1)
'lmin is now the shortest length
For i = 1 To lmin
res = res + Chr$(Asc(Mid$(dat, i, 1)) Xor Asc(Mid$(key, i, 1)) Xor Asc(Mid$(tim, i, 1)))
Next
MsgBox res
End Sub
The result is "4AG27B". I'm quite confident of the result.
I get the min length of all three strings, then in a loop I xor the ASC values of corresponding characters in same positions and add the Chr$() of the resultin value to the resulting string res$.
I'm confident, because I use a similar algorithm to xor strings for simple encoding.
Let me hint, that you are making a common error.
Code:
Dim lonLenKey As Long, lonKeyPos, lonLenTime, lonTmePos As Long
lonKeyPos and lonLenTime wont be long. You have to declare As Long for every variable individually. Without it, it becomaes a variant.
If lazy for writing, you can use the shortcuts
Dim a&, b&, c&, d$, i%
a, b, and c become Long, d becomes string and i% will be integer.
Also you don't need longs for this. Integer is sufficient.
Last edited by WoF; November 6th, 2009 at 12:22 PM.
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
|