0
$\begingroup$

I see this page before. Cracking Playfair code And I download the C file in it.However,I am still confused about the code. How to evaluate a solution? What does this mean?

if (diff > 0 || ((float) rand () / RAND_MAX < exp (diff / T))) champion = mysquare; 

And what is the T and the score?

  K->score = (float) digvalue / N;    T *= 0.98; 

Thanks for your help!I am really urgent to know this.

1 Answers 1

2

I didn't look at the rest of the code, but this looks like simulated annealing. T is a temperature parameter that regulates the randomness you allow in the search. The lower T gets, the less likely it is that a step that increases the energy (the function to be minimized) is accepted. The if statement implements the Metropolis algorithm for bringing the system into statistical equilibrium at temperature T.

[Edit in response to the comments:]

There's more stuff in the directory containing the source code, including the input file for digstat (distat.log) and a short explanation (playn.txt) (which by the way would have told you that the code performs simulated annealing). On comparing the input file for digstat with other digram frequency data, it looks like these are natural logarithms of scaled digram frequencies, rounded to integers. (The scaling has no effect on the algorithm since it merely adds a constant to all scores.)

The code you quote computes the part of the Kullback–Leibler divergence that depends on the current key. This is the relative entropy between the digram frequencies corresponding to the current key and the actual English diagram frequencies. The part $\sum p_i\log p_i$ that involves only the actual digram frequencies and doesn't depend on the digram frequencies corresponding to the current key is omitted, since it would cancel out in the energy differences used in the Metropolis algorithm.

  • 0
    Thanks very much!Thanks!With your help,I am acquainted with a great deal of useful knowledge!Thanks again!2011-10-07