Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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)); } } <>;


Comment on Re: Perl Cipher & questions on semantics/layout optimisation.
Download Code
Re^2: Perl Cipher & questions on semantics/layout optimisation.
by GrandFather (Cardinal) 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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://956217]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2014-07-14 04:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (254 votes), past polls