public SubstitutionCipher getSolution(QuadGramLikelihoods likelihoods) { SubstitutionCipher randCipher = new SubstitutionCipher(this.ciphertext); double probability = randCipher.getScore(likelihoods); for(int i = 0; i < 10000; i++){ SubstitutionCipher newRandCipher = randCipher.randomSwap(); if(probability <= newRandCipher.getScore(likelihoods)){ randCipher = newRandCipher; probability = newRandCipher.getScore(likelihoods); } } return randCipher; }