[Tutor] Python challenge and decryption

Joaquim Santos jsantos.lazer at gmail.com
Mon Dec 19 21:00:40 CET 2011


Hi list!

This is my first post here but I've been following the list for some time
now! I know that recently there was a message about decryption and all. I
think that was what made me go back into the Python challenge and try to
solve some of them...

For the second one, I first laid on paper my ideas, about user interaction
(or input) and what would do what.

I haven't implemented the user input yet but as I tested I ended up having
some problems. Anticipated but still annoying...

 My Python version is 2.7.1 and my OS is Linux Mint 11.

My code is this one:

 def decrypt(cypheredText, shiftedCypherNumber):

'''

This function will take two arguments. The first is the cyphered text, the
second

is the number of characters we need to shift the text so we can decrypt it.

This is a Caesar cypher.

'''

crypticText = list(cypheredText)

for letter in crypticText:

asciiValue = ord(letter)

asciiValue += shiftedCypherNumber

newLetter = chr(asciiValue)

print newLetter

This solves the riddle, however some characters are not correctly
decyphered  (a is coming back as {...) and prints the solution like this:
r
e
c
o
m
m
e
n
d
e
d
0
"
n
o
w
"
{
p
p
l
y
"
o
n
"
t
h
e
"
u
r
l

 - How can I make this "Human readable"? ... Print the letters in just one
(or more) lines and maybe replace the " for spaces (This one I suppose it
could/should be done with whitespaces() or just making a loop to check and
change those for ' '.)

Thanks for your time!
-- 

Joaquim Santos

http://js-vfx.com
<http://js-vfx.com/>
*linkedin*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111219/d556743b/attachment-0001.html>


More information about the Tutor mailing list