mIRC Home    About    Download    Register    News    Help

Print Thread
expert algorithmn help needed md5/hex/endian stuff #215727 03/10/09 01:20 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
I'm working on a challenge string reponse. See:

http://msnpiki.msnfanatic.com/index.php/MSNP11:Challenges

I'm on Step 1: The MD5 Hash according to that document

I just dont understand that hexa stuff that is in the doc, and the byte swapping. can someone help me out a bit?

Code:
alias chl return 22210219642164014968
alias prod_key return YMM8C_H7KCQ2S_KL
alias prod_id return PROD0090YUAUV{2B

alias step1 {
  echo -a $md5($chl $+ $prod_key)
  ; now the swapping hex stuff im not sure
}

Last edited by pouncer; 03/10/09 01:21 PM.
Re: expert algorithmn help needed md5/hex/endian stuff [Re: pouncer] #215757 04/10/09 05:59 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
anyone know what the little endian order stuff is, is this even possible in mirc?

Re: expert algorithmn help needed md5/hex/endian stuff [Re: pouncer] #215769 05/10/09 01:56 AM
Joined: Jul 2008
Posts: 236
S
s00p Offline
Fjord artisan
Offline
Fjord artisan
S
Joined: Jul 2008
Posts: 236
Take the 4x 32-bit integers that are encoded as a hexadecimal string, split them up.

So from the return value of md5("22210219642164014968YMM8C_H7KCQ2S_KL"); you get "ec4917aa5b3017159e3947f8ff981604"
and from this you get 4 integers: 0xec4917aa, 0x5b301715, 0x9e3947f8 and 0xff981604... Hexadecimal is just another way to encode numbers (binary, octal, decimal is the one we use, and hexadecimal). If you don't understand it, then read about it. If you don't understand big/little endian, then read about it.

If you don't know about $base, now's the time to learn. You can usually find these in the mIRC help file. Type /help $base.

edit: ok the mIRC help files aren't always helpful. $base is used to convert between number systems. $base(15,10,16) <-- convert the number 15 from base 10 (decimal) to base 16 (hexidecimal)... It can also pad with zeros: $base(F,16,10,32)

Splitting it up into 4 hexadecimal encoded integers:
Use $base to pad the MD5 out to 32 digits (the term "read mIRC help files" shall be shortened to read). Use $mid to split them up into 4 sections, 8 hexadecimal digits each (read).

If you've read, you'll have some idea how to convert your 4 x hex numbers into decimal. This is where the "little endian" stuff comes into play. If you don't know what "little endian" is, yet, then read (wikipedia should help here). You just so happen to be in luck, but please, read nonetheless. Reading is one of the activities one participates in to become less stupid. Use $and to binary AND them (don't listen to their "logical AND" bs - they meant binary AND).

Last edited by s00p; 05/10/09 02:08 AM.
Re: expert algorithmn help needed md5/hex/endian stuff [Re: s00p] #215782 05/10/09 06:25 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
Hi s00p, many thanks for the reply, really appreciate it. I'm just a bit confused with this stuff in the doc

Quote:

1: 0x2a1749ec = 706169324
2: 0x1517305b = 353841243
3: 0x7847399e = 2017933726
4: 0x041698ff = 68589823


I mean, I know how to use base in the above cases:
//echo -a $base(0x2a1749ec, 16, 10) = = 706169324

But not sure how we get from the original hex number 0xec4917aa to 0x2a1749ec - im guessing the byte swapping stuff has occured here? Ive tried to read on this little endian stuff and understand its just ordering of the bytes but cant see how it relates to this at all. any chance of further explanations? sorry if I missed anything

Re: expert algorithmn help needed md5/hex/endian stuff [Re: pouncer] #215783 05/10/09 06:41 PM
Joined: Sep 2005
Posts: 2,881
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Big to little endian just swaps the bytes around in pairs of twos...

Code:
alias blendian {
  var %i = 2, %result
  while ($mid($1,%i,2) != $null) {
    %result = $+($v1,%result)
    inc %i 2
  }
  return %result
}


$blendian(1234) = 3412

