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 8999865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:14:12+00:00 2026-06-16T00:14:12+00:00

I am currently doing an assignment that encrypts text by using rot 13, but

  • 0

I am currently doing an assignment that encrypts text by using rot 13, but some of my text wont register.

# cgi is to escape html
# import cgi

def rot13(s):
    #string encrypted
    scrypt=''
    alph='abcdefghijklmonpqrstuvwxyz'
    for c in s:
        # check if char is in alphabet
        if c.lower() in alph:
            #find c in alph and return its place
            i = alph.find(c.lower())

            #encrypt char = c incremented by 13
            ccrypt = alph[ i+13 : i+14 ]

            #add encrypted char to string
            if c==c.lower():
                scrypt+=ccrypt
            if c==c.upper():
                scrypt+=ccrypt.upper()

        #dont encrypt special chars or spaces
        else:
            scrypt+=c

    return scrypt
    # return cgi.escape(scrypt, quote = True)


given_string = 'Rot13 Test'
print rot13(given_string) 

OUTPUT:

13 r
[Finished in 0.0s]
  • 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-16T00:14:12+00:00Added an answer on June 16, 2026 at 12:14 am

    First thing that may have caused you some problems – your string list has the n and the o switched, so you’ll want to adjust that 🙂 As for the algorithm, when you run:

    ccrypt = alph[ i+13 : i+14 ]
    

    Think of what happens when you get 25 back from the first iteration (for z). You are now looking for the index position alph[38:39] (side note: you can actually just say alph[38]), which is far past the bounds of the 26-character string, which will return '':

    In [1]: s = 'abcde'
    
    In [2]: s[2]
    Out[2]: 'c'
    
    In [3]: s[2:3]
    Out[3]: 'c'
    
    In [4]: s[49:50]
    Out[4]: ''
    

    As for how to fix it, there are a number of interesting methods. Your code functions just fine with a few modifications. One thing you could do is create a mapping of characters that are already ‘rotated’ 13 positions:

    alph = 'abcdefghijklmnopqrstuvwxyz'
    coded = 'nopqrstuvwxyzabcdefghijklm'
    

    All we did here is split the original list into halves of 13 and then swap them – we now know that if we take a letter like a and get its position (0), the same position in the coded list will be the rot13 value. As this is for an assignment I won’t spell out how to do it, but see if that gets you on the right track (and @Makoto’s suggestion is a perfect way to check your results).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently doing a SQL assignment but a certain task has mentioned that
Hey! I am currently doing some prep for my upcoming college assignment but am
I am currently doing a programming assignment and it says that we should store
Im currently doing a console app that has to send scheduled emails. In one
I am currently doing a C# WPF application that generates a table that does
I'm currently doing the calculator app that has the graph functionality. So then, I
I'm currently doing some testing to determine the performance implications of including an index
I am currently doing an android application that contains customize alert dialog. It contains
Currently doing a group project for college in Java. The assignment is to produce
I'm currently doing a Java assignment as a computer science fresher. As a part

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.