|
|
| Keep It Simple, Stupid | |
| PerlMonks |
Kiddie Codesby HaB (Sexton) |
| on Nov 09, 2000 at 21:15 UTC ( #40747=perlquestion: print w/ replies, xml ) | Need Help?? |
|
HaB has asked for the
wisdom of the Perl Monks concerning the following question:
So I have this younger cousin. He's really into fooling around with codes/ciphers and such. I was into the same stuff as a kid, so I figure I'd save him all the work of encoding and decoding by hand, and write him a coupla cool little programs that would do it for him.
So there's a code table I'd like to generate for him, but I'm not sure of the best way to store the data for easy retrieval later. The table works like this:
Now our table is complete. The way to use it is...you find the plaintext letter you want to encrypt, the ciphertext then becomes a two number set made of a randomly selected row number for that row, and the column number. So, plaintext 'a' becomes ciphertext 11, 41 or 71, 'b' becomes 23, 52, or 83, etc, etc. I can figure out ways to generate the table, given a user supplied keyword, but I'm wondering what the best way to store it so it can easily be looked up against? My initial impression is to use 2 hashes, one with the plaintext as keys, the values of which are an array containing each of the 3 possible ciphertext values, and the other being the opposite, but is there a more elegant solution? Some way to store a matrix of data like that that I'm not thinking of? Thanks! HaB
Back to
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||