in reply to Perl Cipher & questions on semantics/layout optimisation.
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)); } } <>;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Perl Cipher & questions on semantics/layout optimisation.
by GrandFather (Saint) on Feb 26, 2012 at 20:14 UTC |
In Section
Seekers of Perl Wisdom