I have this code here in Java that I wish to convert to PHP. It is possibly related to converting from ascii to binary, then to hex, but I am not quite sure myself. Could anybody help please?
String clearKey = "test";
char [] hexArray = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
byte [] bytes = clearKey.getBytes();
String keyId = "";
for (int i = 0 ; i < clearKey.length() ; i ++) {
keyId = keyId + hexArray[(bytes[i] & 0xFF) / 16] + hexArray[(bytes[i] & 0xFF) % 16];
}
System.out.println(keyId);
Here is what I got so far:
The second line of the code can probably be converted into this:
$bytes = bin2hex($clearKey);
But I don't know what the equivalent of following code in php:
hexArray[(bytes[i] & 0xFF) / 16] + hexArray[(bytes[i] & 0xFF) % 16];
Additional Information
I converted this code into correct Java syntax.
bytes, the author probably meantbyte. However, the array notation and thegetBytes()immediately made me think of Java.