How can I compute the sum of products for the broken diagonals?
The following pseudocode will compute the sum of the products for diagonals, under the assumption that the n^2 matrix elements are stored in A[i,j], 1<=i<=n, 1<=j<=n:
sum = 0
for x = 0 to n-1 step 1
product = 1
for y = 0 to n-1 step 1
m = (x+y) modulo n
product = product*A[m+1, y+1]
next y
sum = sum+product
next x
for x=0 to n-1 step 1
product = 1
for y=0 to n-1 step 1
m = n-1-((x+y) modulo n)
product = product*A[m+1, y+1]
next y
sum = sum+product
next x