473,396 Members | 1,805 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.

Ceasar Cipher help

Hi all, im writing a caesar cipher and ive done most of the program (see below)
Expand|Select|Wrap|Line Numbers
  1. def decrypt(ciphertext, shift):
  2.     decrytped_text = " "
  3.  
  4.  
  5.     for letter in ciphertext:
  6.         if letter.isalpha():
  7.             num = ord(letter)
  8.             num += key
  9.  
  10.             if letter.isupper():
  11.                 if num > ord('Z'):
  12.                     num -= 26
  13.                 elif num < ord ('A'):
  14.                     num += 26
  15.             elif letter.islower():
  16.                 if num > ord('z'):
  17.                    num -= 26
  18.                 elif num < ord('a'):
  19.                     num +=26
  20.  
  21.             decrypted_text += chr(num)
  22.         else:
  23.             decrypted_text += letter
  24.     return decrypted_text
  25.  
  26. print 'Decryted text is : '
  27. print decrypt(ciphertext, shift)
[/i][/i]
now when i run this program it says shift and ciphertext are not defined. I understand that they aren't defined im just having difficulty in knowing where and how to define these to parameters so that my program works.

If you coul help or point me in the right direction that would be great.

Thanks


oh and heres what im testing it on :

decrypt('bcdefghijklmnopqrstuvwxyza', 1)
'abcdefghijklmnopqrstuvwxyz'

very simple i know, but im a n00b at python :)
any help would be greatly appreciated.
Apr 6 '10 #1
2 4391
and it all formatted wrong... i had all the correct spacing by the way just failed in the box.
Apr 6 '10 #2
bvdet
2,851 Expert Mod 2GB
The error message is telling you that the variables are not defined. That gives it away. You need to assign a value to the variables.
Expand|Select|Wrap|Line Numbers
  1. ciphertext = 'bcdefghijklmnopqrstuvwxyza'
  2. shift = -1
You also had a typo with the name decrypted_text and an undefined variable named key.
Apr 7 '10 #3

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

Similar topics

6
by: Michael Sparks | last post by:
Hi, I suspect this is a bug with AMK's Crypto package from http://www.amk.ca/python/code/crypto , but want to check to see if I'm being dumb before posting a bug report. I'm looking at...
4
by: Carl Harris | last post by:
I am trying to write some code to: 1.Prompt a user for filenames 2.Open the files 3.Convert my plain text into a cipher text array/string bear in mind I am a novice! I have wriiten some code...
7
by: Piotr Turkowski | last post by:
Hi! Here you can get some notes about Vigenere Cipher: http://raphael.math.uic.edu/~jeremy/crypt/vignere.html Here's whole code of my program, function stats() is in polish, so you can omit...
9
by: Piotr Turkowski | last post by:
Hi, The code is here: http://free.ud.pl/~piotr/data/vigenere.zip Its my program for decrypting and encrypting text. Shot polish course: szyfrowanie (szyfruj) - encrypting (text i want to code...
2
by: Julio C. Hernandez Castro | last post by:
Dear all, We have just developped a new block cipher called Raiden, following a Feistel Network structure by means of genetic programming. Our intention now consists on getting as much feedback...
1
by: beetle17 | last post by:
Plaintext: a  n i c e  d a y Key: -3 Ciphertext: X  k f Z b  a X v Cipher will accept commands from the user and perform the operations required by the commands. There are three different...
16
by: Cawas | last post by:
Cipher Lab produces some terminals to collect data where we can program using one implementation of plain C which I believe to be ANSI C89 compatible, although not fully. They have their on set of...
4
by: wagn31 | last post by:
i need to use a cipher but I have to used the assigned code in the ciphering i know how to do it, but i am not sure how to add my own dictionary. Here is what i have so far:
2
by: yeruvavasavi | last post by:
Algorithm 1: Write python programs to translate the following algorithm so that the computer can execute it. Algorithm for ceaser cipher. Plain: ABCDEFGHIJKLMNOPQRSTUVWXYZ<br> Cipher: ...
0
by: ntuyen01 | last post by:
Hi all, I want to use the SSLStream with the cipher (TLS_RSA_WITH_AES_128_CBC_SHA) to get the handshake with my server, but I not sure where I can start. I do it in C# 2.0 Here is my code: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.