Hello good people I am working on a caeser cipher program for class. However, I ran into a problem with my outputs. Up to a certain point for example:

two('y', 'z')

Would give a '\x92' output instead of a 'x' output.

Currently this is my code so far:

def chartonum(ch):
    return ord(ch) - 97 

def numtochar(n):
    return chr(n + 97) 

def two(c1 , c2):
    c1 = chartonum(c1)
    c2 = chartonum(c2)
    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.

4 Years
Discussion Span
Last Post by Yozuru

I have found the source of error, it was in regards to precedence in line 10.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.