I've got a PHP script which I have manually converted to C#. The output of the hexSalt and the hexFull variable do print the same but the ouput of variable data is different. I have discovered that the problem persists in converting the int variable to char. How can these be different?
I have tried in C# to convert them and to cast them in multiple ways like:
Char.ConvertFromUtf32(int), Convert.ToChar(int), (char)int
but those are displaying the same incomplete C# output.
C#
string data = "";
string saltFull = "";
string hexFull = "";
char[] saltChars = salt.ToCharArray();
for (int i = 0; i < (salt.Length / 2); i++)
{
string hexSalt = saltChars[i * 2].ToString() + saltChars[(i * 2) + 1].ToString();
saltFull += hexSalt;
int hex = int.Parse(hexSalt, NumberStyles.HexNumber);
hexFull += hex.ToString();
char chr = (char)hex;
data += chr;
}
Response.Write(saltFull + "<br />"); // Same output
Response.Write(hexFull + "<br />"); // Same output
Response.Write(data); // Almost the same output...
// Output of variable data, the converted int to char.
// ¸:}P/C{_ëóCZÔfPüY£Y,Ö]·î~9ªuJb®éI[p¢?0ZÖµz²ð4
PHP
$data = "";
$saltFull = "";
$hexFull = "";
for ($i = 0; $i < strlen($salt) / 2; $i++) {
$hexSalt = $salt[$i * 2] . $salt[($i * 2) + 1];
$saltFull .= $hexSalt;
$hex = hexdec($hexSalt);
$hexFull .= $hex;
$chr = chr($hex);
$data .= $chr;
}
echo $saltFull . "<br />"; // Same output
echo $hexFull . "<br />"; // Same output
echo $data; // Almost the same output...
// Output of variable data, the converted int to char.
// ¸ˆ:}Pž/CŽ”“{_ëóCZ‹ÔfP€üY£Y,Ö]·î~9ªuJb®éI[p¢?0ZÖµz²ð…4
Additional information:
- I am testing it in the same browser
- I am running both codes on the same server.
- I cannot edit the PHP code
- I cannot change the salt
echoandResponse.Write().