DEV Community

Lancelot03
Lancelot03

Posted on

5 2

Rot13

ROT13 is a simple letter substitution cipher that replaces a letter with the letter 13 letters after it in the alphabet. ROT13 is an example of the Caesar cipher.

Create a function that takes a string and returns the string ciphered with Rot13. If there are numbers or special characters included in the string, they should be returned as they are. Only letters from the latin/english alphabet should be shifted, like in the original Rot13 "implementation".

Please note that using encode is considered cheating.

Solution- ###Python

def rot13(message):
    alpha="abcdefghijklmnopqrstuvwxyz"
    string=''
    for i in message:
        if i in alpha:
            if alpha.index(i)<13:
                string += alpha[alpha.index(i)+13]
            else:
                string += alpha[alpha.index(i)-13]
        elif i in alpha.upper():
            if alpha.upper().index(i)<13:
                string += alpha.upper()[alpha.upper().index(i)+13]
            else:
                string += alpha.upper()[alpha.upper().index(i)-13]
        else:
            string +=i
    return string
Enter fullscreen mode Exit fullscreen mode

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay