Last week while implementing a crypto-cipher algorithm, I came across a common operation that new-comers may find confusing.
In combinatorial mathematics, a circular shift is the operation of rearranging the entries in a tuple, either by moving the final entry to the first position, while shifting all other entries to the next position, or by performing the inverse operation.
As an operation, it is pretty easy to understand and implement, but most examples are on a single row matrix. When someone reads the definition carefully, there is no chance to misunderstand. But most students rely on examples and this may be a problem when it comes to 2D matrices.
![]()
So, I will explain how its done, in case someone finds it useful in the future.
We have the matrix named “A”. And “As”, which is the left shifted “A”.
A=[1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12]
then
As=[2, 3, 4, 5,
6, 7, 8, 9,
10, 11, 12, 1]
Pay attention on how the last elements in row move on the previous one.