Converted Q function to matrix multiplication and overall different function from http://www.cse.buffalo.edu/~atri/courses/coding-theory/lectures/lect38.pdf. Not fully operational