Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #68664
| From | Dave Angel <davea@davea.name> |
|---|---|
| Subject | Re:Python - Caeser Cipher Not Giving Right Output |
| Date | 2014-03-20 23:16 -0400 |
| Organization | news.gmane.org |
| References | <7eee0f2b-0d5f-409e-ae4e-8c9c1af31d74@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.8341.1395371543.18130.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Python - Caeser Cipher Not Giving Right Output dtran.ru@gmail.com - 2014-03-20 19:50 -0700
Re:Python - Caeser Cipher Not Giving Right Output Dave Angel <davea@davea.name> - 2014-03-20 23:16 -0400
Re: Python - Caeser Cipher Not Giving Right Output dtran.ru@gmail.com - 2014-03-20 20:23 -0700
Re: Python - Caeser Cipher Not Giving Right Output Dave Angel <davea@davea.name> - 2014-03-21 00:02 -0400
Re: Python - Caeser Cipher Not Giving Right Output Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-03-21 03:58 +0000
Re: Python - Caeser Cipher Not Giving Right Output dtran.ru@gmail.com - 2014-03-20 21:23 -0700
Re: Python - Caeser Cipher Not Giving Right Output Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-03-21 09:50 +0000
Re: Python - Caeser Cipher Not Giving Right Output Rustom Mody <rustompmody@gmail.com> - 2014-03-20 21:02 -0700
Re: Python - Caeser Cipher Not Giving Right Output Ian Kelly <ian.g.kelly@gmail.com> - 2014-03-22 08:22 -0600
Re: Python - Caeser Cipher Not Giving Right Output Rustom Mody <rustompmody@gmail.com> - 2014-03-22 10:29 -0700
csiph-web