from io import StringIO
import string


def rot_encode(data: str, n: int = 13) -> str:
    """ROT-encode the given string, shifting `n` places."""
    if not 1 <= n < 26:
        raise ValueError('n must be in range [1, 26)')
    with StringIO() as digest:
        for char in data:
            if char in string.ascii_letters:
                case = (string.ascii_lowercase
                        if char.islower() else string.ascii_uppercase)
                digest.write(case[(case.index(char) + n) % 26])
            else:
                digest.write(char)
        return digest.getvalue()