473,396 Members | 2,057 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Python - Caeser Cipher Not Giving Right Output

Yozuru
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 
  3.  
  4. def numtochar(n):
  5.     return chr(n + 97) 
  6.  
  7. def two(c1 , c2):
  8.     c1 = chartonum(c1)
  9.     c2 = chartonum(c2)
  10.     return numtochar(c1 + c2 %26)
  11.  
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)
Mar 21 '14 #1
1 1360
Yozuru
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

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

Similar topics

4
by: Chuck Amadi | last post by:
Has anyone got a simple python script that will parse a linux mbox and create a large file to view . Cheers Chu
34
by: Blake T. Garretson | last post by:
I want to save some sensitive data (passwords, PIN numbers, etc.) to disk in a secure manner in one of my programs. What is the easiest/best way to accomplish strong file encryption in Python? ...
1
by: Kun | last post by:
i have a python cgi script that displays tables from a mysql database in html. the problem is, i want to use excel's web query to pull this data and the web query doesn't read .py files. thus...
1
by: Berimor | last post by:
Hi guys, just wondering - which method of output is more fast and use less system resources. The page being build with outup from multiple functions. So, is it better to output each function...
7
by: chiddarwar | last post by:
class Link { public: // function to calculate DH parameter double DHP() { int rows=4; double **R = (double **) malloc(rows * sizeof(double *)); if...
3
by: empiresolutions | last post by:
I'm trying to build my first PHP Class. After days of tweaking, im lost. I am used to working with functions and arrays, but wrapping them in classes is confusing me. The following code is to...
0
by: TheLongshot | last post by:
I have a typed dataset which I used to generate an export file in XML which is consumed by another program. What I'm having a problem is that some of the elements aren't coming out the way I need...
0
by: nuken | last post by:
My code compiles and gives the righ output for the first output
7
by: rsduck | last post by:
Hey, I have spent all of my afternoon writing this program that uses a Caesar Cipher for encryption. I have the entire program written and it works fine. this is the problem area: New text string...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.