Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
#!/usr/bin/perl use strict; use Term::ReadPassword; sub data { my $file = shift; $/ = undef; open(PDATA,$file) || die "Input File Not Found!"; my $data = <PDATA>; my @data = split("", $data); @data = map(ord, @data); $/ = "\n"; close(PDATA); return @data; } sub passphrase { my $p; my $p = read_password('PassPhrase:'); my @p = split("",$p); @p = map(ord, @p); return @p; } $ARGV[2] || die "Usage: $0 <input file> <output file> <mode (e)ncrypt +(d)ecrypt>\n"; my $mode = $ARGV[2]; my @state = 0..255; my $file = $ARGV[0]; my @data = data($file); my (@iv,$iv); if ($mode eq "d") { @iv = splice(@data,0,10);; } else { open(RANDOM,"/dev/urandom") || die "Can't Find Random Source"; read(RANDOM,$iv,10); close(RANDOM); @iv = split("",$iv); @iv = map(ord, @iv); } my @key = passphrase; my $key_length = push(@key,@iv); my $n; my $a = 0; my $b = 0; for ($n = 0; $n <= 255; $n++) { $b = ($b + $key[$a] + $state[$n]) % 256; ($state[$n],$state[$b]) = ($state[$b],$state[$n]); $a = ($a + 1) % $key_length; } $a = 0; $b = 0; my $data_length = @data; $data_length--; my $c; my $i; my $out = $ARGV[1]; open(OUT,">$out"); if ($mode eq "e") { print OUT $iv; } for ($c = 0; $c <= $data_length; $c++) { $a = ($a + 1) % 256; $b = ($b + $state[$a]) % 256; ($state[$a],$state[$b]) = ($state[$b],$state[$a]); $i = ($state[$a] + $state[$b]) % 256; my $byte = chr $data[$c]; my $cbyte = chr $state[$i]; my $obyte = $byte ^ $cbyte; print OUT $obyte; }

In reply to CipherSaber by beretboy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2024-04-18 21:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found