cryptography Caesar cipher Python implementation


The ASCII way

This shifts the characters but doesn't care if the new character is not a letter. This is good if you want to use punctuation or special characters, but it won't necessarily give you letters only as an output. For example, "z" 3-shifts to "}".

def ceasar(text, shift):
    output = ""
    for c in text:
        output += chr(ord(c) + shift)
    return output