["Followup-To:" header set to comp.lang.php.]
Krakatioison wrote:
So I played with your idea a bit and wrote this script:
<?
$str= '10000000000409 00000';
echo "Original string:".$str." <br>";
$encoded = base_convert($s tr, 10, 36); //
echo "Encoded string:".$encod ed."<br>";
$decoded = base_convert($e ncoded, 36, 10);
echo "Decoded string:".$decod ed."<br>";
?>
Are your numbers 'n' always 18 digits long?
php$ cat longn.php
<?php
function test($str) {
if (strlen($str) != 18) {echo "$str: Oops, wrong length\n\n"; return;}
$str1 = substr($str, 0, 9);
$str2 = substr($str, 9, 9);
echo 'Original string: ', $str, ' ==> ';
$encoded = base_convert($s tr1, 10, 36);
$encoded .= '-' . base_convert($s tr2, 10, 36);
echo 'Encoded string: ', $encoded, "\n";
$enc = explode('-', $encoded);
$decoded = substr('0000000 0' . base_convert($e nc[0], 36, 10), -9);
$decoded .= substr('0000000 0' . base_convert($e nc[1], 36, 10), -9);
echo ' Decoded string: ', $decoded, "\n\n";
}
/* test data */
$str= '00000000004090 0000'; test($str);
$str= '00000000004090 0001'; test($str);
$str= '90000000004090 0000'; test($str);
$str= '90000000004090 0001'; test($str);
$str= '12345678901234 5678'; test($str);
$str= '98765432109876 5432'; test($str);
$str= '11111111111111 1111'; test($str);
$str= '55555555555555 5555'; test($str);
$str= '99999999999999 9999'; test($str);
$str= '00000000000000 0000'; test($str);
?>
php$ php longn.php
Original string: 000000000040900 000 ==> Encoded string: 0-ocmn4
Decoded string: 000000000040900 000
Original string: 000000000040900 001 ==> Encoded string: 0-ocmn5
Decoded string: 000000000040900 001
Original string: 900000000040900 000 ==> Encoded string: evu4g0-ocmn4
Decoded string: 900000000040900 000
Original string: 900000000040900 001 ==> Encoded string: evu4g0-ocmn5
Decoded string: 900000000040900 001
Original string: 123456789012345 678 ==> Encoded string: 21i3v9-7clzi
Decoded string: 123456789012345 678
Original string: 987654321098765 432 ==> Encoded string: gc0uy9-1msvw8
Decoded string: 987654321098765 432
Original string: 111111111111111 111 ==> Encoded string: 1u5hvr-1u5hvr
Decoded string: 111111111111111 111
Original string: 555555555555555 555 ==> Encoded string: 96rher-96rher
Decoded string: 555555555555555 555
Original string: 999999999999999 999 ==> Encoded string: gjdgxr-gjdgxr
Decoded string: 999999999999999 999
Original string: 000000000000000 000 ==> Encoded string: 0-0
Decoded string: 000000000000000 000
--
USENET would be a better place if everybody read: | to mail me: simply |
http://www.catb.org/~esr/faqs/smart-questions.html | "reply" to this post, |
http://www.netmeister.org/news/learn2quote2.html | *NO* MIME, plain text |
http://www.expita.com/nomime.html | and *NO* attachments. |