package Crypt::PRNG::RC4; use strict; use warnings; our $VERSION = '0.059'; use base qw(Crypt::PRNG Exporter); our %EXPORT_TAGS = ( all => [qw(random_bytes random_bytes_hex random_bytes_b64 random_bytes_b64u random_string random_string_from rand irand)] ); our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); our @EXPORT = qw(); use CryptX; { ### stolen from Bytes::Random::Secure my $RNG_object = undef; my $fetch_RNG = sub { # Lazily, instantiate the RNG object, but only once. $RNG_object = Crypt::PRNG::RC4->new unless defined $RNG_object && ref($RNG_object) ne 'SCALAR'; return $RNG_object; }; sub rand { return $fetch_RNG->()->double(@_) } sub irand { return $fetch_RNG->()->int32(@_) } sub random_bytes { return $fetch_RNG->()->bytes(@_) } sub random_bytes_hex { return $fetch_RNG->()->bytes_hex(@_) } sub random_bytes_b64 { return $fetch_RNG->()->bytes_b64(@_) } sub random_bytes_b64u { return $fetch_RNG->()->bytes_b64u(@_) } sub random_string_from { return $fetch_RNG->()->string_from(@_) } sub random_string { return $fetch_RNG->()->string(@_) } } 1; =pod =head1 NAME Crypt::PRNG::RC4 - Cryptographically secure PRNG based on RC4 (stream cipher) algorithm =head1 SYNOPSIS ### Functional interface: use Crypt::PRNG::RC4 qw(random_bytes random_bytes_hex random_bytes_b64 random_string random_string_from rand irand); $octets = random_bytes(45); $hex_string = random_bytes_hex(45); $base64_string = random_bytes_b64(45); $base64url_string = random_bytes_b64u(45); $alphanumeric_string = random_string(30); $string = random_string_from('ACGT', 64); $floating_point_number_0_to_1 = rand; $floating_point_number_0_to_88 = rand(88); $unsigned_32bit_int = irand; ### OO interface: use Crypt::PRNG::RC4; $prng = Crypt::PRNG::RC4->new; #or $prng = Crypt::PRNG::RC4->new("some data used for seeding PRNG"); $octets = $prng->bytes(45); $hex_string = $prng->bytes_hex(45); $base64_string = $prng->bytes_b64(45); $base64url_string = $prng->bytes_b64u(45); $alphanumeric_string = $prng->string(30); $string = $prng->string_from('ACGT', 64); $floating_point_number_0_to_1 = rand; $floating_point_number_0_to_88 = rand(88); $unsigned_32bit_int = irand; =head1 DESCRIPTION Provides an interface to the RC4 based pseudo random number generator All methods and functions are the same as for L. =head1 FUNCTIONS =head2 random_bytes See L. =head2 random_bytes_hex See L. =head2 random_bytes_b64 See L. =head2 random_bytes_b64u See L. =head2 random_string See L. =head2 random_string_from See L. =head2 rand See L. =head2 irand See L. =head1 METHODS =head2 new See L. =head2 bytes See L. =head2 bytes_hex See L. =head2 bytes_b64 See L. =head2 bytes_b64u See L. =head2 string See L. =head2 string_from See L. =head2 double See L. =head2 int32 See L. =head1 SEE ALSO =over =item * L =item * L =back =cut