help with code translation
Posted: Mon Nov 27, 2006 6:29 am
				
				i'm currently trying to get msnp11 challenges working, not actually in a program, but just getting it to work so that i can then go ahead and change my program from msnp8 to msnp11....
there are four steps to the process, and i have been able to get the first two to work, but i cannot manage to get the third working...
the page explaining the process is at http://msnpiki.msnfanatic.com/index.php ... Challenges
currently the code i have is this: (firststep\first = md5hash[0] is the pseudo code)
my problem is that high and low are not correct at the end of the loop, and so key ends up incorrect too
have i made an error in the conversion?
(this has taken a lot of today to get working even this far)
			there are four steps to the process, and i have been able to get the first two to work, but i cannot manage to get the third working...
the page explaining the process is at http://msnpiki.msnfanatic.com/index.php ... Challenges
currently the code i have is this: (firststep\first = md5hash[0] is the pseudo code)
Code: Select all
Procedure.s MD5StringHash(tohash.s)
*buffer = AllocateMemory(Len(tohash)+2)
PokeS(*buffer, tohash, -1, #PB_Ascii)
md5hash.s = MD5Fingerprint(*buffer, Len(tohash))
FreeMemory(*buffer)
ProcedureReturn md5hash
EndProcedure
Structure onebyte; For myhex2dec
a.b
EndStructure
ProcedureDLL.l myHex2Dec(HexNumber.s) ;copied from droopys lib and modified to work in unicode mode
  utf8.s = Space(Len(hexnumber))
  PokeS(@utf8, hexnumber, -1, #PB_UTF8)
  *t.OneByte = @utf8
  Result.l = 0 
  While *t\a <> 0 
    If *t\a >= '0' And *t\a <= '9' 
      Result = (Result << 4) + (*t\a - 48) 
    ElseIf *t\a >= 'A' And *t\a <= 'F' 
      Result = (Result << 4) + (*t\a - 55) 
    ElseIf *t\a >= 'a' And *t\a <= 'f' 
      Result = (Result << 4) + (*t\a - 87) 
    Else 
      Result = (Result << 4) + (*t\a - 55) 
    EndIf 
    *t + 1 
  Wend 
  ProcedureReturn Result 
EndProcedure 
Structure firststephex
first.l
second.l
third.l
fourth.l
EndStructure
challengedata.s = "22210219642164014968" ;our test data
;-first step
Debug "first step"
;hash the data
firstmd5hash.s = md5stringhash(challengedata+"YMM8C_H7KCQ2S_KL")
;put into the 'array'
firststep.firststephex
firststep\first = myhex2dec(Left(firstmd5hash, 8))
firststep\second = myhex2dec(Mid(firstmd5hash, 9, 8))
firststep\third = myhex2dec(Mid(firstmd5hash, 17, 8))
firststep\fourth = myhex2dec(Right(firstmd5hash, 8))
;and with $7FFFFFFF - it says it needs to be done, but it doesnt seem to make much difference....
 firststep\first = firststep\first & $7FFFFFFF
 firststep\second = firststep\second & $7FFFFFFF
 firststep\third = firststep\third & $7FFFFFFF
 firststep\fourth = firststep\fourth & $7FFFFFFF
;Debug firststep\first
;Debug firststep\second
;Debug firststep\third
;Debug firststep\fourth
;- second step
Structure secondstep
  p1.l
  p2.l
  p3.l
  p4.l
  p5.l
  p6.l
  p7.l
  p8.l
  p9.l
  p10.l
EndStructure
Debug "step 2"
;make this string's length a multiple of 8 by appending "0"'s to the end
step2chl.s = challengedata+"PROD0090YUAUV{2B"
amounttoadd = (8 - (Len(step2chl) % 8)) + Len(step2chl)
step2chl = LSet(step2chl, amounttoadd, "0")
step2chlutf.s = Space(Len(step2chl)+2);for utf8/ascii version of the string
PokeS(@step2chlutf, step2chl, -1, #PB_UTF8)
;Debug step2chlutf
*secondstep.secondstep = @step2chlutf;to split the string into the 4 byte 'array'
;for step 3 - put them in an actual array
Dim step2pieces.l(10)
step2pieces(0) = *secondstep\p1
step2pieces(1) = *secondstep\p2
step2pieces(2) = *secondstep\p3
step2pieces(3) = *secondstep\p4
step2pieces(4) = *secondstep\p5
step2pieces(5) = *secondstep\p6
step2pieces(6) = *secondstep\p7
step2pieces(7) = *secondstep\p8
step2pieces(8) = *secondstep\p9
step2pieces(9) = *secondstep\p10
For x = 0 To 9
  Debug step2pieces(x);all correct
Next
;-step 3
Debug "Step 3"
high.l = 0
low.l = 0
For i = 0 To 9 Step 2
  temp = step2pieces(i)
  temp = ($0E79A9C1 * temp) % $7FFFFFFF
  temp + high
  temp = firststep\first * temp + firststep\second
  temp = temp % $7FFFFFFF
  high = step2pieces(i + 1)
  high = (high + temp) % $7FFFFFFF
  high = firststep\third * high + firststep\fourth
  high = high % $7FFFFFFF
  low = low + high + temp
Next i
high = (high + firststep\second) % $7FFFFFFF
low = (low + firststep\fourth) % $7FFFFFFF
;// Gives high = 0x69A5A771 (1772463985 decimal) And low = 0xD4020628 (3556902440 decimal)
Debug high;neither equal what it says in the above line
Debug low 
key.q = (high << 32) + low
;// Gives 0x69a5a771d4020628 (7612674852469737000 decimal)
Debug key;incorrecthave i made an error in the conversion?
(this has taken a lot of today to get working even this far)
 
 