Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!newsfeed.fsmpi.rwth-aachen.de!proxad.net!feeder1-2.proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'example:': 0.03; 'output': 0.05; 'subject:Python': 0.06; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.12; 'wrote': 0.14; 'cipher': 0.16; 'parentheses': 0.16; 'precedence': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:Not': 0.16; 'class.': 0.26; 'certain': 0.27; 'header:X-Complaints-To:1': 0.27; 'point': 0.28; 'appreciated.': 0.29; 'went': 0.31; 'code': 0.31; 'that.': 0.31; 'mod': 0.31; 'problem': 0.35; 'display': 0.35; 'test': 0.35; 'picking': 0.36; 'wrong': 0.37; 'to:addr:python- list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:u 10': 0.60; 'lost': 0.61; 'numbers': 0.61; "you're": 0.61; 'email addr:gmail.com': 0.63; 'term': 0.63; 'skip:n 10': 0.64; 'between': 0.67; '26,': 0.68; 'messed': 0.84; 'subject::': 0.85 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dave Angel Subject: Re:Python - Caeser Cipher Not Giving Right Output Date: Thu, 20 Mar 2014 23:16:50 -0400 (EDT) Organization: news.gmane.org References: <7eee0f2b-0d5f-409e-ae4e-8c9c1af31d74@googlegroups.com> X-Gmane-NNTP-Posting-Host: dpc6744198232.direcpc.com X-Newsreader: PiaoHong Usenet NewsReaders 1.36 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1395371543 news.xs4all.nl 2881 [2001:888:2000:d::a6]:35885 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:68664 dtran.ru@gmail.com Wrote in message: > 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: > > 1. 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) You're missing some parentheses in that line. To test your understanding, try picking some numbers for c1 and c2. Display c1 + c2 % 26, and see if the result is always between 0 and 25. Or look up the term precedence in your textbook. > > 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. > -- DaveA