def rot_n(string, n):
    if not isinstance(n, int):
        raise TypeError

    def _handle_char(char):
        if not char.isalpha():
            return char
        dist = n if char.lower() <= 'm' else -n
        # Return character ordinal value after augmenting the position.
        return chr(ord(char) + dist)

    return ''.join([_handle_char(char) for char in list(string)])
Modified, based on: http://en.literateprograms.org/Rot13_(Python)
dataset/ETHPy150Open christabor/MoAL/MOAL/maths/applied/computational/cryptography/ciphers/historical/substitution/rot13.py/rot_n