1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package edu.caltech.cs2.project01;
import java.util.Map;
import java.util.Random;
public class SubstitutionCipher {
private String ciphertext;
private Map<Character, Character> key;
// Use this Random object to generate random numbers in your code,
// but do not modify this line.
private static final Random RANDOM = new Random();
/**
* Construct a SubstitutionCipher with the given cipher text and key
* @param ciphertext the cipher text for this substitution cipher
* @param key the map from cipher text characters to plaintext characters
*/
public SubstitutionCipher(String ciphertext, Map<Character, Character> key) {
// TODO: Student fill this in
}
/**
* Construct a SubstitutionCipher with the given cipher text and a randomly
* initialized key.
* @param ciphertext the cipher text for this substitution cipher
*/
public SubstitutionCipher(String ciphertext) {
// TODO: Student fill this in
}
/**
* Returns the unedited cipher text that was provided by the user.
* @return the cipher text for this substitution cipher
*/
public String getCipherText() {
// TODO: Student fill this in
return null;
}
/**
* Applies this cipher's key onto this cipher's text.
* That is, each letter should be replaced with whichever
* letter it maps to in this cipher's key.
* @return the resulting plain text after the transformation using the key
*/
public String getPlainText() {
// TODO: Student fill this in
return null;
}
/**
* Returns a new SubstitutionCipher with the same cipher text as this one
* and a modified key with exactly one random pair of characters exchanged.
*
* @return the new SubstitutionCipher
*/
public SubstitutionCipher randomSwap() {
// TODO: Student fill this in
return null;
}
/**
* Returns the "score" for the "plain text" for this cipher.
* The score for each individual quadgram is calculated by
* the provided likelihoods object. The total score for the text is just
* the sum of these scores.
* @param likelihoods the object used to find a score for a quadgram
* @return the score of the plain text as calculated by likelihoods
*/
public double getScore(QuadGramLikelihoods likelihoods) {
// TODO: Student fill this in
return 0.0;
}
/**
* Attempt to solve this substitution cipher through the hill
* climbing algorithm. The SubstitutionCipher this is called from
* should not be modified.
* @param likelihoods the object used to find a score for a quadgram
* @return a SubstitutionCipher with the same ciphertext and the optimal
* found through hill climbing
*/
public SubstitutionCipher getSolution(QuadGramLikelihoods likelihoods) {
// TODO: Student fill this in
return null;
}
}