help with code translation

Everything else that doesn't fall into one of the other PB categories.
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

help with code translation

Post by lexvictory »

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)

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;incorrect
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)
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

I was able to correct your four results for step 1. Your results were quite different than the webpage said they should be, and the reason was that you didn't convert the hex values to little endian before changing them to decimals. I rewrote your MyHex2Dec procedure to add this feature and the results from step 1 now equal what the website says they should be. The bad news is that step 3, even though it now has correct input from both previous steps, still isn't working. I have no more time tonight to work on it, so here's what I've done so far:

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 

ProcedureDLL.l MyHex2Dec(hex.s)
  ;convert to Little Endian
  tmp.s = ""
  For i=1 To 7 Step 2
    tmp=Mid(hex,i,2)+tmp
  Next
  hex=tmp
  result.l = 0
  multiplier = 1
  For i = Len(hex) To 1 Step -1
    Select UCase(Mid(hex, i, 1))
      Case "A":temp=10
      Case "B":temp=11
      Case "C":temp=12
      Case "D":temp=13
      Case "E":temp=14
      Case "F":temp=15
      Default : temp = Val(Mid(hex, i, 1))
    EndSelect
    result + temp * multiplier
    multiplier * 16
  Next
  ProcedureReturn result
EndProcedure

Structure firststephex 
first.l
second.l 
third.l
fourth.l 
EndStructure 

challengedata.s = "22210219642164014968" ;our test data 

;-first step 
Debug "Step 1" 

;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  ;706169324  = correct
Debug firststep\second ;353841243  = correct
Debug firststep\third  ;2017933726 = correct
Debug firststep\fourth ;68589823   = correct

;- 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 ""
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(9) 
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 ""
Debug "Step 3" 

high.l = 0 
low.l = 0 

For i = 0 To 9 Step 2 
  temp = step2pieces(i) 
  temp = ($0E79A9C1 * temp) % $7FFFFFFF 

  temp = 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;incorrect
BERESHEIT
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

netmaestro wrote:I was able to correct your four results for step 1. Your results were quite different than the webpage said they should be, and the reason was that you didn't convert the hex values to little endian before changing them to decimals. I rewrote your MyHex2Dec procedure to add this feature and the results from step 1 now equal what the website says they should be.
eek, i swear they were working for me before.... :oops:

thank u 4 wat u did tho.... i suck at this kinda stuff sometimes
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

I figured you probably assumed that because step 2's results were perfect, that step 1's should be right. But 2 didn't depend on 1 at all, which serves to confuse things a bit. If you don't have it solved tomorrow, I'll have a go at step 3. Good luck!
BERESHEIT
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

netmaestro wrote:I figured you probably assumed that because step 2's results were perfect, that step 1's should be right. But 2 didn't depend on 1 at all, which serves to confuse things a bit. If you don't have it solved tomorrow, I'll have a go at step 3. Good luck!
no, i knew they didnt affect each other, but i swear they were right.... thats why i went on to step 2....

but it doesnt surprise me that i stuffed that up, considering i had to fix a stupid error in the actual msn program that was just that i wasnt clearing a variable when it needed to be.... :oops:


and i dont think i'll have much luck... :lol:
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
Post Reply