function biToHex($x) { return biToString($x, 16); }
function biEncryptedString($key, $s) { // Altered by Rob Saunders (rob@robsaunders.net). New routine pads the // string after it has been converted to an array. This fixes an // incompatibility with Flash MX's ActionScript. $a = array(); $sl = strlen($s); $i = 0; while ($i < $sl) { $a[$i] = ord(substr($s, $i, 1)); $i++; } while (count($a) % $key->chunkSize != 0) { $a[$i++] = 0; } $al = count($a); $result = ""; $j; $k; $block; for ($i = 0; $i < $al; $i += $key->chunkSize) { $block = new BigInt(); $j = 0; for ($k = $i; $k < $i + $key->chunkSize; ++$j) { $block->digits[$j] = $a[$k++]; //$block->digits[$j] += $a[$k++] << 8; } $crypt = $key->barrett->powMod($block, $key->e); $text = biToString($crypt, $key->radix); $result .= $text . " "; } return substr($result, 0, strlen($result) - 1); // Remove last space. }