mersenneforum.org

mersenneforum.org (https://www.mersenneforum.org/index.php)
-   Miscellaneous Math (https://www.mersenneforum.org/forumdisplay.php?f=56)
-   -   Possible obfuscation for Mersennes (https://www.mersenneforum.org/showthread.php?t=24025)

paulunderwood 2019-01-23 21:44

Possible obfuscation for Mersennes
 
Carried out on an idle Pi Zero W:

[CODE]? gettime();p=21701;n=2^p-1;e=n;r=Mod(3,n)^((e))-3;print([length(e),lift(r)]);gettime()
[679, 0]
54996
? gettime();p=21701;n=2^p-1;e=lift(Mod(2,n-1)^(p-1));r=Mod(3,n)^((e))+3;print([length(e),lift(r)]);gettime()
[679, 0]
54455
[/CODE]

paulunderwood 2019-01-23 22:10

[QUOTE=paulunderwood;506717]Carried out on an idle Pi Zero W:

[CODE]? gettime();p=21701;n=2^p-1;e=n;r=Mod(3,n)^((e))-3;print([length(e),lift(r)]);gettime()
[679, 0]
54996
? gettime();p=21701;n=2^p-1;e=lift(Mod(2,n-1)^(p-1));r=Mod(3,n)^((e))+3;print([length(e),lift(r)]);gettime()
[679, 0]
54455
[/CODE][/QUOTE]

Oh this is poor. I should have used e=n+1. Other than this the test was 3^((n+1)/2)+3 == 0 (mod n) :redface:

R. Gerbicz 2019-01-23 22:10

[QUOTE=paulunderwood;506717]Carried out on an idle Pi Zero W:

[CODE]? gettime();p=21701;n=2^p-1;e=n;r=Mod(3,n)^((e))-3;print([length(e),lift(r)]);gettime()
[679, 0]
54996
? gettime();p=21701;n=2^p-1;e=lift(Mod(2,n-1)^(p-1));r=Mod(3,n)^((e))+3;print([length(e),lift(r)]);gettime()
[679, 0]
54455
[/CODE][/QUOTE]

Not surprising, in the 1st case e=2^p-1, while in the 2nd case e=2^(p-1) and that enables a simple repeated squaring at powmod. Actually we're doing the 2nd variant with error checking, probably it is better to do 3^(2^p) mod mp to allow a fast space efficient cofactor test for mp/d.

CRGreathouse 2019-01-24 03:14

Incidentally, rather than
[code]? gettime(); foo; print(bar); gettime()[/code]
I would write
[code]? #
? foo; bar[/code]
where # turns the timer on (or off). In your case this would have resulted in
[code]? #
timer = 1 (on)
? p=21701;n=2^p-1;e=n;r=Mod(3,n)^((e))-3;[length(e),lift(r)]
time = 54,996 ms.
%1 = [679, 0]
? p=21701;n=2^p-1;e=lift(Mod(2,n-1)^(p-1));r=Mod(3,n)^((e))+3;[length(e),lift(r)]
time = 54,455 ms.
%2 = [679, 0][/code]

(Apologies if this was known/obvious.)


All times are UTC. The time now is 18:40.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.