Pseudomander has asked for the wisdom of the Perl Monks concerning the following question:
Hello all, this is my first post here and in relation to my first Perl script. I've encountered no bugs however most recently having learnt python my presentation /methods aren't very perl reflective. I was wondering if people could give some pointers on: A. The generally accepted presentation. B. Any ways I could have coded this more effectively/effeciently.
##Authored by Troy Osborne (Pseudomander) 4:45am 25/02/2012 EST +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## $key=""; @karray= split(//,$key); $offsetpattern=""; $offsetpattern2=""; while (length($key) < 4) { print "Please Enter Your Desired Key (5 or more characters) \n --> + :"; $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])+ o +rd($offset2[$i % length($key)]))%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 --> :"; $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 { $a=""; print "Enter Cyphertext\n --> :"; $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)); } } $wait =<>;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl Cipher & questions on semantics/layout optimisation.
by roboticus (Chancellor) on Feb 25, 2012 at 06:35 UTC | |
|
Re: Perl Cipher & questions on semantics/layout optimisation.
by repellent (Priest) on Feb 25, 2012 at 07:43 UTC | |
|
Re: Perl Cipher & questions on semantics/layout optimisation.
by GrandFather (Saint) on Feb 25, 2012 at 08:01 UTC | |
| |
|
Re: Perl Cipher & questions on semantics/layout optimisation.
by oko1 (Deacon) on Feb 25, 2012 at 20:51 UTC | |
|
Re: Perl Cipher & questions on semantics/layout optimisation.
by Pseudomander (Novice) on Feb 26, 2012 at 07:23 UTC | |
by GrandFather (Saint) on Feb 26, 2012 at 20:14 UTC |