Why doesn't this calculation work? I want to find some closed form for $\gcd(x^3+1,3x^2 + 3x  + 1)$ but get $7$ which is not always true.

I prove the gcd $\,d =7\,$ if $\, x = 5\!+\!7n,\,$ else $\,d=1.\,$ First $\,x^3\!+\!1 = (x\!+\!1)h(x),\ h(x) = x^2\!-\!x\!+\!1.\,$  Let $\,g(x) = 3x^2\!+3x+1.\,$ Then  $\,\color{#c00}{(x\!+\!1,g(x))} = (x\!+\!1,g(-1)) = (x+1,1)= \color{#c00}1.\,$ Therefore $\,d = ((\color{#c00}{x\!+\!1})h ,\color{#c00}g) = (h,g) = (h,\, g\ {\rm mod}\ h) = (\color{#0a0}{h,2}(3x\!-\!1))\,$ by $\,x^2\equiv x\!-\!1\,$ mod $\,h.\>$ But $\,2\mid h\!-\!1=x(x-1)
,\, $ so $\ \color{#0a0}{(h,2) = 1},\,$ so $\ d = (h,\ 3x\!-\!1).\,$ Reducing $\,h\,$ mod $\,3x\!-\!1$ we obtain  $\,{\rm mod}\ d\!:\ 0\equiv 9h(x)\equiv 9h(1/3)\equiv 7,\, $ so $\,d\mid 7.\,$ So $\,d\ne 1\iff (h,3x\!-\!1)=7\,$ which is true iff $\,x\equiv -2\equiv 5\pmod 7,\,$  i.e. the common root of $\,3(x\!+\!2)\,$ and $\,h \equiv (x\!+\!2)(x\!-\!3)\,\pmod 7.$
