[Tutor] Still the Python Challenge - Conclusion

Joaquim Santos jsantos.lazer at gmail.com
Thu Jan 5 19:41:30 CET 2012


Hi List!

I just want to say thank you to all that helped me out!
I've now seen the errors I was doing and how to correct them. Now it
works as it should. I'll be sure to come back with more questions! And
one day help out someone else!

This is my script (I know that I only verify a small range but it
works for what I want for now...)

import string

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.
    '''

    textTranslated = list()

    for letter in cypheredText:

        asciiValue = ord(letter)


        if asciiValue in range(97, 123):
            asciiValue += shiftedCypherNumber

            if asciiValue > 122:
                asciiValue -= 26

        newLetter = chr(asciiValue)


        textTranslated.append(newLetter)

    joinedText = ''.join(textTranslated)

    return joinedText


text = 'g fmnc wms bgblr rpylqjyrc gr zw fylb'

a = decrypt(text, 2)

print a

and this is the end result:

i hope you didnt translate it by hand
-- 

Joaquim Santos

http://js-vfx.com

linkedin


More information about the Tutor mailing list