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

decryption

hello
I am trying to make python decrypt a long string into the message

but it seems to be something wrong with my program


I have not done any programming before
and I hope that you help me to understand this one perfectly
here is the quistion
Test 1 - simple phrase, standard shift
>>> decrypt('wkh txlfn eurzq ira mxpsv ryhu wkh odcb grj', 3)
'the quick brown fox jumps over the lazy dog'


and here what I have done so far
Expand|Select|Wrap|Line Numbers
  1. def decrypt(ciphertext, shift):
  2.     """
  3.     Decrypts some ciphertext encrypted with the Caesar cipher.  Uses the
  4.     shift to do the decryption.
  5.     """
  6.  
  7.     newtxt = 'wkh txlfn eurzq ira mxpsv ryhu wkh odcb grj'
  8.     for i in range(len (newtxt)):
  9.         if newtxt[i]== ciphertext:
  10.             return newtxt [(i - shift )%len (newtxt)]
  11.     return newtxt
Apr 4 '10 #1
1 2110
bvdet
2,851 Expert Mod 2GB
Your code is not doing anything. newtxt is never equal to ciphertext. The shift can be accomplished using the built-in functions ord() and chr(). Strings are immutable, so you will have to build a new string. Here's a hint:
Expand|Select|Wrap|Line Numbers
  1. >>> s = "abcdef"
  2. >>> shift=3
  3. >>> "".join([chr(ord(letter)+shift) for letter in s])
  4. 'defghi'
  5. >>> 
Apr 4 '10 #2

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

Similar topics

1
by: D. Alvarado | last post by:
On my Fedora Core 2 Linux dev box, I have installed mcrypt and compiled PHP with the --with-mcrypt option. I am concerned that when I move to another hosting enviornment mcrypt will not be...
1
by: Jase H | last post by:
Hello, I have a ASP.NET web application problem involving the data encryption and decryption assembly(DLL) used on the connection string value that is set in the webconfig file. The problem...
1
by: Martin | last post by:
Hi Im trying to make a Client/Server where im going to encrypt the stream but i cant get it to work. I can recieve and send as long as im not trying to send/recieve encrypted. but when i am i cant...
2
by: sushant.bhatia | last post by:
Hi All. I'm using the NCrypto dll for RSA Encryption/Decryption (http://sourceforge.net/projects/ncrypto/). My encryption code in .Net is pretty simple. The dataToEncrypt length is 1024. The...
2
by: almurph | last post by:
Hi everyone, Can you help me please? I am having a problem with the encryption/decryption of words with the Irish fada in them. The Irish fada is like this: αινσϊ/ΑΙΝΣΪ. It's kind of like the...
0
by: Showjumper | last post by:
I solved my previous problem. The new one is that the password is not being decrypted but rather is still in the enrypted format. I am using Rijndael emcryption. Below is the decryption code. And...
1
by: BigLuzer | last post by:
hi i am using the following setup: - .net 1.1 - 2 load-balanced iis servers - DPAPI machine store. - C# - i encrypted the connection string separately, one on each machine. the error i get...
13
by: Tom Andrecht | last post by:
I'm trying to get some encryption/decryption routines going to take care of my data, and while the encryption is working great, I keep running into the message "Padding is invalid and cannot be...
5
by: Netwatcher | last post by:
well, i started messing around with dictionaries, yet, most of the pages i found about them always talk about getting only one word out of it and turning it vice versa, i've been playing with that...
9
by: Betikci Boris | last post by:
I get bored last night and wrote a script that uses xor for encrypt- decrypt, however it woks fine under linux 2.6.25, text and documents are ok, but fails on compressed files *.jpg, *.pdf , etc ....
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
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
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
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...
0
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...
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.