Bill Allombert on Wed, 21 Jun 2023 18:05:22 +0200
|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: How to compute "Mod(2^(n+1), n)" for very big n?
|
- To: pari-users@pari.math.u-bordeaux.fr
- Subject: Re: How to compute "Mod(2^(n+1), n)" for very big n?
- From: Bill Allombert <Bill.Allombert@math.u-bordeaux.fr>
- Date: Wed, 21 Jun 2023 18:00:25 +0200
- Arc-authentication-results: i=1; smail; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; d=math.u-bordeaux.fr; s=openarc; t=1687363216; c=relaxed/relaxed; bh=6rlZitKPyxD8FqzjC/1nv8WSLR4DIwDtna6P1LNBfrY=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:Mail-Followup-To: References:MIME-Version:Content-Type:Content-Disposition: In-Reply-To; b=pP/jduclUO+rh7xvlKmq0Nlh9nKOJnn2LCkWLtIhsYpf+mQ4h5nY3GYgPvhmiNK6QbSMa0efZxbKOScfR/E8gqD1O7aZMfNSVUWsl1UazkH7we+hnJfVKuJw8ggYK6JnPTjlIQXjiffUl7BTm10DdfNdjWNEwbpd+mmN20ejVedo8e+/5vkhTk9JaVsc9IPQT4xASTwZ9BobFtblw7tx7shU/F1cFLDKRKAsRtxa1NfBILlU/qmPo+cy1uy345INMvR959hemWlWPPecuA4KJwEbagXs4N3XIsbQ1+TtO1WhH8do6ENyVUgc3k2rkyVChKU9Yvv9K2tBB19QfgM7GHuXUALWKsUFHHcHOZucgWYicfYb0MctK/CKiy+wSZGIRMk+aKOpR/b8XA8FCacPNoh5Q6UGgS8IEThCL75LScnd+UaKbSC26A6h7IHEhgo4m/b2wCmes7mCdRplj0vpEBY1cGEXGZtaMzg/Q5WkQNaxXqtqtMIeTQfYl+P0lZGbEAeQkA3K73lwp9F5mpcNRgsihU1N3LbWQa3ES1FrmufIN6dNhVGCVs6BTDVagAN+t4p/SXyHKDxBTGAQbDsIc6xlQazHHzAbzHAfComWhCIKZszeFa3SMBejWP5BxAmH47bLgup68WXfbNAVcj1+oG9Jq2wJ2dneehUDZv8qqQk=
- Arc-seal: i=1; a=rsa-sha256; d=math.u-bordeaux.fr; s=openarc; t=1687363216; cv=none; b=gk0SugprpCZ83FupjwilWoVseLtPJhXC+dx8A97rQRjn5Ka3jhgnGUsvOFueL2QOY7IHA4BS4dflkFaRzHXfZvG6XeEIqOrq0CSZPXTm2+1yUnZ1UQwfVmPvHNthDO8ipdLUkLsk6XeQd237j6lbXCmeLRIytERaSmFxDmClGFkRdowaY7asdkaxhsy5rmY0TqTHVCGBuAuY0LKD/Q9Lf09Kq2ua0fj86TFvCVRaFx13kBT0hINij0gSzAh7g9oRJA42P8n/lzLcR0X7Rxg+RYWLXd3x4YtIqpMDUC9B2V+gHknUmaanTBeMTiHKhTCfeNqoFfLO5gYIBXs0U+6csEQTJekHYzctDciB0dagsqrZZRNgjpW59rJBGjHmAUzpiFEJO5so0me9/e1YFXbIPcyJNjTpnDGahIsJBsv2GK/Fz59mYe7k0W/mNpUB028/ZfvG81bPdpMt814s/2twKGyyGiq+Xo2XIO1UW4/dW9GdlHSUb0T2+U8J7mISmUnez1fqbe26twh+vztgA/J+8bR+2LcPt8I20pQUmkEM0Xgq5nE12SnzOYoHGE94Ji8duG2XaSWs2G32CGRSyrAAxR6WA/c1E1GXwvqC91kTMw3X08E4FV2rvguEy7lscR29xj7XTI75ulpict7QdzpMD4jUexGFrt/oKOTT2N8e3FM=
- Authentication-results: smail; arc=none
- Delivery-date: Wed, 21 Jun 2023 18:05:22 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=math.u-bordeaux.fr; s=2022; t=1687363216; bh=6rlZitKPyxD8FqzjC/1nv8WSLR4DIwDtna6P1LNBfrY=; h=Date:From:To:Subject:References:In-Reply-To:From; b=bNqwSzevkQKXdPYYZFds1vWDIj9PKUTs34JWpsqfu0GA+JSgRQHAYvFjkm2fwlO4B IoPkMYixQ9sZ+LKVuM9qXcJagEg+M/Oth1aMafICQpxPpkaY9GnNT/Up5P24SOhUN2 UoOMaHOy4yh1/4H9De5Trwd0qkfGiGBH+4zjlurl/dK4qfnDfOrP5wUZQfpHrHG8+f 3VWcZRpBGeOWscpxFEEqTgglQ4b85mWhXdkxwYlYqRLUmPY/aRRfxVl61vDJsYwNnr COFhFro4qo53lusAtuksj/YNpVB9fpGyn7TK4MYAjnx0ZiTyBRf9QyKZH0aRFElZJG BB8wEM+t3M3NlTncPYMNTMOe88ml9n36msBrbzKwtoirnLRM9D2JxsyoJNpLbhhnMD baTku6oi+Nqi7+nDGCU3g/SHZpWV1Z+uqoUHHQ40yJBFVLQs+Z877A3FoEgvkJrbTq VeLEit1bEVl6BSGZ44NzdBBqxhnNOG23o/R5qydCz0fCy4XPC+PDYijecrXFXHuTFB 7OB6n1Z89bCuYk7rmAp8qiS6HEThXTwE8m8N01Q74/u3Bgj8hm2W+KDC3aQ5y4scOI XLdDZj91tb07yWF5cCaxc5QMjKd5KMwLy+Y7cH2plmZ82U91yukF1sClAEzx5RyXI0 uaIt3ppKClr9jZO2zZRMG7rM=
- In-reply-to: <ebeeaa417d6426893a751caca375d469@stamm-wilbrandt.de>
- Mail-followup-to: pari-users@pari.math.u-bordeaux.fr
- References: <3f13b3ca89d86d8309ac70bf0fbc59b3@stamm-wilbrandt.de> <ZJLZszjqOCinDkv3@jurong> <ebeeaa417d6426893a751caca375d469@stamm-wilbrandt.de>
On Wed, Jun 21, 2023 at 03:27:05PM +0200, hermann@stamm-wilbrandt.de wrote:
> On 2023-06-21 13:06, Andreas Enge wrote:
> > Do it the other way round:
> > Mod(2,n)^(n+1).
> > This way, exponentiation happens directly in Z/nZ (by successive
> > squaring
> > and multiplying, each followed by a reduction modulo n), instead of
> > trying
> > to compute integers that may not fit into the universe.
> >
> Thank you, that worked perfectly.
>
> I am positively surprised of znlog() speed on big numbers (on i7-11850H CPU)
> ...
>
> Knowing "n+1-(p-1)*(q-1)=p+q" allows to factor "n=p*q"
> https://en.wikipedia.org/wiki/Vieta%27s_formulas#Example
> (factoring of RSA-79 in 6:34min below, slower than 1.54min(msieve) and
> 4:15min(GP factor below))
>
> https://github.com/Hermann-SW/RSA_numbers_factored/blob/main/pari/RSA_numbers_factored.gp
>
> $ gp-2.15 -q
> ? \r RSA_numbers_factored
> ? [l,n,p,q] = rsa[1][1..4];
> ? [l, n==p*q && (l==#digits(n)) || (l==#digits(n,2))]
> [59, 1]
> ? znlog(Mod(2, n)^(n+1), Mod(2, n))
> 557869722222203919880529024454
> ? ##
> *** last result computed in 6,047 ms.
> ? [l,n,p,q] = rsa[2][1..4];
> ? znlog(Mod(2, n)^(n+1), Mod(2, n))
> 9447104136878167876008523981447380846704
> ? ##
> *** last result computed in 6min, 33,579 ms.
You can speed up this by doing
addprimes([p,q])
so that znlog does not need to factor n.
But the cost of znlog is related to the largest prime factor of eulerphi(n),
not of n.
Cheers,
Bill.