#!/usr/bin/perl
use strict;
my @wheel1 = qw( 8 4 6 6 3 3 8 4 );
my @wheel2 = qw( 1 2 4 6 3 8 8 9 5 1 6 1 7 2 8 1 );
print "KEY:";
chomp(my $key = <STDIN>);
my @wheel3 = map(ord, split //, $key);
my $file = @ARGV[0];
$/ = undef;
print "OPENING $file\n";
open(IN, "$file") || die "painful death! (because there is no $file)";
my ($out);
my $plaintext = <IN>;
close(IN);
open(OUT, ">$file");
my @nums = map(ord, split //, $plaintext);
foreach (@nums) {
print "*";
my $x = @wheel1[0] + @wheel2[0] + @wheel3[0];
if (@ARGV[1] eq "-d") {
$out = $_ + $x;
} else {
$out = $_ - $x;
}
$out = chr $out;
print OUT $out;
push @wheel1, shift @wheel1;
push @wheel2, shift @wheel2;
print "\b";
}
In reply to Ximp
by beretboy
-
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.
|