Python - Caeser Cipher Not Giving Right Output

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Yozuru
    New Member
    • Mar 2014
    • 4

    Python - Caeser Cipher Not Giving Right Output

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

    However I did a test of:

    Code:
    two('y', 'z')
    and received a '\x92' output instead of a 'x' output.

    This is my code so far:

    Code:
    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.

    EDIT: SOLVED.

    Line 10 error in precedence. so ((c1 + c1)%26)
    Last edited by Yozuru; Mar 21 '14, 04:26 AM. Reason: Issue was resolved.
  • Yozuru
    New Member
    • Mar 2014
    • 4

    #2
    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.

    Comment

    Working...