Thank you all for your assistance, from the suggestions I've gotten from here and over on the Perl board at HackForums I've made a few updates. I'm yet to include structures but have practised using them as evident in a poem I'm about to upload.
I think I'm going to enjoy it here. Very quick, detailed responses and wonderfully helpful insight.
##Authored by Troy Osborne (Pseudomander) 4:45am 25/02/2012 AEST +10 #
+#
##Free to redistribute, use, copy, upload & adapt this work, all I ask
+ is if it in anyway represents the original version please give credi
+t where due##
use warnings;
$key="";
$offsetpattern="";
$offsetpattern2="";
while (length($key) < 4)
{
print "Please Enter Your Desired Key (5 or more characters) \n -->
+ :";
chomp($key=<>);
}
@karray= split(//,$key);
for ($i=0;$i<length($key);$i++)
{
$temp =0;
for ($i2=0;$i2<length($key);$i2++)
{
$temp += (ord($karray[$i])+ord($karray[$i2]));
$offsetpattern .= chr((ord($karray[$i])+ord($karray[$i2]))
+%256);
}
$offsetpattern2.=chr(int($temp /length($key))%256);
}
@offset = split(//,$offsetpattern);
@offset2 = split(//,$offsetpattern2);
print "Encrypt or Decrypt (E/D)\n --> :";
$inp=<>;
if (($inp=~/E/) or ($inp=~/e/))
#Encryption
{
print "Enter Plaintext\n --> :";
chomp($plaintext = <>);
$len = length($plaintext)-1;
@array = split(//, $plaintext);
for ($i=0;$i<$len;$i++)
{
$char = chr((ord($array[$i]) - ord($offset[$i % length($key)*l
+ength($key)])+ ord($offset2[$i % length($key)]))%256);
print chr(ord($char)-($i%6));
}
}
elsif (($inp=~/D/) or ($inp=~/d/))
#Decryption
{
print "Enter Cyphertext\n --> :";
chomp($cyphertext = <>);
$len = length($cyphertext)-1;
@array = split(//, $cyphertext);
for ($i=0;$i<$len;$i++)
{
$char = chr((ord($array[$i]) + ord($offset[$i % length($key)*l
+ength($key)]) - ord($offset2[$i % length($key)]))%256);
print chr(ord($char)+($i%6));
}
}
<>;
-
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.
|