diff --git a/generate_initial_irreducible_polynomials.sage b/generate_initial_irreducible_polynomials.sage deleted file mode 100644 index ee8cf2d..0000000 --- a/generate_initial_irreducible_polynomials.sage +++ /dev/null @@ -1,12 +0,0 @@ -F = GF(2) -PR = PolynomialRing(F, 'x') - -max_k = 31 -whitespace = max_k+1 - -for i in range(1, max_k+1): - poly_int = '0b'+ ''.join(map(str, PR.irreducible_element(i).coefficients(sparse=False)[::-1])) - poly_int += ',' - poly_int += ' '*(max_k-i) - print(f' {poly_int}// irreducible polynomial of degree {i}') - diff --git a/generate_random_irreducible_polynomial.sage b/generate_random_irreducible_polynomial.sage deleted file mode 100644 index a938d9a..0000000 --- a/generate_random_irreducible_polynomial.sage +++ /dev/null @@ -1,96 +0,0 @@ -k = 31 -F = GF(2) -E = GF(2^k) -PR = PolynomialRing(F, 'x') -p = PR.irreducible_element(k) - -while(True): - gamma = E.random_element() - if gamma not in F: - break - -# gamma = PR('x^3+x') -# print('0b'+ ''.join(map(str, gamma.coefficients(sparse=False)[::-1]))) - -eqs = [PR(gamma)^i % p for i in range(k+1)] -for eq in eqs: - print(eq) -print() - -eqs = list(map(lambda eq: eq.coefficients(sparse=False) + [0]*(k-eq.degree()-1), eqs)) -for eq in eqs: - print(eq) -print() -eqs = matrix(eqs[::-1]) -print(eqs) -print() -eqs = eqs.transpose() -print(eqs) -print() - -rref = eqs.rref() -print(rref) -irrpol = PR(rref[:,-1].list() + [1]) -print(irrpol) -print(irrpol.is_irreducible()) -print() - -# manual rref -def calc_rref_Z2(A, m, n): - """Calculate the reduced row echelon form of a (mxn)-matrix""" - A = copy(A) - - # calculate row echelon form - # https://en.wikipedia.org/wiki/Gaussian_elimination#Pseudocode - h = 0 # Initialization of the pivot row - k = 0 # Initialization of the pivot column - - while h < m and k < n: - # Find the k-th pivot: - i_max = -1 - for i in range(h, m): - if A[i,k] == 1: - i_max = i - break - - if i_max == -1: - # No pivot in this column, pass to next column - k += 1 - else: - tmp = A[i_max, :] - A[i_max, :] = A[h, :] - A[h, :] = tmp - - - # Do for all rows below pivot: - for i in range(h+1, m): - f = A[i][k]; - if f == 0: - continue; - A[i, k] = 0; - for j in range(k+1, n): - A[i, j] = A[i, j] - A[h, j] - - # Increase pivot row and column - h += 1 - k += 1 - - # perform back substitution - for i in range(1, m): - for j in range(i): - if A[j, i] == 1: - A[j, :] -= A[i, :] - - return A - -print('Manual RREF:\n') - -rref = calc_rref_Z2(eqs, k, k+1) # cols = rows+1, since we transposed the matrix -print(rref) -print() -irrpol = PR(rref[:,-1].list() + [1]) -print(irrpol) -print(irrpol.is_irreducible()) -print() - -print('0b'+ ''.join(map(str, irrpol.coefficients(sparse=False)[::-1]))) diff --git a/ex53.cpp b/helper_code/ex53.cpp similarity index 100% rename from ex53.cpp rename to helper_code/ex53.cpp diff --git a/fagprojekt_code/Makefile b/helper_code/fagprojekt_code/Makefile similarity index 100% rename from fagprojekt_code/Makefile rename to helper_code/fagprojekt_code/Makefile diff --git a/fagprojekt_code/ascii_to_bits.cpp b/helper_code/fagprojekt_code/ascii_to_bits.cpp similarity index 100% rename from fagprojekt_code/ascii_to_bits.cpp rename to helper_code/fagprojekt_code/ascii_to_bits.cpp diff --git a/fagprojekt_code/eq17.cpp b/helper_code/fagprojekt_code/eq17.cpp similarity index 100% rename from fagprojekt_code/eq17.cpp rename to helper_code/fagprojekt_code/eq17.cpp diff --git a/fagprojekt_code/ex53.cpp b/helper_code/fagprojekt_code/ex53.cpp similarity index 100% rename from fagprojekt_code/ex53.cpp rename to helper_code/fagprojekt_code/ex53.cpp diff --git a/fagprojekt_code/fast_modulo.cpp b/helper_code/fagprojekt_code/fast_modulo.cpp similarity index 100% rename from fagprojekt_code/fast_modulo.cpp rename to helper_code/fagprojekt_code/fast_modulo.cpp diff --git a/fagprojekt_code/hash_table.cpp b/helper_code/fagprojekt_code/hash_table.cpp similarity index 100% rename from fagprojekt_code/hash_table.cpp rename to helper_code/fagprojekt_code/hash_table.cpp diff --git a/fagprojekt_code/hash_table.hpp b/helper_code/fagprojekt_code/hash_table.hpp similarity index 100% rename from fagprojekt_code/hash_table.hpp rename to helper_code/fagprojekt_code/hash_table.hpp diff --git a/fagprojekt_code/hashed_string.cpp b/helper_code/fagprojekt_code/hashed_string.cpp similarity index 100% rename from fagprojekt_code/hashed_string.cpp rename to helper_code/fagprojekt_code/hashed_string.cpp diff --git a/fagprojekt_code/hashed_string.hpp b/helper_code/fagprojekt_code/hashed_string.hpp similarity index 100% rename from fagprojekt_code/hashed_string.hpp rename to helper_code/fagprojekt_code/hashed_string.hpp diff --git a/fagprojekt_code/hashing_algorithms.cpp b/helper_code/fagprojekt_code/hashing_algorithms.cpp similarity index 100% rename from fagprojekt_code/hashing_algorithms.cpp rename to helper_code/fagprojekt_code/hashing_algorithms.cpp diff --git a/fagprojekt_code/hashing_algorithms.hpp b/helper_code/fagprojekt_code/hashing_algorithms.hpp similarity index 100% rename from fagprojekt_code/hashing_algorithms.hpp rename to helper_code/fagprojekt_code/hashing_algorithms.hpp diff --git a/fagprojekt_code/hashing_speed_comparisons.cpp b/helper_code/fagprojekt_code/hashing_speed_comparisons.cpp similarity index 100% rename from fagprojekt_code/hashing_speed_comparisons.cpp rename to helper_code/fagprojekt_code/hashing_speed_comparisons.cpp diff --git a/multiply_polynomials_modulo_polynomial.sage b/multiply_polynomials_modulo_polynomial.sage deleted file mode 100644 index f35a9e0..0000000 --- a/multiply_polynomials_modulo_polynomial.sage +++ /dev/null @@ -1,68 +0,0 @@ -import math - -k = 31 -F = GF(2) -var = 'x' -PR = PolynomialRing(F, var) -p = PR.irreducible_element(k) -gamma = PR.random_element(k) - -exp = 10 -target = gamma^exp % p - -def polynomial_power_in_Z2(q, exp, p, var): - if exp == 0: - return 1 - - if q.degree() == p.degree(): - q += p - - res = q - - for i in range(2, exp+1): - res = multiply_polynomials_in_Z2(res, q, p, var) - - return res - -def polynomial_power_in_Z2_V2(q, exp, p, var): - if exp == 0: - return 1 - - if q.degree() == p.degree(): - q += p - - log2deg = math.floor(math.log2(exp)) + 1 - arr = [0]*log2deg - arr[0] = q - for i in range(1, log2deg): - arr[i] = multiply_polynomials_in_Z2(arr[i-1], arr[i-1], p, var) - - res = PR(1) - for i, b in enumerate(bin(exp)[:1:-1]): - if b == '1': - res = multiply_polynomials_in_Z2(res, arr[i], p, var) - - return res - - -def multiply_polynomials_in_Z2(q1, q2, p, var): - if q1.degree() > p.degree(): - raise ValueError('Unsupported!') - - if q1.degree() == p.degree(): - q1 += p - - arr = [0]*(q2.degree()+1) - arr[0] = q1 - for i in range(1, q2.degree()+1): - arr[i] = arr[i-1]*PR(var) - if arr[i].degree() == p.degree(): - arr[i] += p - - return sum(arr[i] for i in q2.exponents()) - -print(target) -res = polynomial_power_in_Z2(gamma, exp, p, var) -print(res) -res = polynomial_power_in_Z2_V2(gamma, exp, p, var) -print(res) diff --git a/hash_function_library.cpp b/to_be_rewritten_bin/hash_function_library.cpp similarity index 100% rename from hash_function_library.cpp rename to to_be_rewritten_bin/hash_function_library.cpp diff --git a/hash_function_library.hpp b/to_be_rewritten_bin/hash_function_library.hpp similarity index 100% rename from hash_function_library.hpp rename to to_be_rewritten_bin/hash_function_library.hpp diff --git a/porat-porat.cpp b/to_be_rewritten_bin/porat-porat.cpp similarity index 100% rename from porat-porat.cpp rename to to_be_rewritten_bin/porat-porat.cpp