Skip to content

Instantly share code, notes, and snippets.

View MurageKibicho's full-sized avatar
🛼
Working from home

Murage Kibicho MurageKibicho

🛼
Working from home
  • Yale University
  • New Haven, Connnecticut
  • 22:33 (UTC -05:00)
View GitHub Profile
@MurageKibicho
MurageKibicho / Eisenstein.c
Created December 6, 2025 12:12
Arithmetic with Eisenstein numbers
//https://github.com/RasmusFL/EisensteinIntegers/blob/main/EisensteinIntegers/eisenstein_integers.cpp
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <stdbool.h>
#include <time.h>
#include <math.h>
#include <gmp.h>
@MurageKibicho
MurageKibicho / GaussReduce.c
Created December 5, 2025 08:08
2D Gaussian lattice reduction
void GaussReduce(fmpz_t x1, fmpz_t y1, fmpz_t x2, fmpz_t y2)
{
//Shortest solution is stored in x1,y1
fmpz_t mu, dot12, dot11, tmp,tmp2,tmp3;
fmpz_init(mu);fmpz_init(tmp2);fmpz_init(tmp3); fmpz_init(dot12); fmpz_init(dot11); fmpz_init(tmp);
int infiniteLoopCheck = 0;
while(1)
{
//mu = round((v1·v2)/(v1·v1))
fmpz_mul(dot12, x1, x2);fmpz_mul(tmp, y1, y2);fmpz_add(dot12, dot12, tmp);
@MurageKibicho
MurageKibicho / Cornacchia.py
Created December 4, 2025 19:31
Cornacchia's algorithm for Gaussian Integers paper
#Complete walkthrough: https://leetarxiv.substack.com/p/computation-of-discrete-logarithms
import sympy as sp
p = sp.Integer("5213619424271520371687014113170182341777563603680354416779")
# Step 1: find root of -2 mod p
r = sp.sqrt_mod(-2, p, all_roots=False) # choose one root
if r is None:
raise ValueError("No solution exists.")
@MurageKibicho
MurageKibicho / Fold.py
Created November 27, 2025 06:02
Folding Bit Tracker
import random
import math
p = 2**256 - 2**32 - 977
def pseudo_mersenne_reduce(x, p):
# Split into high and low 256-bit parts
x_low = x & ((1 << 256) - 1)
x_high = x >> 256
# First fold: add high * (2^32 + 977)
@MurageKibicho
MurageKibicho / Pell.py
Created November 3, 2025 05:42
Pell Curve Finite Field Group Structure
# Self-contained Python script for Pell conic group law check
def pell_add(a, b, D, p):
"""Group law on x^2 - D*y^2 = 1 mod p."""
x1, y1 = a
x2, y2 = b
x3 = (x1 * x2 + D * y1 * y2) % p
y3 = (x1 * y2 + x2 * y1) % p
return x3, y3
@MurageKibicho
MurageKibicho / FMPZ_IndexCalculus.c
Last active October 18, 2025 14:01
Big Integer Index Calculus till RREF using FLINT and LibGMP in C. Needs FLINT 3.4 or greater for fmpz_mod_mat
////Complete walkthrough: https://leetarxiv.substack.com/p/row-reduction-over-finite-fields
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <stdbool.h>
#include <time.h>
#include <math.h>
#include <gmp.h>
@MurageKibicho
MurageKibicho / fmpz.c
Created October 18, 2025 06:14
Flint Code to RREF a matrix
#include <flint/fmpz_mod_mat.h>
#include <flint/fmpz_mod.h>
#include <flint/fmpz.h>
#include <stdio.h>
int main() {
fmpz_t n;
fmpz_init_set_ui(n, 2); // Set modulus to 2
fmpz_mod_ctx_t ctx;
@MurageKibicho
MurageKibicho / SinkhornKnopp.c
Created October 17, 2025 09:06
Sinhorn-Knopp Algorithm with total support checking
//Complete LeetArxiv walkthrough: https://leetarxiv.substack.com/p/sinkhorn-knopp-algorithm
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#include <string.h>
#include <assert.h>
#define INDEX(x, y, cols) ((x) * (cols) + (y))
//clear && gcc SinkhornKnopp.c -lm -o m.o && ./m.o
void PrintSinkhornCode(int sinkhornCode)
@MurageKibicho
MurageKibicho / LUDecomposition.c
Last active October 17, 2025 08:22
Using LU Decomposition in C to find the matrix determinant
//Full walkthrough: https://leetarxiv.substack.com/p/sinkhorn-knopp-algorithm
void PrintMatrix(int rows, int cols, double *matrix)
{
for(int i = 0; i < rows; i++)
{
for(int j = 0; j < cols; j++)
{
double element = matrix[INDEX(i,j, cols)];
printf("%.3f,",element);
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <stdint.h>
#include <assert.h>
#include <math.h>
uint32_t RANGE_LOW = 1;
uint32_t RANGE_HIGH = 0xffffffff;
uint32_t RANGE_CURRENT = 0;