Skip to content

Instantly share code, notes, and snippets.

View Hermann-SW's full-sized avatar

Hermann Stamm-Wilbrandt Hermann-SW

View GitHub Profile
@Hermann-SW
Hermann-SW / Kunerth.gp
Last active November 26, 2023 11:35
Kunerth's algorithm from 1878, for determining modular sqrt
assert(b,s)=if(!(b), error(Str(s)));
m=eval(getenv("m"));
b=m.mod;
c=lift(m);
if(ispseudoprime(c),s=sqrt(Mod(-b,c)),issquare(Mod(b,-c),&s));
V=r=lift(s);;
print("V=",r);
@Hermann-SW
Hermann-SW / tqf.gp
Last active February 29, 2024 02:18
Generate ternary quadratic form that represents n and has determinant 1, for determining sum of 3(4) squares for n
assert(b,s)=if(!(b), error(Str(s)));
dbg(a,b,c="")=if(getenv("dbg"),print(a,b,c));
get_tqf(n,vstart)={
assert(n%4!=0);
assert(n%8!=7);
my(Q,v,b,p,a12);
if(n%4==2,
for(vv=vstart,oo,
@Hermann-SW
Hermann-SW / foursquare.cc
Created October 4, 2023 00:13
libgmpxx+libpari code to determine sum of four squares for semiprime p*q with qfsolve()
// p,q -> a,b,c,d with a^2+b^2+c^2+d^2==p*q
//
// f=foursquare
//
// g++ $f.cc -lgmp -lgmpxx -O3 -o $f -lpari -DPARI -Wall -Wextra -pedantic
//
// $ ./$f 999999999999999999999999999989 999999999999999999999999999983
// R = qfsolve(M)
// 2.85703s
// 223605138439657340220247124809 147944036070869714718268156597 314020169936458430849348767399 910771451642793118995923538064
@Hermann-SW
Hermann-SW / nsum.py
Last active September 23, 2023 14:36
Find permutations of numbers 1..N with each successive pair summing to a square
# pylint: disable=C0103, R1728
# invalid-name, consider-using-generator
""" blacked and pylinted; https://mersenneforum.org/showthread.php?t=22915 """
import sys
from sys import argv, stderr
from math import isqrt
N = 15 if len(argv) < 2 else int(argv[1])
a = [[] for i in range(N + 1)]
stop = len(argv) >= 3
@Hermann-SW
Hermann-SW / rsa_test.gp
Last active September 5, 2023 19:33
PARI/GP test script wrt kronecker(), chinese(), and prime factors of rsa numbers
\r RSA_numbers_factored.gp
test(v)=
{
if(#v<4,
break());
my([l,n,p,q]=v,pnr,qnr,sqrtm1);
if ((p%4!=1)||(q%4!=1),
break());
forprime(t=2,oo,
@Hermann-SW
Hermann-SW / range_client
Created August 25, 2023 14:27
client demonstrating working with range_server.py, Cullen prime demo
#!/bin/bash
if [[ "$3" != '' ]]
then
for((i=1; i<=$3; ++i))
do
$0 "$1" "$2" &
done
exit
fi
@Hermann-SW
Hermann-SW / range_server.py
Last active August 25, 2023 14:38
HTTP server: serves numbers in range for multi-host multi-core work distribution
# pylint: disable=C0103 (invalid-name)
"""
python range_server.py port start stop
"""
from socketserver import TCPServer
from http.server import SimpleHTTPRequestHandler
from threading import Thread
from timeit import default_timer
from time import strftime, gmtime
from sys import argv, stdout
@Hermann-SW
Hermann-SW / cado-nfs.loop
Created July 28, 2023 11:55
Simple bash script restarting cado-nfs.py until factorization completes successful (only needed for ARM bug)
#!/bin/bash
p=""
date
echo "======================="
./cado-nfs.py $1
while [ $? -ne 0 ]
do
date
echo "======================="
@Hermann-SW
Hermann-SW / wol.js
Created July 14, 2023 10:13
minimal nodejs code to power on wakeonlan enabled PC with given mac address
// eslinted; send wakeonlan magic packet for mac address defined in m
//
const m = Buffer.from([0x9c, 0x6b, 0x00, 0x15, 0xbd, 0xc2]);
const p = Buffer.concat([Buffer.alloc(6,0xff),m,m,m,m,m,m,m,m,m,m,m,m,m,m,m,m]);
const sock = require('dgram').createSocket('udp4').on('listening', function() {
sock.setBroadcast(true);
sock.send(p, 0, p.length, 9, '255.255.255.255', function() {
sock.close();
});
@Hermann-SW
Hermann-SW / latest_new_primes
Created June 19, 2023 07:50
shows difference for "list of largest 5000 primes"
#!/bin/bash
wget -O /tmp/all.txt https://t5k.org/primes/lists/all.txt 2> /dev/null
if [ ! -f t5k.org_primes_lists_all.txt ]
then
echo "initial download of largest primes list"
cp /tmp/all.txt t5k.org_primes_lists_all.txt
fi
if [ ! -f t5k.org_primes_lists_all.txt.old ]