LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-21-2005, 05:17 AM   #1
necrolin
LQ Newbie
 
Registered: Jun 2003
Posts: 10

Rep: Reputation: 0
Question Rot13 in Python


I've only just begun getting a taste of Python & have a quick question. Is there any easy way to change a character (Rot13 style, so the letter 'a' becomes the 13th char of the alphabet & the 13th char becomes the 'a', etc) in Python?

Many other programming languages let you just add/subtract 13 to a char to change it, but Python allways concatenates & doesn't seem to allow any operations to be done on strings (yes I know that they're immutable).

The solution is probably SO EASY.... I just can't figure it out....

Any ideas?

(Supa thanks in advanced)
 
Old 05-21-2005, 12:21 PM   #2
ortho-orange#42
LQ Newbie
 
Registered: Feb 2005
Distribution: Slackware
Posts: 16

Rep: Reputation: 2
Quote:
I've only just begun getting a taste of Python & have a quick question. Is there any easy way to change a character (Rot13 style, so the letter 'a' becomes the 13th char of the alphabet & the 13th char becomes the 'a', etc) in Python?
Once you have a single char in a variable, you can use ord() and chr():

Code:
n='a'
n=chr(ord(n)+13)
of course, as with most lanugages, this won't account for when n='q', and it returns '~'

good luck
 
Old 05-22-2005, 06:20 AM   #3
necrolin
LQ Newbie
 
Registered: Jun 2003
Posts: 10

Original Poster
Rep: Reputation: 0
Super thanks I'll try that out.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Processing Conflict: python-devel conflicts python< 2.3.4-13.1 guarriman Fedora 2 04-23-2009 07:02 PM
installing python library's (Python Numeric) Four Linux - Newbie 1 10-16-2005 02:31 PM
WineX, python-gnome, and python-gtk DrD Fedora 0 08-03-2004 12:11 PM
decrypting a file using "crypt" & "rot13" JAMZM101 Solaris / OpenSolaris 1 03-07-2004 09:32 AM
install python 2.3 ,necssary to remove python 2.2 ngan_yine Linux - Newbie 7 12-28-2003 04:07 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration