Greetings!
In my current project (reinventing the wheel: a request tracking system) I use Crypt::RSA to encrypt username and password strings when sent between client and server. To exchange the public key between two perl clients are a piece of cake but I need to be able to exchange the key with a Visual Basic.NET client aswell. To do this I convert the modulus (a really big integer) to an array of bytes and then to a comma separated string. This is fairly easy to import in .NET Framework cryptography API (it works, I've tested it).
Anyway, I use the module Math::BigInt to be able to handle really large numbers. I have two subroutines: bigint_to_bytearray($bigint) and bytearray_to_bigint(@bytearray). The first one (used when converting the modulus to an array of bytes) runs fast on my development box (a Pentium II 350MHz) but the second one (used when converting an array of bytes back to a bigint) takes 4-5 seconds.
I'm wondering if there's something I can do to speed this up, besides getting a better development box? :)
sub bigint_to_bytearray { my $bigint = shift; my @bytes; while(1) { my ($q,$r) = $bigint->brsft(8); push(@bytes,$r+0); last if $q == 0; $bigint = Math::BigInt->new($q); } return @bytes; }
## This is the one I would like to speed up ## The array looks something like (127,6,64,27,166,33 .... ) sub bytearray_to_bigint { my @array = @_; my $count = Math::BigInt->new('0'); my $result = Math::BigInt->new('0'); foreach my $a (@array) { $result += $a * (256**$count++); } return $result; }
--
dempa
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |