r68676 - in /branches/upstream/libmath-base85-perl: ./ current/ current/Base85.pm current/Changes current/MANIFEST current/Makefile.PL current/README current/rfc1924.txt current/test.pl

takaki at users.alioth.debian.org takaki at users.alioth.debian.org
Tue Feb 15 04:51:08 UTC 2011


Author: takaki
Date: Tue Feb 15 04:51:02 2011
New Revision: 68676

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=68676
Log:
[svn-inject] Installing original source of libmath-base85-perl (0.2)

Added:
    branches/upstream/libmath-base85-perl/
    branches/upstream/libmath-base85-perl/current/
    branches/upstream/libmath-base85-perl/current/Base85.pm
    branches/upstream/libmath-base85-perl/current/Changes
    branches/upstream/libmath-base85-perl/current/MANIFEST
    branches/upstream/libmath-base85-perl/current/Makefile.PL
    branches/upstream/libmath-base85-perl/current/README
    branches/upstream/libmath-base85-perl/current/rfc1924.txt
    branches/upstream/libmath-base85-perl/current/test.pl

Added: branches/upstream/libmath-base85-perl/current/Base85.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmath-base85-perl/current/Base85.pm?rev=68676&op=file
==============================================================================
--- branches/upstream/libmath-base85-perl/current/Base85.pm (added)
+++ branches/upstream/libmath-base85-perl/current/Base85.pm Tue Feb 15 04:51:02 2011
@@ -1,0 +1,136 @@
+package Math::Base85;
+
+use strict;
+use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $base85_digits);
+
+use Carp;
+use Exporter;
+use Math::BigInt qw(:constant);
+
+$VERSION = '0.2';
+
+ at ISA = qw(Math::BigInt);
+ at EXPORT = qw();
+ at EXPORT_OK = qw(from_base85 to_base85);
+
+=head1 NAME
+
+Math::Base85 - Perl extension for base 85 numbers, as referenced by RFC 1924
+
+=head1 SYNOPSIS
+
+  use Math::Base85;
+
+  $bigint = from_base85($number);
+  $b85str = to_base85($bigint);
+
+=head1 DESCRIPTION
+
+RFC 1924 describes a compact, fixed-size representation of IPv6
+addresses which uses a base 85 number system.  This module handles
+some of the uglier details of it.
+
+The base 85 numbers (from 0 to 84) are as follows:
+
+    0..9 A..Z a..z ! # $ % & ( ) * + - ; < = > ? @ ^ _ ` { | } ~
+
+At the moment, there's not much in this module.  But it should be
+sufficient for the purposes of RFC 1924.
+
+This module has a variable called C<$Math::Base85::base85_digits>,
+which is a string containing the digits of the base 85 alphabet
+from lowest (0) to highest (~), in that order.
+
+Additionally, the following two functions are defined for general
+use.  (They will be exported upon request.)
+
+=cut
+
+$Math::Base85::base85_digits = join('', 
+    '0' .. '9', 
+    'A' .. 'Z', 
+    'a' .. 'z', 
+    '!', '#', qw/$ % & ( ) * + - ; < = > ? @ ^ _ ` { | } ~/,
+);
+
+
+# Maybe we can make this a little more general...
+
+use constant B85_BASE => 85;
+
+=pod
+
+=head1 from_base85
+
+=head2 Parameters
+
+A string composed of valid base 85 digits.
+
+=head2 Returns
+
+A C<Math::BigInt> object representing the number.
+
+=cut
+
+sub from_base85
+{
+    my $num = shift;
+    my @digits = split(//, $num);
+    my $answer = new Math::BigInt "0";
+    my $n;
+    my $d;
+    while (defined($d = shift @digits)) {
+	$answer = $answer * B85_BASE;
+	$n = index($base85_digits, $d);
+	if ($n < 0) {
+	    croak __PACKAGE__ . "::from_base85 -- invalid base 85 digit $d";
+	}
+	$answer = $answer + $n;
+    }
+    return $answer;
+}
+
+=pod
+
+=head1 to_base85
+
+=head2 Parameters
+
+A C<Math::BigInt> object.
+
+=head2 Returns
+
+A string of base 85 digits representing the number.
+
+=cut
+
+sub to_base85
+{
+    my $num = shift;
+    my @digits;
+    my $q;
+    my $r;
+    my $d;
+    while ($num > 0) {
+	$q = $num / B85_BASE;
+	$r = $num % B85_BASE;
+	$d = substr($base85_digits, $r, 1);
+	unshift @digits, $d;
+	$num = $q;
+    }
+    unshift @digits, '0' unless (@digits);
+    return join('', @digits);
+}
+
+=head1 AUTHOR
+
+Tony Monroe <tmonroe+perl at nog.net>
+
+=head1 SEE ALSO
+
+perl(1).
+
+=cut
+
+1;
+__END__

Added: branches/upstream/libmath-base85-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmath-base85-perl/current/Changes?rev=68676&op=file
==============================================================================
--- branches/upstream/libmath-base85-perl/current/Changes (added)
+++ branches/upstream/libmath-base85-perl/current/Changes Tue Feb 15 04:51:02 2011
@@ -1,0 +1,9 @@
+Revision history for Perl extension Math::Base85.
+
+0.2     Fri May 03 09:11:41 PDT 2002
+	- Initial zeroes fix from Jyrki Soini <jyrki dot soini at 
+	  sonera dot com>.
+
+0.1 	Fri Jul 20 17:11:22 PDT 2001
+	- to_base85 and from_base85 work, and can be exported.
+	- $Math::Base85::base85_digits made available to other modules.

Added: branches/upstream/libmath-base85-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmath-base85-perl/current/MANIFEST?rev=68676&op=file
==============================================================================
--- branches/upstream/libmath-base85-perl/current/MANIFEST (added)
+++ branches/upstream/libmath-base85-perl/current/MANIFEST Tue Feb 15 04:51:02 2011
@@ -1,0 +1,7 @@
+Base85.pm
+Changes
+MANIFEST
+Makefile.PL
+test.pl
+README
+rfc1924.txt

Added: branches/upstream/libmath-base85-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmath-base85-perl/current/Makefile.PL?rev=68676&op=file
==============================================================================
--- branches/upstream/libmath-base85-perl/current/Makefile.PL (added)
+++ branches/upstream/libmath-base85-perl/current/Makefile.PL Tue Feb 15 04:51:02 2011
@@ -1,0 +1,7 @@
+use ExtUtils::MakeMaker;
+# See lib/ExtUtils/MakeMaker.pm for details of how to influence
+# the contents of the Makefile that is written.
+WriteMakefile(
+    'NAME'	=> 'Math::Base85',
+    'VERSION_FROM' => 'Base85.pm', # finds $VERSION
+);

Added: branches/upstream/libmath-base85-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmath-base85-perl/current/README?rev=68676&op=file
==============================================================================
--- branches/upstream/libmath-base85-perl/current/README (added)
+++ branches/upstream/libmath-base85-perl/current/README Tue Feb 15 04:51:02 2011
@@ -1,0 +1,27 @@
+========================
+Math::Base85 Version 0.2
+========================
+
+This module handles numbers in base 85, via strings and Math::BigInt.
+For more information, read the module or rfc1924.txt.
+
+The usual installation instructions apply:
+
+	/path/to/perl Makefile.PL
+	make
+	make test
+	make install
+
+Please report bugs to the author at <tmonroe plus perl at nog dot net>.
+
+---------------------
+Copyright and License
+---------------------
+
+This distribution (with the exception of any included RFC's) is
+copyright (c) 2001-2002 Tony Monroe.  All rights reserved.  This
+software is distributed under the same license terms as Perl itself.
+This software comes with NO WARRANTIES WHATSOEVER, express, implied,
+or otherwise.
+
+$Id: README,v 1.3 2002/08/06 21:31:52 tony Exp $

Added: branches/upstream/libmath-base85-perl/current/rfc1924.txt
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmath-base85-perl/current/rfc1924.txt?rev=68676&op=file
==============================================================================
--- branches/upstream/libmath-base85-perl/current/rfc1924.txt (added)
+++ branches/upstream/libmath-base85-perl/current/rfc1924.txt Tue Feb 15 04:51:02 2011
@@ -1,0 +1,339 @@
+
+
+
+
+
+
+Network Working Group                                             R. Elz
+Request for Comments: 1924                       University of Melbourne
+Category: Informational                                     1 April 1996
+
+
+               A Compact Representation of IPv6 Addresses
+
+Status of this Memo
+
+   This memo provides information for the Internet community.  This memo
+   does not specify an Internet standard of any kind.  Distribution of
+   this memo is unlimited.
+
+1. Abstract
+
+   IPv6 addresses, being 128 bits long, need 32 characters to write in
+   the general case, if standard hex representation, is used, plus more
+   for any punctuation inserted (typically about another 7 characters,
+   or 39 characters total).  This document specifies a more compact
+   representation of IPv6 addresses, which permits encoding in a mere 20
+   bytes.
+
+2. Introduction
+
+   It is always necessary to be able to write in characters the form of
+   an address, though in actual use it is always carried in binary.  For
+   IP version 4 (IP Classic) the well known dotted quad format is used.
+   That is, 10.1.0.23 is one such address.  Each decimal integer
+   represents a one octet of the 4 octet address, and consequently has a
+   value between 0 and 255 (inclusive).  The written length of the
+   address varies between 7 and 15 bytes.
+
+   For IPv6 however, addresses are 16 octets long [IPv6], if the old
+   standard form were to be used, addresses would be anywhere between 31
+   and 63 bytes, which is, of course, untenable.
+
+   Because of that, IPv6 had chosen to represent addresses using hex
+   digits, and use only half as many punctuation characters, which will
+   mean addresses of between 15 and 39 bytes, which is still quite long.
+   Further, in an attempt to save more bytes, a special format was
+   invented, in which a single run of zero octets can be dropped, the
+   two adjacent punctuation characters indicate this has happened, the
+   number of missing zeroes can be deduced from the fixed size of the
+   address.
+
+   In most cases, using genuine IPv6 addresses, one may expect the
+   address as written to tend toward the upper limit of 39 octets, as
+   long strings of zeroes are likely to be rare, and most of the other
+
+
+
+Elz                          Informational                      [Page 1]
+
+RFC 1924       A Compact Representation of IPv6 Addresses   1 April 1996
+
+
+   groups of 4 hex digits are likely to be longer than a single non-zero
+   digit (just as MAC addresses typically have digits spread throughout
+   their length).
+
+   This document specifies a new encoding, which can always represent
+   any IPv6 address in 20 octets.  While longer than the shortest
+   possible representation of an IPv6 address, this is barely longer
+   than half the longest representation, and will typically be shorter
+   than the representation of most IPv6 addresses.
+
+3. Current formats
+
+   [AddrSpec] specifies that the preferred text representation of IPv6
+   addresses is in one of three conventional forms.
+
+   The preferred form is x:x:x:x:x:x:x:x, where the 'x's are the
+   hexadecimal values of the eight 16-bit pieces of the address.
+
+   Examples:
+
+        FEDC:BA98:7654:3210:FEDC:BA98:7654:3210  (39 characters)
+
+        1080:0:0:0:8:800:200C:417A  (25 characters)
+
+   The second, or zero suppressed, form allows "::" to indicate multiple
+   groups of suppressed zeroes, hence:
+
+        1080:0:0:0:8:800:200C:417A
+
+   may be represented as
+
+        1080::8:800:200C:417A
+
+   a saving of just 5 characters from this typical address form, and
+   still leaving 21 characters.
+
+   In other cases the saving is more dramatic, in the extreme case, the
+   address:
+
+        0:0:0:0:0:0:0:0
+
+   that is, the unspecified address, can be written as
+
+        ::
+
+   This is just 2 characters, which is a considerable saving.  However
+   such cases will rarely be encountered.
+
+
+
+
+Elz                          Informational                      [Page 2]
+
+RFC 1924       A Compact Representation of IPv6 Addresses   1 April 1996
+
+
+   The third possible form mixes the new IPv6 form with the old IPv4
+   form, and is intended mostly for transition, when IPv4 addresses are
+   embedded into IPv6 addresses.  These can be considerably longer than
+   the longest normal IPv6 representation, and will eventually be phased
+   out.  Consequently they will not be considered further here.
+
+4. The New Encoding Format
+
+   The new standard way of writing IPv6 addresses is to treat them as a
+   128 bit integer, encode that in base 85 notation, then encode that
+   using 85 ASCII characters.
+
+4.1. Why 85?
+
+   2^128 is 340282366920938463463374607431768211456.  85^20 is
+   387595310845143558731231784820556640625, and thus in 20 digits of
+   base 85 representation all possible 2^128 IPv6 addresses can clearly
+   be encoded.
+
+   84^20 is 305904398238499908683087849324518834176, clearly not
+   sufficient, 21 characters would be needed to encode using base 84,
+   this wastage of notational space cannot be tolerated.
+
+   On the other hand, 94^19 is just
+   30862366077815087592879016454695419904, also insufficient to encode
+   all 2^128 different IPv6 addresses, so 20 characters would be needed
+   even with base 94 encoding.  As there are just 94 ASCII characters
+   (excluding control characters, space, and del) base 94 is the largest
+   reasonable value that can be used.  Even if space were allowed, base
+   95 would still require 20 characters.
+
+   Thus, any value between 85 and 94 inclusive could reasonably be
+   chosen.  Selecting 85 allows the use of the smallest possible subset
+   of the ASCII characters, enabling more characters to be retained for
+   other uses, eg, to delimit the address.
+
+4.2. The Character Set
+
+   The character set to encode the 85 base85 digits, is defined to be,
+   in ascending order:
+
+             '0'..'9', 'A'..'Z', 'a'..'z', '!', '#', '$', '%', '&', '(',
+             ')', '*', '+', '-', ';', '<', '=', '>', '?', '@', '^', '_',
+             '`', '{', '|', '}', and '~'.
+
+   This set has been chosen with considerable care.  From the 94
+   printable ASCII characters, the following nine were omitted:
+
+
+
+
+Elz                          Informational                      [Page 3]
+
+RFC 1924       A Compact Representation of IPv6 Addresses   1 April 1996
+
+
+      '"' and "'", which allow the representation of IPv6 addresses to
+      be quoted in other environments where some of the characters in
+      the chosen character set may, unquoted, have other meanings.
+
+      ',' to allow lists of IPv6 addresses to conveniently be written,
+      and '.' to allow an IPv6 address to end a sentence without
+      requiring it to be quoted.
+
+      '/' so IPv6 addresses can be written in standard CIDR
+      address/length notation, and ':' because that causes problems when
+      used in mail headers and URLs.
+
+      '[' and ']', so those can be used to delimit IPv6 addresses when
+      represented as text strings, as they often are for IPv4,
+
+      And last, '\', because it is often difficult to represent in a way
+      where it does not appear to be a quote character, including in the
+      source of this document.
+
+5. Converting an IPv6 address to base 85.
+
+   The conversion process is a simple one of division, taking the
+   remainders at each step, and dividing the quotient again, then
+   reading up the page, as is done for any other base conversion.
+
+   For example, consider the address shown above
+
+        1080:0:0:0:8:800:200C:417A
+
+   In decimal, considered as a 128 bit number, that is
+   21932261930451111902915077091070067066.
+
+   As we divide that successively by 85 the following remainders emerge:
+   51, 34, 65, 57, 58, 0, 75, 53, 37, 4, 19, 61, 31, 63, 12, 66, 46, 70,
+   68, 4.
+
+   Thus in base85 the address is:
+
+        4-68-70-46-66-12-63-31-61-19-4-37-53-75-0-58-57-65-34-51.
+
+   Then, when encoded as specified above, this becomes:
+
+        4)+k&C#VzJ4br>0wv%Yp
+
+   This procedure is trivially reversed to produce the binary form of
+   the address from textually encoded format.
+
+
+
+
+
+Elz                          Informational                      [Page 4]
+
+RFC 1924       A Compact Representation of IPv6 Addresses   1 April 1996
+
+
+6. Additional Benefit
+
+   Apart from generally reducing the length of an IPv6 address when
+   encode in a textual format, this scheme also has the benefit of
+   returning IPv6 addresses to a fixed length representation, leading
+   zeroes are never omitted, thus removing the ugly and awkward variable
+   length representation that has previously been recommended.
+
+7. Implementation Issues
+
+   Many current processors do not find 128 bit integer arithmetic, as
+   required for this technique, a trivial operation.  This is not
+   considered a serious drawback in the representation, but a flaw of
+   the processor designs.
+
+   It may be expected that future processors will address this defect,
+   quite possibly before any significant IPv6 deployment has been
+   accomplished.
+
+8. Security Considerations
+
+   By encoding addresses in this form, it is less likely that a casual
+   observer will be able to immediately detect the binary form of the
+   address, and thus will find it harder to make immediate use of the
+   address.  As IPv6 addresses are not intended to be learned by humans,
+   one reason for which being that they are expected to alter in
+   comparatively short timespan, by human perception, the somewhat
+   challenging nature of the addresses is seen as a feature.
+
+   Further, the appearance of the address, as if it may be random
+   gibberish in a compressed file, makes it much harder to detect by a
+   packet sniffer programmed to look for bypassing addresses.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Elz                          Informational                      [Page 5]
+
+RFC 1924       A Compact Representation of IPv6 Addresses   1 April 1996
+
+
+9. References
+
+   [IPv6]        Internet Protocol, Version 6 (IPv6) Specification,
+                 S. Deering, R. Hinden, RFC 1883, January 4, 1996.
+
+   [AddrSpec]    IP Version 6 Addressing Architecture,
+                 R. Hinden, S. Deering, RFC 1884, January 4, 1996.
+
+10. Author's Address
+
+   Robert Elz
+   Computer Science
+   University of Melbourne
+   Parkville, Victoria, 3052
+   Australia
+
+   EMail: kre at munnari.OZ.AU
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Elz                          Informational                      [Page 6]
+

