473,549 Members | 2,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Python - Caeser Cipher Not Giving Right Output

Yozuru
4 New Member
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 1365
Yozuru
4 New Member
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
8854
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
4070
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? Any modern block cipher will do: AES, Blowfish, etc. I'm not looking for public key stuff; I just want to provide a pass-phrase. I found a few...
1
1170
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 i am wondering what is the easiest way to just turn my .py html output into a .html output. you can check the query here:
1
1235
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 result directly with "echo" construction: echo "string1"; echo "string2"; ................ echo "stringN";
7
1443
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 (joint_type == 0)
3
1873
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 return an Array Collection representative of a folder and sub folder in a directory of choice. It doesn't work. Throws an error "Call to undefined...
0
993
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 them. For example, I have a section (which is a child table for my record) which keeps track of security accesses. The problem is, I need the...
0
944
by: nuken | last post by:
My code compiles and gives the righ output for the first output
7
3645
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 is the above string converted to lower case, "the quick brown fox jumps over the lazy dog" Extract the letter 'D' (first letter) from the key. ...
0
7451
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7720
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7959
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7473
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5088
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3501
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3483
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1944
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1061
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.