I need to generate a "random" 128 byte key (Strength of randomness is not important at the moment). I do this in Javascript with the following code:
var buffer = "";
for(var i=0; i<128; i++)
{
buffer += String.fromCharCode(Math.round(Math.random()*255));
}
However, when I send this key to a PHP script via POST, I find that certain characters in my key do not have the same encoding! For example when I output the encoding of ò in Javascript I get 254, yet the same character has an encoding of 195 in PHP.
Certain characters, such as A-Z, a-z, and 0-9 have the same encoding in both Javascript and PHP.
To output character codes, I use Javascript's .charCodeAt() method and PHP's ord() function.
I was hoping someone could explain to me why the character encodings differ. Thank you!