Changeset 1754
 Timestamp:
 Aug 3, 2010, 1:32:18 PM (11 years ago)
 Location:
 trunk/CrypPlugins
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

trunk/CrypPlugins/AutokorrelationFunction/AutokorrelationFunction.cs
r1699 r1754 122 122 //START 123 123 //Preparations for the Analyse 124 125 ProgressChanged(0, 1); 126 127 cipher = InputCipher; //initialising the ciphertext 128 cipher = prepareForAnalyse(cipher); //and prepare it for the analyse (> see private methods section) 129 130 ak = new double[cipher.Length]; //initialise ak[]...there are n possible shifts where n is cipher.length 131 132 presentation.histogram.SetBackground(Brushes.Beige); //sets the background colour for the quickwatch 133 presentation.histogram.SetHeadline("Autocorrelation matches"); //sets its title 134 135 // 136 //Analyse 137 // 138 139 //for each possible shift value... 140 for(int t=0; t<cipher.Length; t++) 141 { 142 same=0; 143 144 //...calculate how often the letters match... 145 for(int x=0; x<cipher.Lengtht;x++) 146 { 147 if(cipher[x] == cipher[x+t]) 148 { 149 same++; 150 } 151 } 152 153 try 154 { 155 //...and save the count for the matches at the shift position 156 ak[t] = same; 157 } 158 catch 159 { 160 } 161 } 162 163 data.ValueCollection.Clear(); 164 165 //for all observed shifts... 166 for(int y=1;y<ak.Length;y++) 167 { 168 //find the one with the highest match count... 169 if(ak[y] > probablekorr) 170 { 171 probablekorr = ak[y]; 172 probablelength = y; //...and remember this shift value 173 } 174 } 175 176 //find the top 13 matches... 177 if (ak.Length > 11) 178 { 179 ak = findTopThirteen(ak); 180 } 181 182 for (int y = 1; y < ak.Length; y++) 183 { 184 if (ak[y] > 1) //Adds a bar into the presentation if it is higher then the average matches 185 { 186 bar = new HistogramElement(ak[y], ak[y], "" + y); 187 data.ValueCollection.Add(bar); 188 } 189 } 190 191 presentation.histogram.SetHeadline("Highest match count " + probablekorr + " with shift: " + probablelength); 192 193 if(data != null) 194 { 195 presentation.histogram.ShowData(data); 196 } 197 198 OutputLength = probablelength; //sending the keylength via output 199 OnPropertyChanged("OutputLength"); 200 124 125 if (InputCipher != null) //Starts only if a ciphertext is set 126 { 127 ProgressChanged(0, 1); 128 129 cipher = InputCipher; //initialising the ciphertext 130 cipher = prepareForAnalyse(cipher); //and prepare it for the analyse (> see private methods section) 131 132 ak = new double[cipher.Length]; //initialise ak[]...there are n possible shifts where n is cipher.length 133 134 presentation.histogram.SetBackground(Brushes.Beige); //sets the background colour for the quickwatch 135 presentation.histogram.SetHeadline("Autocorrelation matches"); //sets its title 136 137 // 138 //Analyse 139 // 140 141 //for each possible shift value... 142 for (int t = 0; t < cipher.Length; t++) 143 { 144 same = 0; 145 146 //...calculate how often the letters match... 147 for (int x = 0; x < cipher.Length  t; x++) 148 { 149 if (cipher[x] == cipher[x + t]) 150 { 151 same++; 152 } 153 } 154 155 try 156 { 157 //...and save the count for the matches at the shift position 158 ak[t] = same; 159 } 160 catch 161 { 162 } 163 } 164 165 data.ValueCollection.Clear(); 166 167 //for all observed shifts... 168 for (int y = 1; y < ak.Length; y++) 169 { 170 //find the one with the highest match count... 171 if (ak[y] > probablekorr) 172 { 173 probablekorr = ak[y]; 174 probablelength = y; //...and remember this shift value 175 } 176 } 177 178 //find the top 13 matches... 179 if (ak.Length > 11) 180 { 181 ak = findTopThirteen(ak); 182 } 183 184 for (int y = 1; y < ak.Length; y++) 185 { 186 if (ak[y] > 1) //Adds a bar into the presentation if it is higher then the average matches 187 { 188 bar = new HistogramElement(ak[y], ak[y], "" + y); 189 data.ValueCollection.Add(bar); 190 } 191 } 192 193 presentation.histogram.SetHeadline("Highest match count " + probablekorr + " with shift: " + probablelength); 194 195 if (data != null) 196 { 197 presentation.histogram.ShowData(data); 198 } 199 200 OutputLength = probablelength; //sending the keylength via output 201 OnPropertyChanged("OutputLength"); 202 } 201 203 202 204 
trunk/CrypPlugins/VigenereAutokeyAnalyser/VigenereAutokeyAnalyser.cs
r1683 r1754 171 171 { 172 172 //START 173 //Preparations for the Analyse 174 175 ProgressChanged(0, 1); 176 177 quickWatchPresentation.Clear(); 173 //Preparations for the Analyse 174 175 if (InputCipher != null) 176 { 177 ProgressChanged(0, 1); 178 179 quickWatchPresentation.Clear(); 178 180 179 alphabet = settings.AlphabetSymbols; //initialising the alphabet as given by the user 180 181 if (InputCipher != null) 182 { 183 ciphertext = InputCipher; //initialising the ciphertext 184 ciphertext = prepareForAnalyse(ciphertext); //and prepare it for the analyse (> see private methods section) 185 } 186 187 modus = settings.Modus; //initialise which modus is used 188 language = settings.Language; //initialise which language frequencys are expected 189 finalIC = 0.0; //initialise the highest index of coincidence to be found among all tests 190 191 if (textkorpus != null) //1) if there's a textkorpus given us it to calculate the expected frequency... 192 { // (> see private methods section) 193 textkorpus = prepareForAnalyse(textkorpus); 194 EF = observedFrequency(textkorpus); 195 } 196 else //OR 197 { 198 EF = expectedFrequency(language); //2) just use the expected frequency from the guessed language 199 } // (> see private methods section) 200 181 alphabet = settings.AlphabetSymbols; //initialising the alphabet as given by the user 182 183 ciphertext = InputCipher; //initialising the ciphertext 184 ciphertext = prepareForAnalyse(ciphertext); //and prepare it for the analyse (> see private methods section) 185 186 187 modus = settings.Modus; //initialise which modus is used 188 language = settings.Language; //initialise which language frequencys are expected 189 finalIC = 0.0; //initialise the highest index of coincidence to be found among all tests 190 191 if (textkorpus != null) //1) if there's a textkorpus given us it to calculate the expected frequency... 192 { // (> see private methods section) 193 textkorpus = prepareForAnalyse(textkorpus); 194 EF = observedFrequency(textkorpus); 195 } 196 else //OR 197 { 198 EF = expectedFrequency(language); //2) just use the expected frequency from the guessed language 199 } // (> see private methods section) 201 200 202 201 // … … 204 203 // 205 204 206 207 if (InputKeylength != 0) //1) if the autokorrelation function has provided an assumed 208 { // keylength break the AutokeyCipher with it... 209 lock (this) // IMPORTANT: This is a critical Area and has to be used by only one thread 205 if (InputKeylength != 0) //1) if the autokorrelation function has provided an assumed 206 { // keylength break the AutokeyCipher with it... 207 lock (this) // IMPORTANT: This is a critical Area and has to be used by only one thread 208 { 209 assumedkeylength = InputKeylength; 210 breakVigenereAutoKey(assumedkeylength); 211 } 212 } 213 else //OR 210 214 { 211 assumedkeylength = InputKeylength; 212 breakVigenereAutoKey(assumedkeylength); 213 } 214 } 215 else //OR 216 { 217 maxkeylength = (ciphertext.Length / 40) + 1; //2) Brute force the keylength up to (ciphertext.length / 40) 218 for (int d = 1; d <= maxkeylength; d++) 219 { 220 breakVigenereAutoKey(d); //"BREAK VIGENERE AUTO KEY(KEYLENGTH)" IS THE MAIN METHODE IN FINDING THE KEY FOR A GIVEN KEYLENGTH 221 } //(> see private methods section) 222 } 223 224 quickWatchPresentation.selectIndex((finalkey.Length)  1); 225 226 OutputKey = finalkey; //sending the key via output 227 OnPropertyChanged("OutputKey"); 215 maxkeylength = (ciphertext.Length / 40) + 1; //2) Brute force the keylength up to (ciphertext.length / 40) 216 for (int d = 1; d <= maxkeylength; d++) 217 { 218 breakVigenereAutoKey(d); //"BREAK VIGENERE AUTO KEY(KEYLENGTH)" IS THE MAIN METHODE IN FINDING THE KEY FOR A GIVEN KEYLENGTH 219 } //(> see private methods section) 220 } 221 222 quickWatchPresentation.selectIndex((finalkey.Length)  1); 223 224 OutputKey = finalkey; //sending the key via output 225 OnPropertyChanged("OutputKey"); 226 } 227 228 228 229 229 ProgressChanged(1, 1); 230 230 231 231 } 232 233 232 //EXECUTE END 234 233 … … 332 331 333 332 /// <summary> 334 /// Convert athe letter to an intvalue that resembles his position in the given alphabet333 /// Convert the letter to an intvalue that resembles his position in the given alphabet 335 334 /// </summary> 336 335 private int getPos(char c)
Note: See TracChangeset
for help on using the changeset viewer.