At last I wrote this small script in Magma; let $\deg(f)=k$.

```
for i in [k..m] do
if Gcd(f,x^i-1) eq f then
print i;
end if;
end for;
```

This works fine for small $k$: write in place of $'m'$ here, the following;
if $f=f_1.f_2...f_t$ for each $f_j$ being irreducible factors of $f$, then $m=q^{(\operatorname{lcm}({\deg f_j}))}-1$, which will be exactly the place where $f$ splits.

See this example;

```
> F<x>:=PolynomialRing(GF(3));
> f:= x^7-1-x^2-x^3;
> for i in [7..728] do
for> if Gcd(f1,x^i-1) eq f1 then
for|if> print i;
for|if> end if;
for> end for;`
104
208
312
416
520
624
728
```

If you also desire the condition that $\deg(f)$ divides $n$, then you should do;

```
for i in [k..m] do
if Gcd(f,x^i-1) eq f
and Gcd(k,i) eq k then
print i;
end if;
end for;
```

For the above example this gives the result $728$.

But for larger $k$'s, the algorithm needs much time..