What is the least value of $k$ for which $B^k = I$? I found the following question in a textbook, and I wasn't able to solve it.

Suppose $A$ and $B$ are two non-singular matrices such that $B \neq I$, $A^6 = I$, and $AB^2 = BA$, then what is the least value of $k$ for which $B^k = I$?

My attempt
We can see that $A^6 = I$, so, I tried to manipulate the second equation to involve $A^6$, so that we can get the identity matrix. But this didn't work, and I ended up getting something of the form, $B^{-1}AB^2 = A$. I wasn't able to reduce it further.
Answer

 The answer is $k = 127$.

 A: If we remove the hypothesis $A^6=I_n$...
Proposition. Let $B\in GL_n(\mathbb{C})$ s.t. $B^2$ and $B$ are similar.
Then, there is a positive integer $k$ s.t. $B^k=I_n+N$ where $N$ is nilpotent.
Proof. Let $\sigma(B)$ be the spectrum of $B$ and $\lambda\in \sigma(B)$. Then $\lambda^2,\lambda^{2^2},\cdots\in\sigma(B)$; it is not difficult to deduce that there is $p\leq n$ s.t. $\lambda^{2^p-1}=1$. Let $k=lcm(2-1,2^2-1,\cdots,2^n-1)$. Then, for every $\lambda\in\sigma(B)$, $\lambda^k=1$ and we are done.
Example. If $n=4$, then $k=lcm(1,3,7,15)=105$.
Remark 1. Of course, if $B$ is diagonalizable, then $B^k=I_n$.
EDIT. Remark 2. We assume $A^6=I$ and we search a couple s.t. the order of $B$ is $63$ (maximal). According to the proof above, necessarily, $n\geq 6$ and, in fact, $6$ is convenient. Indeed, let $a=exp(2i\pi/63)$ and take
$B=diag(a,a^2,a^4,a^8,a^{16},a^{32}),A=[a_{i,j}]$ where $A$ is the permutation defined by: the $a_{i,j}$ are $0$ except $a_{i,i+1}=1,a_{n,1}=1$. Then $A^6=I,ABA^{-1}=B^2$.
A: Let's tackle the more general problem with $A^n=I$. We have
$$
B^2=A^{-1}BA
$$
Therefore
$$
A^{-2}BA^2=A^{-1}(A^{-1}BA)A=A^{-1}B^2A=(A^{-1}BA)^2=B^4=B^{2^2}
$$
By easy induction,
$$
A^{-m}BA^m=B^{2^m}
$$
for every integer $m\ge0$, so, in particular,
$$
B=A^{-n}BA^n=B^{2^n}
$$
and so $B^{2^n-1}=I$.
So certainly $B^{63}=I$.
Note that if $A^2=I$, one would conclude that $B^3=I$. Moreover $B^2=I$ would imply $A=BA$, so $B=I$, which is disallowed. Hence the minimum value for which $B^k$ can be the identity is $3$, certainly not $127$.
Is it possible to find two matrices with these properties? Yes.
Let's work on $3\times 3$ matrices. Consider as $A$ the permutation matrix exchanging rows $1$ and $2$, whereas $B$ is the permutation matrix that sends row $1$ to row $2$, row $2$ to row $3$ and row $3$ to row $1$. Then it's easy to check that $A^{-1}BA=B^2$ and $A^2=I$.
A: $$\begin{array}{rcl}
B &=& BA^6 \\
&=& (BA)A^5 \\
&=& (AB^2)A^5 \\
&=& A(B^2A)A^4 \\
&=& A(B(BA))A^4 \\
&=& A(B(AB^2))A^4 \\
&=& A((BA)B^2)A^4 \\
&=& A(AB^4)A^4 \\
&=& A^2(B^4A)A^3 \\
&=& \cdots \\
&=& A^6B^{64} \\
&=& B^{64}
\end{array}$$
Multiply both sides by $B^{-1}$ (guaranteed to exist because $B$ is non-singular) to give $I=B^{63}$.
A: This is not a complete answer, just some thoughts that might help.
We have $$AB^2=BA\Rightarrow\\ A^6B^2=A^5BA\Rightarrow \\B^2=A^5BA\Rightarrow \\(B^2)^n=(A^5BA)(A^5BA)\dots (A^5BA)\Rightarrow\\B^{2n}=A^5B^nA$$
Now let's assume that the desired minimal value $k$ is even. 
It follows that $k=2n$ for some $n\in \mathbb{N}$ so 
$$B^{2n}=B^k=A^5B^nA=I\Rightarrow\\B^nA=A\Rightarrow \\B^n=I$$
which is a contradiction since $n\lt k$ and $k$ is the smallest value for which $B^k=I$
So $k$ must be odd
We have $$B^{2n}=A^5B^nA\Rightarrow \\B^{2n+1}=A^5B^nAB\Rightarrow\\B^k=A^5B^{\frac{k+1}{2}}AB^{-1}$$
