*Facepalm* (Sorry About The Meme)

Well, I came to a sudden realization shortly after my post on Saturday — because ROT13 is its own solver, I didn’t need any loops at all for encoding vs. decoding ROT13, just a single function 😳 . And even more horrifying was the next realization — I didn’t even need to have two separate ROT13 programs in the first place AT ALL! Wow. That makes me feel good about myself.

So… here is the “all I ever really needed to do” update, rot13er.v1-0-1.py:

ROT13er v1.0.1

ROT13er v1.0.1

#!/usr/bin/env python

# rot13er.py v1.0.1
# ROT13er
#
# Changelog:
# v1.0.1 (09/26/2010) + Cleaned up code
# v1.0.0 (09/25/2010) + Initial release
#                     * Combines ROT13 Encoder & ROT13 Decoder
#
# Copyright 2010 Benjamin Braithwaite
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# imports maketrans capability & generate ROT13 translation table

from string import maketrans

rot13table = maketrans("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",\
"NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm")

# user interface and encoding magics

print "ROT13er v1.0.1"
print "Copyright 2010 by Benjamin Braithwaite"
print
print "A simple ROT13 translator"
print
toberotted = ""
while not toberotted.strip():
    toberotted = raw_input("Enter your text (ROT13 or plaintext): ")
print
print toberotted.translate(rot13table)
print

# successful exit dialog

raw_input ("Press <enter> to exit.")

You can download rot13er.v1-0-1.py from my Dropbox.

It’s the simple things that get you.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s