Re: New IETF draft on "Messages between Email and Netnews"

New Message Reply About this list Date view Thread view Subject view Author view

From: Ian G Batten (I.G.Batten@batten.eu.org)
Date: Fri Sep 12 1997 - 02:44:53 CDT


-----BEGIN PGP SIGNED MESSAGE-----

In article <199709112157.OAA13260@onyx.OCE.ORST.EDU>,
John Stanley <stanley@oce.orst.edu> wrote:
> Excuse me, I thought you were talking about message id's, which are a
> tiny bit different than simple integers.

There's a one-to-one mapping. For non-null message id constructed from
a character set with n possible characters, there is a unique mapping to
the set of positive integers formed by considering the message-id as the
representation of an integer in base n. Every positive integer can be
converted to base n and read as a message-id, although some (I would
suggest most, but then I'm not an expert) will not be syntactically
valid.

I think from this the set of message ids is isomorphic to the set of
positive integers (as opposed to the `larger' infinity of the set of
reals, for example). The only reason our message ids are _not_ simply
represented as integers is because it would be wasteful of space if you
then in turn represented the integers as printable strings.

#!/usr/local/perl5/bin/perl

use strict;
use Math::BigInt;
use FileHandle;

my $radix = 128;

while (my $id = STDIN->getline ()) {
  chomp $id;
  if ($id =~ /^\+?\d+$/) {
    STDOUT->print (int_to_id (Math::BigInt->new ($id)), "\n");
  } else {
    STDOUT->print (id_to_int ($id), "\n");
  }
}

sub int_to_id {
  my ($int) = @_;
  my $id = '';
  
  while ($int) {
    my ($quot, $mod) = $int->bdiv ($radix);
    $id = chr ($mod) . $id;
    $int = $quot;
    # we want to use bdiv even if it isn't b
    $int = Math::BigInt->new ($int) unless ref ($int) eq 'Math::BigInt';
  }

  $id;
}

sub id_to_int {
  my ($id) = @_;
  my $int = Math::BigInt->new ("0");
  my (@chars) = split ('', $id);

  while (@chars) {
    $int *= $radix;
    $int += ord (shift (@chars));
  }
  $int;
}

-----BEGIN PGP SIGNATURE-----
Version: 2.6.3ia
Charset: noconv

iQB1AwUBNBjy2Moy0yij3IvtAQFASAL/WM6A8g+JlfhaplENujzvDT4eoTAKCVD6
owv2A53XYQah99xp3gEovGmc0TRMLiyxGUCiUAveBUfkWcznaFn6CZzr3ZtiJP8+
kUtR2s//W+fGB/hR+YXFoaBSqc4lTEgD
=5Zw/
-----END PGP SIGNATURE-----


New Message Reply About this list Date view Thread view Subject view Author view


This archive was generated by hypermail 2b29.