def crack_secret_exponent_from_k(generator, signed_value, sig, k):
    """
    Given a signature of a signed_value and a known k, return the secret exponent.
    """
    r, s = sig
    return (s * k - signed_value) * generator.inverse(r) % generator.order()
