Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

Code

Project: SAC
Views: 185
Image: ubuntu2004
Kernel: SageMath 9.2
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
# 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
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(
f(g,g)

2g3+g2(2g+2)+g(2g+1)+1\displaystyle 2 g^{3} + g^{2} \left(2 g + 2\right) + g \left(2 g + 1\right) + 1

#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)) lam_f(g)

gx6+gx4+x5+x3(g2+g+1)+x2(g+1)+x(g+1)\displaystyle g x^{6} + g x^{4} + x^{5} + x^{3} \left(g^{2} + g + 1\right) + x^{2} \left(g + 1\right) + x \left(g + 1\right)

#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
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