Is there any way to turn a string of arbitrary length text into an arbitrary BigInt and back?
Not that I know of - though I don't usually use Math::BigInt.
Is it guaranteed that the "arbitrary length text" will contain only valid base 64 characters ?
Math::GMPz (plug) will certainly handle such text, even if it contains invalid base 64 characters - though Math::GMPz isn't included in perl, and depends upon the gmp C library:
use strict;
use warnings;
use Math::GMPz qw(:mpz);
my ($order, $size, $endian, $nails) = (1, 1, 0, 0);
my $s = 'Som3/Arbitr@ri!y/long/string';
my $z = Math::GMPz->new();
Rmpz_import($z, length($s), $order, $size, $endian, $nails, $s);
print $z, "\n";
$z++;
print "$z\n";
my $incremented_s = Rmpz_export( $order, $size, $endian, $nails, $z);
print "$s\n";
print "$incremented_s\n";
# Next retrieve original string:
$z--;
my $orig_s = Rmpz_export( $order, $size, $endian, $nails, $z);
print "$orig_s\n";
__END__
Outputs:
8786758437493627904416651010636024986357833879283932790893327248999
8786758437493627904416651010636024986357833879283932790893327249000
Som3/Arbitr@ri!y/long/string
Som3/Arbitr@ri!y/long/strinh
Som3/Arbitr@ri!y/long/string
But perhaps someone else can provide a solution that better suits your needs.
Cheers,
Rob.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.