Added: branches/upstream/libmath-base85-perl/current/test.pl
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmath-base85-perl/current/test.pl?rev=68676&op=file
==============================================================================
--- branches/upstream/libmath-base85-perl/current/test.pl (added)
+++ branches/upstream/libmath-base85-perl/current/test.pl Tue Feb 15 04:51:02 2011
@@ -1,0 +1,28 @@
+use strict;
+
+use Math::BigInt;
+use Test;
+
+BEGIN { plan tests => 5; }
+
+use Math::Base85;
+ok(1);
+
+# Stealing values from RFC 1924.
+my $n = new Math::BigInt("21932261930451111902915077091070067066");
+my $m = Math::Base85::to_base85($n);
+ok($m, "4)+k&C#VzJ4br>0wv%Yp");
+
+# Supply some invalid stuff.
+my $x = qq("anbukrvq35490ASRVKOAMRS");
+eval {
+    my $y = Math::Base85::from_base85($x);
+};
+ok($@);
+ok($@, qr/invalid base 85 digit/);
+
+# Add 1 and see if we get what we expect.
+my $p = "4)+k&C#VzJ4br>0wv%Yq";
+my $q = Math::Base85::from_base85($p);
+my $r = new Math::BigInt("21932261930451111902915077091070067067");
+ok($q == $r);




More information about the Pkg-perl-cvs-commits mailing list