I'm trying to find the modular inverse of 28 mod 45 with the Euclidean algorithm but I'm getting the wrong answer. According to online calculators, the answer is $37$, but I'm getting $42$, here are my steps, where am I messing up? Thanks in advance.
Euclidean algorithm: $$45=28\left(1\right)+17$$
$$28=17\left(1\right)+11$$
$$17=11\left(1\right)+6$$
$$11=6\left(1\right)+5$$
$$6=5\left(1\right)+1$$
Then I rearrange the bottom 3 equations: $$6-5\left(1\right)=1$$ $$11-6\left(1\right)=5$$ $$17-11\left(1\right)=6$$
Substitute for $5$ in the $6-5(1)=1$ equation:
$$6-\left(11-6\left(1\right)\right)\left(1\right)=1$$ $$6-11+6=1$$ $$2(6)+11(-1)=1$$
And finally, substitute the $6$ to get my answer of $42$:
$$2\left(17-11\left(1\right)\right)+11\left(-1\right)=1$$ $$2\left(17\right)+11\left(-3\right)=1$$ $$45-3\ =\ 42$$
I don't know where does the last line come from. From$$2\times17+(-3)\times11=1,$$you should get that$$2\times17+(-3)\times(28-17)=1,$$or$$5\times17-3\times28=1.$$And now$$5\times(45-28)-3\times28=1,$$or$$5\times45-8\times28=1.$$So, the inverse of $28$ mod $45$ is $-8$, or $37$.