Wednesday, March 18, 2015

Do You Want To Write Some Code?

OK I feel better. I was overcome with an urge to write some code. Now I have a program I should write. I want to combine my seating chart program (with pictures) with the program I use to randomly pick on students. I mean randomly pick who to call on. Whoops. But I don't have the time to work on that right now.

So I wanted a "toy program." I remembered that I had been playing with a simple Caesar cipher program  (who else remembers ROT-13?) What I have long been meaning to do was to write a program that took a string and rotated it though all 25 possible rotations (26 puts it back the way it was) and build a list so that if you suspected a Caesar substitution you could test it to see how it was rotated. Fine.

So I took the code for rotating in the encoding program and made it a simple little string function. Added a loop to pass a string to the function with different values to rotate and put the result in a listbox. By reusing code I was done in about 10 minutes. And I have a toy program I will probably use once every couple of years and could probably find a web app that does the same thing in about the same time it took to write the code. But oh so much more satisfying. image

Who knows - I might assign it as a programming assignment someday as well. BTW Mike Zamansky has a closely related (and probably more useful post) on his blog  Rot13 - Gateway Drugs Techniques

5 comments:

Mike Zamansky said...

Check out my related post from last year

Alfred C Thompson II said...

I'd forgotten about that post Mike. Much more useful than mine. I added a link to it in body of the post.

AndyNu said...

I've long loved ciphers, as you know. While lazily watching cartoons I noticed an odd frame at the end of Gravity Falls ( http://vignette2.wikia.nocookie.net/gravityfalls/images/0/0d/S1e1_barf_gnome_code.png/revision/latest?cb=20140301184202 ). Turns out they had been embedding ciphers into every episode! A bit of fun figuring out what ciphers were used and decoding them.

Unknown said...

Challenge accepted!
After reading the post, Alfred, I had to code it!
Here it is in Java: http://repl.it/e1r
(currently shows AndyNu's cipher from his image link (23rd rotation) :)

Alfred C Thompson II said...

Andy, actually you are at least partially responsible for reenergizing an interest in ciphers I had but had left behind for a while.