views:

179

answers:

1

Hi, I'm trying to convert this piece of code from PHP to C#. It's part of a Captive Portal. Could somebody explain what it does?

  $hexchal = pack ("H32", $challenge);
  if ($uamsecret) {
    $newchal = pack ("H*", md5($hexchal . $uamsecret));
  } else {
    $newchal = $hexchal;
  }
  $response = md5("\0" . $password . $newchal);
  $newpwd = pack("a32", $password);
  $pappassword = implode ("", unpack("H32", ($newpwd ^ $newchal)));
+1  A: 

Eduardo,

if you take a look at the pack manual, pack is used to convert a string in (hex, octal, binary )to his number representation.

so

$hexcal = pack('H32', $challenge);

would convert a string like 'cca86bc64ec5889345c4c3d8dfc7ade9' to the actual 0xcca... de9

if $uamsecret exist do the same things with the MD5 of hexchal concacteate with the uamsecret. if ($uamsecret) { $newchal = pack ("H*", md5($hexchal . $uamsecret)); } else { $newchal = $hexchal; }

$response = md5("\0" . $password . $newchal);

MD% '\0' + $password + $newchal

$newpwd = pack("a32", $password);

pad password to 32 byte

  $pappassword = implode ("", unpack("H32", ($newpwd ^ $newchal)));

do a xor newpwd and newchal and convert it to a hexadecimal string, I don't get the implode() maybe it's to convert to string to an array of character.

RageZ
Thanks RageZ. Could you post an input / output example of those pack results?
Eduardo