]>
jfr.im git - snippets.git/blob - snippets.php
2 function num2code($num, $dict) {
3 // Source: perl Acme::Tools
4 // License: GNU GPL v1+; Artistic License
5 if (!is_array($dict)) {
6 $dict = str_split($dict);
11 $buf[] = $dict[$num %
$base];
12 $num = (int)($num/$base);
15 return implode(array_reverse($buf));
18 function code2num($str, $dict) {
19 // Source: perl Acme::Tools
20 // License: GNU GPL v1+; Artistic License
21 if (is_array($dict)) {
22 $dict = implode($dict);
24 $base = strlen($dict);
26 foreach (str_split($str) as $c) {
27 $buf = $buf*$base +
strpos($dict, $c);
32 // vim: ts=4 nosmarttab noexpandtab