the algorithm is simple (works with any NxN square if N is odd): start from any cell and travel diagonally counting up to N. (if you end up outside the square anytime during this traversal, "wrap around" to the opposite side as if right connects to left and top connects to bottom.) when you reach N, move one cell orthogonally (ie. left, right, up, down). repeat these actions (diagonal traversal for N cells, orthogonal move for 1 cell) but using the original directions (diagonal, orthogonal) selected at the start.
i've noticed that if you start at the middle of the first row, and travel diagonally north east (to direction of right upper corner) for N cells, then move DOWN one cell and repeat, the magic square will have all columns, rows, and even diagonals add up to the same value.
i'm sure there are tons of "scientific" documents out there on magic squares!