I'm trying to convert this:
function _password_itoa64() {
return './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
}
function _password_base64_encode($input, $count) {
$output = '';
$i = 0;
$itoa64 = _password_itoa64();
do {
$value = ord($input[$i++]);
$output .= $itoa64[$value & 0x3f];
if ($i < $count) {
$value |= ord($input[$i]) << 8;
}
$output .= $itoa64[($value >> 6) & 0x3f];
if ($i++ >= $count) {
break;
}
if ($i < $count) {
$value |= ord($input[$i]) << 16;
}
$output .= $itoa64[($value >> 12) & 0x3f];
if ($i++ >= $count) {
break;
}
$output .= $itoa64[($value >> 18) & 0x3f];
} while ($i < $count);
return $output;
}
php code into Java and currently have this:
private static String _password_itoa64(){
return "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
}
private String _password_base64_encode(byte[] hash, int count){
StringBuffer output = new StringBuffer();
String input = new String(hash);
String itoa64 = _password_itoa64();
int i = 0, value;
do {
value = input.charAt(i++);
output.append(itoa64.charAt(value & 0x3f));
if (i < count) {
value |= (int)(input.charAt(i) << (char)8);
}
output.append(itoa64.charAt((value >> 6) & 0x3f));
if (i++ >= count) {
break;
}
if (i < count) {
value |= (int)(input.charAt(i) << (char)16);
}
output.append(itoa64.charAt((value >> 12) & 0x3f));
if (i++ >= count) {
break;
}
output.append(itoa64.charAt((value >> 18) & 0x3f));
}
while (i < count);
return output.toString();
}
When supplied with the same thing this happened:
php - 6gL/BBSRbbJS7V.avvpcInZvukU4scZRsdWGwlPCG7R
java - 6gL/BBSRbbJS7V.rvvpcInZvukU4scZRsdWGwlPCG7R
input string - as hex its this 087b054de375e75979490898fb5ea3d45cee3a0c1a385a76782a4a7cbc3952d21d8b9523175d95d21c5eddb3efebb88733d8cb9de121b11683a41175429e1170
Any clues as to what caused the random non conforming character?
EDIT:
Tracing down where it went wrong goes to value |= (int)(input.charAt(i) << (char)16); in PHP this line sets value to be 9963593 with ord($input[$i]) is 152 and in Java it sets it to be 47974473 when input.charAt(i) is 732
Guess this means I havnt chosen the right way of converting ord($input[$i]) into Java