It's not an "expert algorithm" - 99% of your problems can be solved with simple string manipulation.

Re: expert algorithmn help needed md5/hex/endian stuff [Re: hixxy] #215784 05/10/09 08:52 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
Thanks for the reply hixxy but I still don't get it,

//echo -a $blendian(1234)

gives me 423

Re: expert algorithmn help needed md5/hex/endian stuff [Re: pouncer] #215785 05/10/09 10:19 PM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
change
Code:
var %i = 2
to
Code:
var %i = 1


Not sure why hixxy started at the 2nd character, or how hixxy got the proper results, as shown in their post, but that change should make the code work correctly.

Re: expert algorithmn help needed md5/hex/endian stuff [Re: RusselB] #215794 07/10/09 03:04 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
Hmm ok thanks. But according to that doc

//echo -a $blendian(0xec4917aa) = aa1749ec0x

In that doc its 1: 0x2a1749ec

Re: expert algorithmn help needed md5/hex/endian stuff [Re: pouncer] #215796 07/10/09 07:09 PM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
If you read that document more carefully you'll see this:
Quote:
Once you have stored them in the array, and have converted each of the elements to regular numbers (32 bit unsigned) you should logically AND them with 0x7FFFFFFF.

Here's how you could go about it:
Code:
alias blendian {
  bset &a 1 $replace($longip($base($1,16,10)),.,$chr(32))
  return $base($and($bvar(&a,1).long,$base(0x7fffffff,16,10)),10,16,8)
}

An alternative, slightly more compact, way is
Code:
alias blendian return $regsubex($1,/^(?:0x)?([a-f\d]{2})((?1))((?1))((?1))/,$base($and($base(\4,16,10),127),10,16,2) $+ \3\2\1)

Last edited by qwerty; 07/10/09 07:49 PM.

/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: expert algorithmn help needed md5/hex/endian stuff [Re: qwerty] #215809 08/10/09 09:53 AM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
Thanks very much for that qwerty.

//echo -a $blendian(0x2a1749ec)

It gives me 6C49172a - it doesn't match with the results in the doc

Quote:

1: 0x2a1749ec = 706169324
2: 0x1517305b = 353841243
3: 0x7847399e = 2017933726
4: 0x041698ff = 68589823

Re: expert algorithmn help needed md5/hex/endian stuff [Re: pouncer] #215810 08/10/09 10:18 AM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
The text you quoted simply shows the hex and decimal representations of 4 numbers - what's that got to do with $blendian(0x2a1749ec) returning 6C49172a?


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: expert algorithmn help needed md5/hex/endian stuff [Re: qwerty] #215812 08/10/09 05:21 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
ah oops i inputted the wrong hex

//echo -a $base($blendian(0xec4917aa), 16, 10) = 706169324

thats perfect!! thanks alot qwerty

also, i dont really need to put the 0x infront to make it a hex number right? thats only for languages like C and java??

Re: expert algorithmn help needed md5/hex/endian stuff [Re: pouncer] #215859 11/10/09 03:34 PM
Joined: Jul 2008
Posts: 236
S
s00p Offline
Fjord artisan
Offline
Fjord artisan
S
Joined: Jul 2008
Posts: 236
Quote:
thats only for languages like C and java??


Correct. It's a notation used by C and Java to represent a hex number.

Code:
int x = 0x10;

is the equivelant of
Code:
int x = 16;


There is no such type "int" in mIRC as there is in C or Java, because mIRC doesn't have types. It operates solely on strings, and numbers may be encoded in strings... base 10, base 16 or even base 223 if you choose so...

I already gave you the answer (to your most recent question/thread). If you had read about $mid, you wouldn't have had to ask about splitting the string into 4 parts. If you had read the documentation more clearly, you would have noticed that the parts you were confused about were merely examples. You might also have noticed that the $blendian function is, in this case, useless and unnecessary because mIRC uses an implementation that is in your favour. Please, in the future, read, read, read, and read some more until you can come to us with what you believe is a clear understanding of the topic and as a result, display a precise point of confusion that we may be able to correct.

Last edited by s00p; 11/10/09 03:34 PM.