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 / foursquare.cc
Created October 4, 2023 00:13
libgmpxx+libpari code to determine sum of four squares for semiprime p*q with qfsolve()
View foursquare.cc
// 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
View nsum.py
# 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
View rsa_test.gp
\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
View range_client
#!/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
View range_server.py
# 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)
View cado-nfs.loop
#!/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
View wol.js
// 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"
View latest_new_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 ]
@Hermann-SW
Hermann-SW / sqrtm1.smallest_known_1million_digit_prime.cc
Created June 19, 2023 00:10
Only here to investigate "munmap_chunk(): invalid pointer"
View sqrtm1.smallest_known_1million_digit_prime.cc
This file has been truncated, but you can view the full file.
// x,y -> sqrtm1 [-> x,y]
//
// https://t5k.org/primes/lists/all.txt
// 2147 10^999999+308267*10^292000+1 1000000 CH10 2021
//
// f=sqrtm1.smallest_known_1million_digit_prime
//
// either
// g++ $f.cc -lgmp -lgmpxx -O3 -o $f
// or
@Hermann-SW
Hermann-SW / cypari2_.py
Last active June 14, 2023 09:59
Python script for testing making use of cypari2 if available
View cypari2_.py
from sympy import gcd, I
try:
import cypari2
pari = cypari2.Pari()
gen_to_python = cypari2.convert.gen_to_python
except ImportError:
cypari2 = None