![]() | 1 | initial version |
If you need to compute $U_n$ efficiently - here is a way:
a=1
b=2
c=3
u0=u1=u2=1. # initial values
x = polygen(QQ)
C = companion_matrix(x^3-a*x^2-b*x-c)
def U(n):
return (vector([u0,u1,u2]) * C^n)[0]
Alternatively you can use LFSR as described at https://doc.sagemath.org/html/en/reference/cryptography/sage/crypto/lfsr.html
![]() | 2 | No.2 Revision |
If you need to compute $U_n$ efficiently - here is a way:
a=1
b=2
c=3
u0=u1=u2=1. # initial values
x = polygen(QQ)
C = companion_matrix(x^3-a*x^2-b*x-c)
def U(n):
return (vector([u0,u1,u2]) * C^n)[0]
Alternatively you can use LFSR as described at https://doc.sagemath.org/html/en/reference/cryptography/sage/crypto/lfsr.html
![]() | 3 | No.3 Revision |
If you need to compute $U_n$ efficiently - here is a way:
a=1
b=2
c=3
u0=u1=u2=1. u0=u1=u2=1 # initial values
x = polygen(QQ)
C = companion_matrix(x^3-a*x^2-b*x-c)
def U(n):
return (vector([u0,u1,u2]) * C^n)[0]
Alternatively you can use LFSR as described at https://doc.sagemath.org/html/en/reference/cryptography/sage/crypto/lfsr.html