mIRC Home    About    Download    Register    News    Help

Print Thread
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.
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?

Joined: Jul 2008
Posts: 236
S
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.
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

Joined: Sep 2005
Posts: 2,881
H
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.

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

Joined: Aug 2004
Posts: 7,252
R
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.

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

Joined: Jan 2003
Posts: 2,523
Q
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
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

Joined: Jan 2003
Posts: 2,523
Q
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
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??

Joined: Jul 2008
Posts: 236
S
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.

Link Copied to Clipboard