I have a PHPscript that I manually converted to C#. Output variable hexSaltand hexFullshould print the same, but the output variable datais different. I found that the problem remains in converting the variable intto char. How can they be different?
I tried to C#convert them and make them in several ways, such as:
Char.ConvertFromUtf32(int), Convert.ToChar(int), (char)int
but they show the same incomplete conclusion C#.
WITH#
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 />");
Response.Write(hexFull + "<br />");
Response.Write(data);
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 />";
echo $hexFull . "<br />";
echo $data;
Additional Information:
- I am testing it in the same browser
- I run both codes on the same server.
- I can not edit PHP code
- I can not change the salt
source
share