#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
Contains common functions
"""

def repeat_char(char, times):
    """
    Repeats a character and returns the result.
    """

    i = 0
    res = ""

    while i < times:
        res += char
        i += 1

    return res

def caesar(text, rot_amount):
    """
    Applies caesar encryption to text.
    """
    lower = "abcdefghijklmnopqrstuvwxyz"
    upper = lower.upper()
    length = len(lower)

    result = ""
    for c in text:
        if c.lower() in lower:
            index = lower.index(c.lower()) + rot_amount

            while index >= length:
                index -= length
            
            if c.isupper():
                result += upper[index]
            else:
                result += lower[index]
        else:
            result += c

    return result
