예제 #1
0
 private double eval(ADFGVX key)
 {
     threadingHelper.decryptions[taskId - 1]++;
     allPlain.length = 0;
     foreach (ADFGVXVector cipher in ciphers)
     {
         key.decode(cipher, interimCipher, plain);
         allPlain.append(plain);
     }
     allPlain.stats();
     return(6000.0 * allPlain.IoC1 + 180000.0 * allPlain.IoC2);
 }
예제 #2
0
 private void printIfBest(ADFGVX key, int cycles, int step, double score, double temp, int deviation)
 {
     lock (threadingHelper.bestOverallLock)
     {
         if (score > threadingHelper.bestOverall)
         {
             threadingHelper.bestOverall = score;
             analyzer.AddNewBestListEntry(Math.Round(threadingHelper.bestOverall, 0),
                                          Math.Round(allPlain.IoC1, 2), Math.Round(allPlain.IoC2, 2), key.transpositionKey.ToString(), allPlain.ToString());
             if (allPlain.IoC1 >= IndexOfCoinzidenz.Getlanguage(language) * ((float)(100 - deviation) / 100))
             {
                 analyzer.TranspositionResult = allPlain.ToString();
             }
             analyzer.Transpositionkey = key.transpositionKey.ToString();
             analyzer.LogText         += Environment.NewLine + "Task: " + taskId + Environment.NewLine + "cycle: " + cycles +
                                         Environment.NewLine + "temp: " + temp + Environment.NewLine + "trans key: " + key.transpositionKey +
                                         Environment.NewLine + "bestOverall: " + threadingHelper.bestOverall +
                                         Environment.NewLine + "IoC1 and IoC2: " + allPlain.IoC1 + " " + allPlain.IoC2;
         }
     }
 }
예제 #3
0
        public void SANgramsIC()
        {
            AlphabetVector keepTranspositionKey = new AlphabetVector(keyLength, false);
            AlphabetVector newTranspositionKey  = new AlphabetVector(keyLength, false);

            ADFGVX key = new ADFGVX("", keyLength);
            TranspositionTransformations transforms = new TranspositionTransformations(keyLength, true, true, true);

            for (int cycles = 1; cycles <= restarts; cycles++)
            {
                if (cycles % 10 == 0)
                {
                    analyzer.LogText += Environment.NewLine + "Task id: " + taskId + " starting with cycle: " + cycles;
                }
                key.randomTranspositionKey();
                double score = eval(key);

                double startTemp = 500.0;
                double endTemp   = 20.0;
                double delta     = 20.0;

                double temp = startTemp;
                for (int step = 0; temp >= endTemp; step++, temp -= delta)
                {
                    transforms.randomize();
                    int size = transforms.size();

                    for (int i = 0; i < size; i++)
                    {
                        keepTranspositionKey.copy(key.transpositionKey);
                        transforms.transform(keepTranspositionKey.TextInInt, newTranspositionKey.TextInInt, keyLength, i);
                        key.setTranspositionKey(newTranspositionKey);
                        double newScore = eval(key);
                        if (SimulatedAnnealing.accept(newScore, score, temp))
                        {
                            score = newScore;
                            if (score > threadingHelper.bestOverall)
                            {
                                printIfBest(key, cycles, step, score, temp, deviation);
                            }
                        }
                        else
                        {
                            key.setTranspositionKey(keepTranspositionKey);
                        }
                    }
                    // Update PresentationView
                    long alldecryptions = 0;
                    lock (threadingHelper.decryptionsLock)
                    {
                        foreach (long d in threadingHelper.decryptions)
                        {
                            alldecryptions += d;
                        }
                        threadingHelper.UpdateDisplayEnd(keyLength, alldecryptions, restarts * (long)(startTemp / delta) * size + restarts);
                    }
                }
            }

            //log.LogText("Task " + taskId + " Fertig", Logtype.Info);
        }