[Tutor] implementing rot 13 problems

RJ Ewing ewing.rj at gmail.com
Tue Mar 12 06:57:41 CET 2013


I am trying to implement rot 13 and am having troubles. My code is as
follows:

class Rot_13(webapp2.RequestHandler):
def write_form(self, user=""):
self.response.out.write(rot_form % user)
 def get(self):
self.write_form()
 def post(self):
user = self.request.get("text")
s = self.rot_text(user)
print s
s = "".join(s)
self.escape_html(s)
self.write_form(s)
 def rot_text(self, s):
ls = [i for i in s]
for i in ls:
if i.isalpha():
if i.isupper():
if i <= 'M':
x = ls.index(i)
ls[ls.index(i)] = chr(ord(i) + 13)
else:
x = ls.index(i)
ls[ls.index(i)] = chr(ord(i) - 13)
 elif i.islower():
if i <= 'm':
x = ls.index(i)
ls[x] = chr(ord(i) + 13)
elif i > 'm':
x = ls.index(i)
ls[x] = chr(ord(i) - 13)
return ls

def escape_html(self, s):
return cgi.escape(s, quote = True)

Now if I enter abc, I get nop. But if I enter abcdefghijklmnop, I
get abcqrstuvwxyznop. I have included print statements to check if ls[x] is
changing and it is, but something is going wrong when I return the ls, and
I am not quite sure what it is.

Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130311/18dd0951/attachment.html>


More information about the Tutor mailing list