Pseudomander:

Actually, there are several bugs in your program. First, a simple test. Using the key 'ABCDEFG' and encrypt the string 'Now is the time for all good men to come'. Then decrypt the resulting string with the key 'ABCDEFG' -- that works just fine. Now let's demonstrate the bug: Try decrypting the result with key values 'XBCDEFG' or 'LMN'. It seems that the key you enter doesn't really do much.

If you add use strict and use warnings, then after prefixing some of the variables with 'my', you'll find a few errors to fix--You're not always indexing your arrays with variables! So adding strict and warnings would be my first suggestion.

When you get those errors out, you'll then see a page of warnings with your program output that should point you to the bug I noticed: You're not initializing @karray with your key string.

While your indenting looks pretty reasonable, I wouldn't double-space the code so much. It just makes everything longer and a bit harder to read.

...roboticus

When your only tool is a hammer, all problems look like your thumb.


In reply to Re: Perl Cipher & questions on semantics/layout optimisation. by roboticus
in thread Perl Cipher & questions on semantics/layout optimisation. by Pseudomander

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.