Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8961935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:00:34+00:00 2026-06-15T16:00:34+00:00

I am trying to do the following: In an HTML TextArea, change the position

  • 0

I am trying to do the following:

In an HTML TextArea, change the position of each character of the entered text in the ASCII table by 13 positions (in my code it is rot13 function).

Here’s the Rot13 function:

def rot13(s):
    for a in s:
       print chr(ord(a)+13)

It does work this way, but it prints as well header information and omits the last character. So when I enter the word ‘Hello’ in the box, the result is:

U r y y | Status: 200 Content-Type: text/html; charset=utf-8 Cache-Control: no-cache Content-Length: 4 None

So how to go about this?

Also, when I tried to do it this way:

def rot13(s):
    for a in s:
       chr(ord(a)+13)
    return s

It returned the same text I’ve put in the text, without the changes I thought there would be. So as I understand, it doesn’t modify the ‘s’ directly that way? So how to go about this?

The whole code is below:

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

form = """<html>
<head><title>Rot13</title></head>
<body>
<form method="post">
Please enter your text here:<br>
<textarea name="text"></textarea>
<input type="submit">
</form>
</body>
</html>
"""

def rot13(s):
    for a in s:
       print chr(ord(a)+13)

class MainHandler(webapp2.RequestHandler):
    def get(self):
        self.response.out.write(form)

    def post(self):
        entered_text = self.request.get('text')
        self.response.out.write(rot13(entered_text))

app = webapp2.WSGIApplication([
    ('/', MainHandler)
], debug=True)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:00:35+00:00Added an answer on June 15, 2026 at 4:00 pm

    EDIT: Here is a function for performing an actual ROT13 on a string (my apologies – I wasn’t aware this was an actual algorithm – the method I provided in the previous answer will not perform true ROT13). However if you are looking for an efficient way to implement it, you are going to have a hard time beating @NickJohnson’s answer 🙂 This translates according to table here, with uppercase mapping to uppercase and lowercase mapping to lowercase. This creates a mapping of uppercase and lowercase letters, mapped to their ROT13 equivalents by splitting the component parts in half and flipping them. You then zip the ‘normal’ and ‘reversed’ lists together and create a dictionary from the key/value pairs that are generated:

    In [1]: import string
    
    In [2]: w = 'SecretWord'
    
    In [3]: uc, lc = string.uppercase, string.lowercase
    
    In [4]: c_keys = uc + lc
    
    In [5]: c_val = uc[13:] + uc[:13] + lc[13:] + lc[:13]
    
    In [6]: d = dict((k, v) for k, v in zip(c_keys, c_val))
    
    In [7]: ''.join(d[i] for i in w)
    Out[7]: 'FrpergJbeq'
    

    And to hopefully make it easier to visualize, here is what the key/value strings look like:

    In [8]: c_keys
    Out[8]: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
    
    In [9]: c_val
    Out[9]: 'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm'
    

    Instead of using print, you’ll want to use self.response.out.write (as you have in other places). This will write the result to the HTTP response that is sent to the requester (note that headers are part of the response as well, but aren’t printed to the screen unless specified when using self.response.out.write). In your case, a simplified version could look something like this:

    def rot13(s):
        return ''.join(chr(ord(a)+13) for a in s)
    

    Instead of printing each character, it constructs a string using the function you defined. This will return that string, and the result will be written out as a response. You could also add additional HTML formatting etc., but this should hopefully get you on the right track.

    Also, regarding why your second function didn’t work:

    def rot13(s):
        for a in s:
           chr(ord(a)+13)
        return s
    

    The reason that it returns s unaltered is because although you are performing the chr(ord(a)+13) step, you aren’t doing anything with it. Your function is definitely on the right track, so one way to make it return identical output to the one in the example above is to create an empty list that will store each modified character, and then join the list at the end:

    def rot13(s):
        # This is your container
        l = []
        for a in s:
           # Now, instead of just running the function, we add the result to the list
           l.append(chr(ord(a)+13))
        # And finally, we use join to join all the list elements together and return
        # E.g. If your list is ['a', 'b', 'c'], this returns the string 'abc'
        return ''.join(l)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to generate the following html code using cl-who: <html> <body> <div id=cnt_1></div>
Following chunk html code works as expected: <iframe src=http://www.amazon.com/></iframe> But when trying embed inner
I am trying to replicate the following code using HTML Helper in CakePHP 2.1.
i am trying to understand following fragment of javascript code <!DOCTYPE html> <html> <body>
Trying to customize Symfony2 form to produce html code looking like the following example:
I have the following html: <div class=bf_form_row> <label for=findout>Text goes here</label> <textarea class=findOut cols=40
I have the following html code, and I am trying to get all the
I am trying out the following HTML code on iOS Safari: <!DOCTYPE html> <html>
I have the following HTML code <td class=testclass> </td> I'm trying with the following
I'm trying to Parse the following HTML pages using BeautifulSoup (I'm going to parse

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.