CoCalc Public FilesTest for Lambda.ipynbOpen with one click!
Author: Tjbim
Views : 30
Description: Code
Compute Environment: Ubuntu 20.04 (Default)
In [1]:
field = GF(3**2, 'g') g = field.gen() R = PolynomialRing(field, "x") points = [(0, 1),(1, g), (g,g), (g+1, g)] newpol = R.lagrange_polynomial(points) newpol
2*x^3 + (2*g + 2)*x^2 + (2*g + 1)*x + 1
In [2]:
# from sage.crypto.sbox import SBox # S = SBox(7, 0, 4, 12, 11, 8, 2, 1, 15, 3, 5, 6, 9, 10, 13, 14) # pol = S.interpolation_polynomial() # pol
(a^2 + a)*x^13 + (a + 1)*x^12 + (a^3 + a + 1)*x^10 + (a^3 + a + 1)*x^9 + (a^3 + a)*x^8 + (a^3 + 1)*x^7 + (a^3 + a^2 + a)*x^6 + x^5 + (a^3 + a^2 + 1)*x^4 + a*x^3 + x + a^2 + a + 1
In [2]:
from sympy import Eq from sympy.abc import x,g from sympy.utilities.lambdify import lambdify f = lambdify([x,g], newpol)
/ext/sage/sage-9.2/local/lib/python3.8/site-packages/sympy/core/sympify.py:383: SymPyDeprecationWarning: String fallback in sympify has been deprecated since SymPy 1.6. Use sympify(str(obj)) or sympy.core.sympify.converter or obj._sympy_ instead. See https://github.com/sympy/sympy/issues/18066 for more info. SymPyDeprecationWarning(
In [3]:
# #Working Function Maker # from sympy.abc import x # from sympy.utilities.lambdify import lambdify, implemented_function # f = implemented_function('f', lambda x: newpol) # lam_f = lambdify(x, f(x))
In [3]:
#GF(2**N) n = int(input()) p = 4 FF.<g> = GF(p**n) FFlist = list(FF) print(FFlist)
--------------------------------------------------------------------------- KeyboardInterrupt Traceback (most recent call last) <ipython-input-3-4d0d8c5ed53a> in <module> 1 #GF(2**N) ----> 2 n = int(input()) 3 p = Integer(4) 4 FF = GF(p**n, names=('g',)); (g,) = FF._first_ngens(1) 5 FFlist = list(FF) /ext/sage/sage-9.2/local/lib/python3.8/site-packages/ipykernel/kernelbase.py in raw_input(self, prompt) 858 "raw_input was called, but this frontend does not support input requests." 859 ) --> 860 return self._input_request(str(prompt), 861 self._parent_ident, 862 self._parent_header, /ext/sage/sage-9.2/local/lib/python3.8/site-packages/ipykernel/kernelbase.py in _input_request(self, prompt, ident, parent, password) 891 except KeyboardInterrupt: 892 # re-raise KeyboardInterrupt, to truncate traceback --> 893 raise KeyboardInterrupt("Interrupted by user") from None 894 else: 895 break KeyboardInterrupt: Interrupted by user
In [8]:
for x in FFlist: print (f(x,g))
1 g g^3 + 1 g^3 + g + 1 g 1 g^2 g^2 + 1 0 g^2 + g + 1 g^3 + g + 1 g + 1 g^3 + g + 1 g^3 + g^2 + g + 1 g^3 + g g
In [ ]: