Loading src/bignum.c +26 −0 Original line number Diff line number Diff line #include <stdlib.h> #include <stdio.h> #include <gmp.h> typedef mpz_t* bignum_t; Loading @@ -15,6 +16,13 @@ bignum_t bignum_from_int(int n){ return x; } bignum_t bignum_from_str(char* s, int base){ bignum_t x = (bignum_t) malloc(sizeof(mpz_t)); mpz_set_str(*x, s, base); return x; } bignum_t bignum_copy(bignum_t x){ bignum_t y = bignum_zero(); mpz_set(*y, *x); Loading Loading @@ -91,6 +99,24 @@ bignum_t bignum_pow(bignum_t x, bignum_t exp){ return z; } bignum_t bignum_gcd(bignum_t a, bignum_t b){ bignum_t g = bignum_zero(); mpz_gcd(*g, *a, *b); return g; } bignum_t bignum_from_MD5(unsigned char* md5sum, size_t len){ char s[100]; size_t r = 0; bignum_t res = bignum_zero(); for(size_t i = 0; i < len; i++) r = r + sprintf(s+r, "%x", md5sum[i]); mpz_set_str(*res, s, 16); return res; } char* bignum_to_str(bignum_t x){ return mpz_get_str(NULL, 10, *x); } src/bignum.h +5 −0 Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ typedef mpz_t* bignum_t; bignum_t bignum_zero(); bignum_t bignum_from_int(int); bignum_t bignum_from_str(char*, int); bignum_t bignum_copy(bignum_t); void bignum_destroy(bignum_t); Loading @@ -24,5 +25,9 @@ bignum_t bignum_mod(bignum_t, bignum_t); bignum_t bignum_powm(bignum_t, bignum_t, bignum_t); bignum_t bignum_pow(bignum_t, bignum_t); bignum_t bignum_gcd(bignum_t, bignum_t); bignum_t bignum_from_MD5(unsigned char* md5sum, size_t len); char* bignum_to_str(bignum_t); #endif src/bst.cdeleted 100644 → 0 +0 −33 Original line number Diff line number Diff line struct node_t { unsigned long int key; void* val; struct node_t* left; struct node_t* right; }; typedef struct bst_t { // Use this to compute a key from a val // It is not really a hash function, the key must be unique unsigned long int (*h)(void*); unsigned long int size; struct node_t* tree; } bst_t; bst_t bst_empty(void){ } int bst_is_empty(bst_t t){ } bst_t bst_add(bst_t t, void* x){ } void bst_destroy(bst_t t, void (*free_void)(void*)){ } int bst_in(bst_t t, void* x){ } unsigned long int bst_size(bst_t t){ } src/bst.hdeleted 100644 → 0 +0 −24 Original line number Diff line number Diff line #ifndef __BST__ #define __BST__ struct node_t { unsigned long int key; void* val; struct node_t* left; struct node_t* right; }; typedef struct bst_t { unsigned long int size; struct node_t* tree; } bst_t; unsigned long int hash(void*); bst_t bst_empty(void); int bst_is_empty(bst_t); bst_t bst_add(bst_t, void*); void bst_destroy(bst_t, void (*free_void)(void*)); int bst_in(bst_t, void*); unsigned long int bst_size(bst_t); #endif src/hash_tbl.c +1 −1 Original line number Diff line number Diff line #include <stddef.h> #include <stdlib.h> #include "list.h" #define ARRAY_CAPACITY 1 << 16 Loading Loading
src/bignum.c +26 −0 Original line number Diff line number Diff line #include <stdlib.h> #include <stdio.h> #include <gmp.h> typedef mpz_t* bignum_t; Loading @@ -15,6 +16,13 @@ bignum_t bignum_from_int(int n){ return x; } bignum_t bignum_from_str(char* s, int base){ bignum_t x = (bignum_t) malloc(sizeof(mpz_t)); mpz_set_str(*x, s, base); return x; } bignum_t bignum_copy(bignum_t x){ bignum_t y = bignum_zero(); mpz_set(*y, *x); Loading Loading @@ -91,6 +99,24 @@ bignum_t bignum_pow(bignum_t x, bignum_t exp){ return z; } bignum_t bignum_gcd(bignum_t a, bignum_t b){ bignum_t g = bignum_zero(); mpz_gcd(*g, *a, *b); return g; } bignum_t bignum_from_MD5(unsigned char* md5sum, size_t len){ char s[100]; size_t r = 0; bignum_t res = bignum_zero(); for(size_t i = 0; i < len; i++) r = r + sprintf(s+r, "%x", md5sum[i]); mpz_set_str(*res, s, 16); return res; } char* bignum_to_str(bignum_t x){ return mpz_get_str(NULL, 10, *x); }
src/bignum.h +5 −0 Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ typedef mpz_t* bignum_t; bignum_t bignum_zero(); bignum_t bignum_from_int(int); bignum_t bignum_from_str(char*, int); bignum_t bignum_copy(bignum_t); void bignum_destroy(bignum_t); Loading @@ -24,5 +25,9 @@ bignum_t bignum_mod(bignum_t, bignum_t); bignum_t bignum_powm(bignum_t, bignum_t, bignum_t); bignum_t bignum_pow(bignum_t, bignum_t); bignum_t bignum_gcd(bignum_t, bignum_t); bignum_t bignum_from_MD5(unsigned char* md5sum, size_t len); char* bignum_to_str(bignum_t); #endif
src/bst.cdeleted 100644 → 0 +0 −33 Original line number Diff line number Diff line struct node_t { unsigned long int key; void* val; struct node_t* left; struct node_t* right; }; typedef struct bst_t { // Use this to compute a key from a val // It is not really a hash function, the key must be unique unsigned long int (*h)(void*); unsigned long int size; struct node_t* tree; } bst_t; bst_t bst_empty(void){ } int bst_is_empty(bst_t t){ } bst_t bst_add(bst_t t, void* x){ } void bst_destroy(bst_t t, void (*free_void)(void*)){ } int bst_in(bst_t t, void* x){ } unsigned long int bst_size(bst_t t){ }
src/bst.hdeleted 100644 → 0 +0 −24 Original line number Diff line number Diff line #ifndef __BST__ #define __BST__ struct node_t { unsigned long int key; void* val; struct node_t* left; struct node_t* right; }; typedef struct bst_t { unsigned long int size; struct node_t* tree; } bst_t; unsigned long int hash(void*); bst_t bst_empty(void); int bst_is_empty(bst_t); bst_t bst_add(bst_t, void*); void bst_destroy(bst_t, void (*free_void)(void*)); int bst_in(bst_t, void*); unsigned long int bst_size(bst_t); #endif
src/hash_tbl.c +1 −1 Original line number Diff line number Diff line #include <stddef.h> #include <stdlib.h> #include "list.h" #define ARRAY_CAPACITY 1 << 16 Loading