hcrypto.analyzer
Class Individual
java.lang.Object
|
+--hcrypto.analyzer.Individual
- All Implemented Interfaces:
- java.lang.Comparable
- public class Individual
- extends java.lang.Object
- implements java.lang.Comparable
Constructor Summary |
Individual(Individual i)
Copy constructor |
Individual(java.lang.String text,
java.lang.String initKey)
This constructor takes an initial distribution for the key as
a parameter. |
Method Summary |
void |
calcFitness()
|
int |
compareTo(java.lang.Object o)
From the Comparable interface. |
static void |
cross(Individual i1,
Individual i2)
This version of cross swaps characters from each individual's
list of characters used in the words found by each individual's key. |
double |
getFitness()
|
java.lang.String |
getKey()
public String mapKey(String key) {
String knownEnglishDist = "etaoinshrdlucmwfgypbvkjxqz";
StringBuffer sb = new StringBuffer();
// System.out.println("key = " + key.toString());
for (char ch = 'a'; ch <= 'z'; ch++)
sb.append(key.charAt(knownEnglishDist.indexOf(ch)));
return sb.toString();
} |
int |
mutate(double rate)
This version of mutate swaps two random characters
in the key. |
int |
mutateUnused(double rate)
This version of mutate swaps two random characters
in the key. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
unusedLetters
public java.lang.StringBuffer unusedLetters
usedLetters
public java.lang.StringBuffer usedLetters
usedLettersNoDups
public java.lang.String usedLettersNoDups
used_decrypt
public java.lang.String used_decrypt
unused_decrypt
public java.lang.String unused_decrypt
Individual
public Individual(java.lang.String text,
java.lang.String initKey)
- This constructor takes an initial distribution for the key as
a parameter.
- Parameters:
text
- -- A string giving the text to be decrypted.initKey
- -- A string giving the initial values for the key.
Individual
public Individual(Individual i)
- Copy constructor
cross
public static void cross(Individual i1,
Individual i2)
- This version of cross swaps characters from each individual's
list of characters used in the words found by each individual's key.
If the OCCURS check is included -- that is, if a check is made to
insure that a swap will not negate a key's decrypt of a word --
then this algorithm will guarantee that the children are no
worse than their parents at finding words. In experimental runs,
approximately half the crosses result in improvements and half in
no change. Without the occurs check a very small percentage of all
crosses lead to improvement and a slightly smaller percentage produce
children that are actually lower scoring than their parents.
MODIFICATION: 11/5/02. Added some swapping of unused characters.
- Parameters:
i1
- an Individual parenti2
- an Individual parent
mutate
public int mutate(double rate)
- This version of mutate swaps two random characters
in the key. The mutation is done with frequency equal
to rate. The resulting mutant is discarded if it
does not improve the fitness of the individual.
- Parameters:
rate
- is the mutation rate
mutateUnused
public int mutateUnused(double rate)
- This version of mutate swaps two random characters
in the key. The mutation is done with frequency equal
to rate. The resulting mutant is discarded if it
does not improve the fitness of the individual.
- Parameters:
rate
- is the mutation rate
getFitness
public double getFitness()
calcFitness
public void calcFitness()
getKey
public java.lang.String getKey()
- public String mapKey(String key) {
String knownEnglishDist = "etaoinshrdlucmwfgypbvkjxqz";
StringBuffer sb = new StringBuffer();
// System.out.println("key = " + key.toString());
for (char ch = 'a'; ch <= 'z'; ch++)
sb.append(key.charAt(knownEnglishDist.indexOf(ch)));
return sb.toString();
}
compareTo
public int compareTo(java.lang.Object o)
- From the Comparable interface.
- Specified by:
compareTo
in interface java.lang.Comparable