def encrypt(plaintext, rails):
    """
    Rail fence cipher. Encrypts plaintext by given number of rails.

    :param plaintext: plaintext to encrypt.
    :param rails: number of rails to use to encrypt.
    :returns: encrypted plaintext (ciphertext).

    See https://en.wikipedia.org/wiki/Rail_fence_cipher
    Example:

    >>> encrypt("DANGEROUS", 2)
    'DNEOS AGRU'
    >>> encrypt("DANGEROUS", 3)
    'DGO AEU NRS'
    """
    data = [""] * rails
    for index, character in enumerate(plaintext):
        data[index % rails] += character

    return " ".join(data)