[update]: adapted the symbols S, b and c to the convention in the OP, sign error corrected [/update]
What I get for an orthogonal similarity transformation is (using r for $\small \cos(x) $ and s for $\small \sin(x) $ with some rotation-angle x and $\small S^{-1} \cdot A S $ for the matrix-multiplication
$ \small
\begin{array} {rr|rr}
& & r & s \\
& & -s & r \\
\hline \\
a & b & -s b+ar & rb+as \\
c & d & -sd+cr & rd+cs \\
\hline \\
r & -s & -srb+s^2d+ar^2-csr & r^2b-srd+asr-cs^2 \\
s & r & -s^2 b-srd+cr^2+asr & srb+r^2d+csr+as^2
\end{array} $
Using the abbreviations $\small r_2 = r^2-s^2=\cos(x)^2-\sin(x)^2 = \cos(2 x)$ and $\small s_2 = 2 r s= 2 \cos(x) \sin(x) = \sin(2 x)$ for the angle-duplication then I get for the resulting matrix
$ \small S^{-1} \cdot A \cdot S =
\begin{array} {r|r|}
(a+d)+(a-d)r_2-(b+c)s_2 & (b-c)+(a-d)s_2 + (b+c)r_2 \\
\hline \\
-(b-c) + (a-d)s_2 + (b+c)r_2 & (a+d) - (a-d)r_2 + (b+c)s_2 \\
\end{array} \cdot {1 \over 2} $
Then to have the diagonal-entries equal, the term $\small (b+c)s_2 -(a-d)r_2 $ must be zero.
[update]
The generalization for higher
n seems obvious. Assume the diagonalelements $\small d_1,d_2,d_3 $, then each similarity-rotation on one pair of columns / rows modifies only two of that elements. If we denote one transformation between the columns/rows $\small T_{c_1,c_2} $ and $\small A_{c_1,c_2} = T_{c_1,c_2}^{-1} \cdot A \cdot T_{c_1,c_2} $ then the diagonal-elements behave like this over the iteration of transformations
T :
$\small \begin{array} {rrr}
T_{1,2}: & (d_1+d_2)/2 &, (d_1+d_2)/2 &, d_3 \\
T_{1,3}: & (d_1+d_2)/4+d_3/2 &, (d_1+d_2)/2 &, (d_1+d_2)/4+d_3/2 \\
T_{2,3}: & (d_1+d_2)/4+d_3/2 &, (d_1+d_2)3/8+d_3/4 &,(d_1+d_2)3/8+ d_3/4 \\
\ldots
\end{array} $
and I think this is not too difficult to show, that iterations of this converge.
I've done an example using my (somehow primitive) MatMate-program. But I think the code will be selfexplaining enough to be translated to some other programming language.
[Update 3]: The macro had to be updated to overcome the local-minimum-problem.
We introduce a dynamic selection of the x,y-axes according to the smallest and greatest element in the diagonal of the currently iterated matrix
// Macro definitions
macrodef rotpair // rotates matrix M in one plane (=x,y) using rotation-matrix t1
m1 = t'*m*t // get a temporary working copy
// get values a,b,c,d from submatrix
a,b,c,d = v(m1[x,x]),v(m1[x,y]),v(m1[y,x]),v(m1[y,y])
s_2,c_2 = a - d, b + c // determine cos(2 phi) and sin(2 phi)
phi = -arccs(c_2,s_2)/2 // determine required rotation-angle phi
t1 = rotsp(einh(n),x,y,cos(phi),sin(phi)) // create rotation-matrix
// for one x/y plane-rotation
m2 = t1' * m1 * t1 // do similarity-rotation
t = t*t1 // append current rotation to accumulator
macroend
macrodef init
set randomstart=41
m = (randomu(n,n,-10,10)) // create some randommatrix of size n x n
t = einh(n) // rotation-matrix, accumulates all rotations while iterating
dg = diag(m) ' // get the diag of the initial matrix
protocol = dg // initialize some protocol for the documentation of the
// diagonal elements
macroend
macrodef run // pairwise rotations over all pairs of coordinates
x,y = v(iminzl(dg)), v(imaxzl(dg)) // store indexes of smallest and largest
// diagonal-element into x and y-"coordinates"
macroexec rotpair // do rotation
dg = diag(m2) '
protocol = {protocol, dg} // append current diagonal to protocol
macroend
// commands in dialog:
n=5 // use matrix-size n=5
macroexec init
macroexec run // repeat this until convergence
// commands in dialog:
n=10 // use matrix-size n=10
macroexec init
macroexec run // repeat this until convergence
Results
// result: (n=5 size=5x5)
-4.2684, 7.7193, 3.0452, -0.8330, -9.9136
-4.2684, -1.0972, 3.0452, -0.8330, -1.0972
-0.6116, -1.0972, -0.6116, -0.8330, -1.0972
-0.6116, -0.8544, -0.8544, -0.8330, -1.0972
-0.8544, -0.8544, -0.8544, -0.8330, -0.8544
-0.8544, -0.8437, -0.8544, -0.8437, -0.8544
-0.8544, -0.8490, -0.8544, -0.8437, -0.8490
-0.8490, -0.8490, -0.8544, -0.8490, -0.8490
-0.8490, -0.8490, -0.8517, -0.8490, -0.8517
-0.8490, -0.8490, -0.8504, -0.8504, -0.8517
-0.8504, -0.8490, -0.8504, -0.8504, -0.8504
-0.8504, -0.8497, -0.8504, -0.8497, -0.8504
-0.8504, -0.8497, -0.8504, -0.8500, -0.8500
-0.8500, -0.8500, -0.8504, -0.8500, -0.8500
-0.8500, -0.8500, -0.8502, -0.8500, -0.8502
-0.8501, -0.8500, -0.8501, -0.8500, -0.8502
-0.8501, -0.8501, -0.8501, -0.8500, -0.8501
-0.8501, -0.8501, -0.8501, -0.8501, -0.8501
// result: (n=10 size=10x10, 40 iterations)
-4.2684, 8.0316, 7.0596, -6.1777, 3.5646, -6.5801, 9.0093, 5.8538, 2.9013, -9.6980
-4.2684, 8.0316, 7.0596, -6.1777, 3.5646, -6.5801, -0.3444, 5.8538, 2.9013, -0.3444
-4.2684, 0.7257, 7.0596, -6.1777, 3.5646, 0.7257, -0.3444, 5.8538, 2.9013, -0.3444
-4.2684, 0.7257, 0.4410, 0.4410, 3.5646, 0.7257, -0.3444, 5.8538, 2.9013, -0.3444
...
...
0.9696, 0.9696, 0.9695, 0.9696, 0.9695, 0.9698, 0.9695, 0.9696, 0.9696, 0.9696
0.9696, 0.9696, 0.9696, 0.9696, 0.9695, 0.9696, 0.9695, 0.9696, 0.9696, 0.9696
0.9696, 0.9696, 0.9696, 0.9696, 0.9695, 0.9696, 0.9695, 0.9696, 0.9696, 0.9695
0.9696, 0.9696, 0.9696, 0.9696, 0.9695, 0.9695, 0.9695, 0.9696, 0.9696, 0.9695
[Update 2]:[obsolete, I found a better solution] I tried the same routine simply using n=10 instead of n=5, and with the same initializing of the randomnumber generator, so the solution should be reproducable. Unfortunately the iteration seems to run into a local minimum, such that the process converges to a non-equal solution. Here is the result near the limit:
// result
...
1.6419, 1.6419, 1.6419, 1.6419, 1.6419,-6.5801, 9.0093, 5.8538, 2.9013,-9.6980