Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Perl Cipher & questions on semantics/layout optimisation.

by Pseudomander (Novice)
on Feb 26, 2012 at 07:23 UTC ( #956217=note: print w/replies, xml ) Need Help??

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 (Sage) on Feb 26, 2012 at 20:14 UTC

    You asked for guidance concerning presentation and effective/efficient coding. You were given a large stack of replies, most of which you seem to have ignored. You have fixed the bugs we pointed out (even though you thought you had none), but seem not to have made a single style change of the many suggested.

    We are generally keen to help, but become less keen when ignored. Re-read roboticus's, repellent's, oko1's and my replies again to get the details. A list of key points that you have ignored would include:

    • roboticus (and others) use strictures
    • roboticus don't double space your code (this may be a foible of copy and paste, but fix it)
    • repellent avoid redundant work
    • oko1 use Perl - especially Perl's for loops
    • GrandFather refactor your code to avoid large chunks of duplicated code

    Most of those replies touched on most of those points either directly or indirectly. As you didn't seem to pick up on them first time round you should really go back and read them in detail until you understand what they are saying. Each respondent will be eager to explain further anything that seems unclear if you show an interest.

    True laziness is hard work

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://956217]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2018-06-23 06:53 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (125 votes). Check out past polls.