''what is k doing here? or in the other loop''
May be i should explain the background. The user can enter number of input and output in the range of 2 to 64 maximum. So the total number of input will be divided to 8 bits block by block. This is the function of k(8 loop maximum).
''this assignment has different widths ?'' The out_reg
has 8 bits. however the number of bits assign to out_reg is depends on the formula.
for example
total number of input is 12 bits.
so, out_reg[0] has 8 bit(MSB)
then the remaining of 4 bits will be the LSB of out_reg[1](out_reg[1] has 8 bits too_