Problems with calculating inverse of finite field $GF(2^8)$ of AES I know this question is being asked to death here but please hear me out.
I was learning how to encrypt using AES and in one of the methods, we have to calculate multiplicative inverse in the finite field $\operatorname{GF}(2^8)$ to make $S-box$.
I learned finite fields and its operations but while calculating the inverse of $x^7+x+1$(83 in hex) with $\bmod x^8+x^4+x^3+x+1$(standard for AES).
Here my calculations using extended Euclidean algorithm:
\begin{align}
(x^8+x^4+x^3+x+1) &amp;= (x^7+x+1)(x) + (x^4+x^3+x^2+1)\\
(x^7+x+1) &amp;= (x^4+x^3+x^2+1)(x^3+x^2+1) + (x)\\
(x^4+x^3+x^2+1) &amp;= (x)(x^3+x^2+x) + 1\\
\end{align}
now calculating $s$ and $t$ for $$(x^8+x^4+x^3+x+1) \cdot s + (x^7+x+1)\cdot t = 1$$

let $a = x^8+x^4+x^3+x+1$,
$b = x^7+x+1$,
$c = x^4+x^3+x^2+1$,
$d = x$

$$c + d(x^3+x^2+x) = 1$$
$$c + (x^3+x^2+x)(b + c(x^3+x^2+1)) = 1$$
$$c + (x^3+x^2+x)b + (x^6+x^4+x^3+x^2)c = 1$$
$$(x^3+x^2+x)b + (x^6+x^4+x^3+x^2+1)c = 1$$
$$(x^3+x^2+x)b + (x^6+x^4+x^3+x^2+1)(a + b(x)) = 1$$
$$(x^3+x^2+x)b + (x^6+x^4+x^3+x^2+1)a + (x^7+x^5+x^4+x^3+x)b$$
$$(x^6+x^4+x^3+x^2+1)a + (x^7+x^5+x^4+x^2)b$$
now, (c inverse)
$$c^{-1} = t* \mod a$$
$$c^{-1} = t$$
$$=x^7+x^5+x^4+x^2$$
that is in hex = B4
which is not what this table shows
http://tratliff.webspace.wheatoncollege.edu/2016_Fall/math202/inclass/sep21_inclass.pdf
the inverse should be 80(hex).
While I was trying different values, I found that the values which are two steps or less in
Extended Euclidean algorithm is correct means when it takes more than 2 steps I am getting different values of course I may be just mistaken here but this is what I know.
Ps:- I am trying to solve this mystery for 3 days now so any help is appreciated thank you
Let $g(x) = (x^8+x^4+x^3+x+1)$ and $p(x) = (x^7+x+1)$
The GCD is correct and it is $1$ as the last non zero remainders.
\begin{align}
(x^8+x^4+x^3+x+1) &amp;= (x^7+x+1)(x) + \color{blue}{(x^4+x^3+x^2+1)}\\
(x^7+x+1) &amp;= (x^3+x^2+1)\color{blue}{(x^4+x^3+x^2+1)} + \color{red}{(x)}\\
(x^4+x^3+x^2+1) &amp;= (x^3+x^2+x)\color{red}{(x)} + 1\\
\end{align}
Now collect back to find to reach Bézout's identity $$a(x)g(x) + b(x)p(x) = d(x)$$ where $d(x)$ is the $\gcd(p(x),g(x))$
and we want to keep $g(x) $ and $p(x)$

begin from the last equation ( the last one that has non-zero remainder)
$$(x^4+x^3+x^2+1) =  (x^3+x^2+x) \color{red}{(x)} + 1$$  change to  (in $GF(2)$ we have $-1=1$)
$$1 = (x^4+x^3+x^2+1) + (x^3+x^2+x)  \color{red}{(x)}$$

Now substitute $\color{red}{(x)}$ from the previous
$$(x^7+x+1) = (x^3+x^2+1)\color{blue}{(x^4+x^3+x^2+1)} + \color{red}{(x)}$$
that is
$$\color{red}{(x)} = p(x) + (x^3+x^2+1)\color{blue}{(x^4+x^3+x^2+1)}$$
now substitute
\begin{align}
1 &amp;= \color{blue}{(x^4+x^3+x^2+1)}) + (x^3+x^2+x)\big[(p(x) + (x^3+x^2+1)\color{blue}{(x^4+x^3+x^2+1)}\big]\\
  1 &amp;= \color{blue}{(x^4+x^3+x^2+1)}) + (x^3+x^2+x)p(x) + (x^6 + x^2 + x)\color{blue}{(x^4+x^3+x^2+1)})\\
1 &amp;= (x^3+x^2+x)p(x) + (x^6 + x^2 + x +1)\color{blue}{(x^4+x^3+x^2+1)})\\
\end{align}

Now substitute $\color{blue}{(x^4+x^3+x^2+1)}$ from the first equation
$$g(x) = p(x)(x) + \color{blue}{(x^4+x^3+x^2+1)}$$
$$\color{blue}{(x^4+x^3+x^2+1)} = p(x)(x) + g(x)$$
\begin{align}
1 &amp;= (x^3+x^2+x)p(x) + (x^6 + x^2 + x +1) \big[p(x)(x) + g(x)\big]\\
1 &amp;= (x^3+x^2+x)p(x) + (x^7 + x^3 + x^2 + x) p(x) + (x^6 + x^2 + x+1) g(x))\\
1 &amp;= (x^7 ) p(x) + (x^6 + x^2 + x) g(x))\\
\end{align}
Now that modulo $g(x)$ of both sides
$$1 = (x^7 ) p(x) $$ and this implies inverse of $p(x)^{-1} = x^7$

Note: for the field calculations I've used a Sagemath code as below, and this can be used for AES calculations.
#Base field
R.&lt;y&gt; = PolynomialRing(GF(2), 'y')

#Defining polynomial
G = y^8+y^4+y^3+y+1

#The field extension
S.&lt;x&gt; = QuotientRing(R, R.ideal(G))
S.is_field()

#this is zero
X = x^8+x^4+x^3+x+1
print(X)

#GCD
print(X.gcd(x^7+x+1))
#to find and inverse use the 1/
1/(x^7+x+1)
#field calculations
(x^3+x^2+1)* (x^4+x^3+x^2+1) + (x)