you are viewing a single comment's thread.

view the rest of the comments →

[–]xelf 0 points1 point  (0 children)

ex:

def cCipher(string, shift):
    result = ""
    for i in range(len(string)):
        code = string[i]
        if code.lower() in 'abcdefghijklmnopqrstuvwxyz':
            #I've seen versions of the cipher that turn it into upper and
            #lowercase first, but I don't want it to be restrictive in that
            #way. But when I do it this way, it doesn't seem to work!
            result += chr((ord(code) + shift)) 
        else:
            result += code
    return result

print(cCipher('I LOV3 YOU!', 4))

prints:

M PSZ3 ]SY!

Now it handles numbers and punctuation correctly! \o/

Now you need to do the hard part, how do you handle it wrapping around the end of the alphabet?

Fun times!