We’ve to implement an encryption for an external interface. The owner of the interface has given documentation of how to preform the same encryption on our side. However, this documentation is in C# and we work in PHP.
Most of the parts we understand except for where they seem to typecast a hash to an int. Their code reads:
// hashString exists and is a md5 a like string
int[] keyBuffer = new int[hashString.length];
for (int i=0; i<hashString.length; i++) {
keyBuffer[i] = (int)hashString[i];
}
In PHP, when casting a letter as int, you get 0 (int). As we can’t imagine this is what the third party means, we believe C# does something else.
Does C# also cast to int 0, or possibly to a char?
Second, the original hashString is 320 long. This means the code will be creating an int which is 320 long?? In PHP you don’t have this idea of reserving memory as C# does here. But when we try to typecast a 320 long string to an int we get an int which is 19 ‘chars’ long.
Does C# also create a shorter int when typecasting a really long ‘number’ in a string?
You’re converting a
chartoint. Acharis a UTF-16 code unit – an unsigned 16-bit integer (the range is[0, 65535]). You get that value, basically, widened to a 32-bit signed integer. So'A'ends up as 65, for example, and the Euro symbol (U+20AC) ends up as 8364 (0x20ac).As for your second part – you’re creating an
int, you’re creating anintarray. An yes, you’ll be creating an array with 320 elements.