By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,747 Members | 1,258 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,747 IT Pros & Developers. It's quick & easy.

Python - Caeser Cipher Not Giving Right Output

P: 4
Hello good people, I am able to run my code and it works fine.

However I did a test of:

Expand|Select|Wrap|Line Numbers
  1. two('y', 'z')
and received a '\x92' output instead of a 'x' output.

This is my code so far:

Expand|Select|Wrap|Line Numbers
  1. def chartonum(ch):
  2.     return ord(ch) - 97 
  4. def numtochar(n):
  5.     return chr(n + 97) 
  7. def two(c1 , c2):
  8.     c1 = chartonum(c1)
  9.     c2 = chartonum(c2)
  10.     return numtochar(c1 + c2 %26)
I am thinking I have messed up on my mod 26, however, I am at a lost where I might have went wrong in that. Any help would be appreciated.


Line 10 error in precedence. so ((c1 + c1)%26)
Mar 21 '14 #1
Share this Question
Share on Google+
1 Reply

P: 4
I have found my answer, it was in a problem in line 10 with precedence. Such a simple error that have cost me a few hours. Hope this is useful to those who will see this.
Mar 21 '14 #2

Post your reply

Sign in to post your reply or Sign up for a free account.