The middle-square method Introduction
The middle-square method is used for the generation of pseudorandom numbers. However, this is not a good method in practice, since its period is usually very short and has some severe weaknesses. How does this work? Let's take an example:
For the seed, we pick 123456:
Seed     123456

The seed squared (seed × seed), is equal to:
Seed²  15241383936

We started with a 6-digit number. That means that the seed squared should deliver a 12-digit number. If this is not the case, leading zeroes are added to compensate:
Seed²  015241383936

We then take the middle part of the number, with the same size as the seed:
Seed²  015241383936
          ^^^^^^

This is then our new seed: 241383. We repeat the same process as shown above. We get the following:
0:     123456
    015241383936
       |    |
1:     241383
    058265752689
       |    |
2:     265752
    070624125504
       |    |
3:     624125
    389532015625
       |    |
4:     532015
    283039960225
       |    |
5:     039960
    001596801600
       |    |
6:     596801

And this keeps on in a while... Now we know what the middle-square method is, let's get to the challenge:

The Task
Every seed has a period. The period of a n-digit seed cannot be longer than 8n. For example, the seed 82. This would give the following sequence:
82 &gt; 72 &gt; 18 &gt; 32 &gt; 02 &gt; 00 &gt; 00 &gt; 00 &gt; 00 &gt; 00
|____|____|____|____|____|____|____|____|____|___...
0    1    2    3    4    5    6    7    8    9

You can see that the period is equal to 5, before containing the same digit again. Your task is, when given a seed greater than 0 containing no leading zeroes, output the period of the seed. So, in this case, you need to output 5.
Another example is: 24, which gives the following:
24 &gt; 57 &gt; 24
|____|____|___...
0    1    2

As you can see, not all sequences end in 0. This cycle has a period of 1.

Test cases
Input   &gt;   Output
24      &gt;   1
82      &gt;   5
123456  &gt;   146
8989    &gt;   68
789987  &gt;   226

The pastebins with the sequences for 123456, 8989, 789987
This is code-golf, so the submission with the least amount of bytes wins!
You can assume that the input will never have an uneven number of digits.
Pure bash, 162 131 116 113 107

Saved 3 bytes by using $c...

Thanks @Dennis for help me to save 6 more bytes.

---- begin middleSquare ----

for((b=$1;i[c=10#$b]&lt;2;)){ a=${#b}
printf -v b %0$[a*2]d $[c*c]
b=${b:a/2:a};((i[10#$b]++))
};echo ${#i[@]}


---- end middleSquare ----

for testCase in 24 82 123456 8989 789987 111111;do
    printf "%12s: " $testCase
    bash middleSquare $testCase
  done
          24: 2
          82: 5
      123456: 146
        8989: 68
      789987: 226
      111111: 374


Square formated, 131

---- begin middleSquare ----

for((b=$1;i[
10#$b]&lt;2;1))
do a="${#b}" 
printf -v b\
 %0$[a*2]d \
$[10#$b**2];
b=${b:a/2:a}
((i[10#$b]++
));done;ech\
o ${#i[@]:0}


---- end middleSquare ----

for testCase in 24 82 123456 8989 789987 111111;do
    printf "%12s: %9d\n" $testCase $(
        bash middleSquare $testCase)
  done
          24:         2
          82:         5
      123456:       146
        8989:        68
      789987:       226
      111111:       374


Old but with fancy output, 162

---- begin middleSquare ----

for((b=$1;i[10#$b
]&lt;2;1))do a=${#b}
printf -v b %0$[a
*2]d  $[10#$b**2]
b=${b:a/2:a};((i[
10#$b]++));print\
f "%9d %s\n" ${#\
i[@]} $b;done;ec\
ho -- ${#i[@]} --


---- end middleSquare ----

bash middleSquare 24
        1 57
        2 24
        2 57
-- 2 --

for testCase in 24 82 123456 8989 789987 111111
    do while read f v f
        do r=$v;done &lt; &lt;(
        bash middleSquare $testCase)
    printf "%12s: %11d\n" $testCase $r
  done
          24:           2
          82:           5
      123456:         146
        8989:          68
      789987:         226
      111111:         374