def encrypt(msg, a, b, k):
    """ encrypts message according to the formula l' = a * l + b mod k """
    encrypted_message = ""
    for letter in msg:
        if letter == " ":
            encrypted_message += " "
        else:
            encrypted_letter_index = (a * (ord(letter) - ord('a')) + b) % k
            encrypted_message += chr(encrypted_letter_index + ord('a'))
    return encrypted_message