Changeset 1204


Ignore:
Timestamp:
Feb 26, 2010, 5:37:21 PM (12 years ago)
Author:
Sven Rech
Message:

small cost function entropy optimization

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/CostFunction/CostFunction.cs

    r1176 r1204  
    425425
    426426            int[] n = new int[256];
    427             //count all ASCII symbols
    428             int counter = 0;
    429             foreach (byte b in text)
    430             {
    431                 n[b]++;
    432                 counter++;
    433                 if (counter == bytesToUse)
    434                     break;
     427            //count all ASCII symbols
     428            for (int counter = 0; counter < bytesToUse; counter++)
     429            {
     430                n[text[counter]]++;
    435431            }
    436432
    437433            double entropy = 0;
    438434            //calculate probabilities and sum entropy
    439             for (int i = 0; i < n.Length; i++)
     435            for (int i = 0; i < 256; i++)
    440436                entropy += xlogx[n[i]];
    441437
Note: See TracChangeset for help on using the changeset viewer.