hermann on Sat, 02 Nov 2024 17:08:47 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Using Python with PARI/GP questions


On 2024-11-02 14:42, Bill Allombert wrote:
A)
GP has (clear text) input(). Is GP equivalent of Python stdiomask.getpass()
that outputs asterisks instead of typed characters available?

Well, you can do this
system("stty -echo");pass=input();system("stty echo");

Thanks,

the only difference is now that the asterisk string is printed
after input is done, and millisecond instead of nanosecond
epoch time resolution. But works completely in GP:


pi@raspberrypi5:~/RSA_numbers_factored/1_sum_of_2_sqs_semiprime $ gp -q challenge2.gp
factor: *****************************
1
1
12674988827644889593886051396659669133790754562802381898025231956799840196181471058316567353242931322400922980847459764209579800938
9211836267421248614009865925992363275561558169502211175708993142609913375197182792658023465416009109275544330543363710062812454623
245513269198700214532821005376453832068566191949797939758100426102896056777101734793436365552506093863559978647854618527678907206365921953315786880756850102741847738255056458215402745365290758082184122510669989523798578472944843382620095748357877340978139751973
261 decimal digits semiprime
pi@raspberrypi5:~/RSA_numbers_factored/1_sum_of_2_sqs_semiprime $ cat challenge2.gp
readvec("../pari/RSA_numbers_factored.gp");

{
print1("factor: ");system("stty -echo");s=input();
system("stty echo");for(i=1,#digits(s),print1("*"));print();

setrand(getwalltime() * eval(s));

L=432;

[p,q]=[random(2^L), random(2^(L+2))];
p=nextprime(p); while(p%4==3, p=nextprime(p+1));
q=nextprime(q); while(q%4==3, q=nextprime(q+1));
n=p*q;

[x,y]=to_squares_sum(lift(sqrt(Mod(-1,p))),p);
[X,Y]=to_squares_sum(lift(sqrt(Mod(-1,q))),q);
print(x^2+y^2==p && X^2+Y^2==q);

[a,b]=abs(square_sums([x,y,X,Y]));[x,y]=a;[X,Y]=b;
print(x^2+y^2==n && X^2+Y^2==n && #Set([a[1],a[2],b[1],b[2]])==4);

print(x);
print(y);
print(n);
print(#digits(n)," decimal digits semiprime");
quit;
}
pi@raspberrypi5:~/RSA_numbers_factored/1_sum_of_2_sqs_semiprime $


regards,

Hermann.