def perm_conjugate(p1, p2, n=None):
    """
    Conjugate ``p1`` by ``p2``.

    Let call ``res`` the output of this function. If ``p1`` was
    mapping ``a`` to ``b`` then ``res`` will map ``p2[a]``
    to ``p2[b]``.

    EXAMPLES::

        sage: from surface_dynamics.misc.permutation import perm_random, perm_conjugate

        sage: p1 = perm_random(23)
        sage: p2 = perm_random(23)
        sage: res = perm_conjugate(p1, p2)
        sage: res[p2[14]] == p2[p1[14]]
        True
        sage: res[p2[19]] == p2[p1[19]]
        True
    """
    if n is None:
        n = len(p1)
    res = [-1] * n
    for i in range(n):
        res[p2[i]] = p2[p1[i]]
    return res
