This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ////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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //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); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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; |
NewerOlder