libvenus has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

Is there a encrypt/decrypt module built in pure perl ?

Thanks

  • Comment on Enrypt/decrypt module built in pure perl

Replies are listed 'Best First'.
Re: Enrypt/decrypt module built in pure perl
by zentara (Cardinal) on Feb 27, 2009 at 12:46 UTC
    Here is a pure Perl RC4, that I wrangled from some old Perl4 code. Making it work on strings and writing to variables is up to you.
    #!/usr/bin/perl -0777 -- # $0 key infile > outfile # symmetric works both ways use strict; use warnings; my @k = map { ord($_) } split //, shift; my ( @s, $x, $y ); $y = 0; for ( my @t = @s = 0 .. 255 ) { $y = ( $k[ $_ % @k ] + $s[ $x = $_ ] + $y ) % 256; &S; } $x = $y = 0; for ( unpack( 'C*', <> ) ) { $x++; $y = ( $s[ $x %= 256 ] + $y ) % 256; &S; print pack( 'C', $_ ^= $s[ ( $s[$x] + $s[$y] ) % 256 ] ); } sub S { @s[ $x, $y ] = @s[ $y, $x ] }

    I'm not really a human, but I play one on earth My Petition to the Great Cosmic Conciousness

      This looks Neat, Thanks Guys !!

Re: Enrypt/decrypt module built in pure perl
by dHarry (Abbot) on Feb 27, 2009 at 11:14 UTC

    yes

    Shortest answer ever?

    e.g. UnixCrypt for a Perl only crypt module. But there are several, see CPAN! What are your requirements?

    Udate
    Crypt::Lite is an option but not if you're looking for STRONG encryption.

      Well i m browsing a website using Mechanize.I m authenticating myself by entering my login credentials. Now the login password is stored in clear text and i want to get rid of that.So i thought if i could store the encryted password somewhere and later retreive and decrypt it and then use it in my script, i could achieve the same.

      Let me know if there is a more elegant way to do the same

        I would follow the same approach. Of course don't hard code the password/key in the script, then you would gain little compared to your current approach.