NAME

variant - Create and manipulate a variant cipher

SYNOPSIS

set cipherProc [cipher create variant]

cipherProc configure ?options?
cipherProc cget option
cipherProc substitute pt ct ?column?
cipherProc undo column
cipherProc restore ct pt
cipherProc locate tip ?ct?
cipherProc locatebest tip
cipherProc fit column
cipherProc solve

DESCRIPTION

cipherProc configure ?options?
Configure the settings for the variant cipher. Valid options are:

cipherProc configure -ciphertext string
cipherProc configure -ct string
Set the ciphertext for this cipher instance to string. Invalid letters or numbers in the ciphertext are silently discarded.

cipherProc configure -period n
Set the period for this cipher to n.

cipherProc configure -stepinterval n
Set the display interval while solving to n. The stepcommand procedure will be called for every nth iteration while solving. This is used to provide user feedback while solving is taking place.

cipherProc configure -stepcommand proc
Set the display command while solving to proc. This command will be called for every nth iteration while solving. The arguments for this procedure are:

stepcommand iter key pt

iter is the current iteration number. key is the current value of the key that is being used. pt is the plaintext that is produced with this key.

cipherProc configure -bestfitcommand proc
Set the best fit display command while solving to proc. This command will be called every time a better solution is found while autosolving. The arguments for this procedure are:

bestfitcommand iter key value pt

iter is the current iteration number. key is the current value of the key that is being used. value is the value of the metric used to judge how good this solution is. The value is often a digram or trigram frequency count. pt is the plaintext that is produced with this key.

cipherProc configure -language language
This option is currently ignored for all cipher types. Set the current cipher language to language. If the cipher has a solve method then digram frequencies for this language are used to determine the best fit. If the language is not specified or not known then english is used.
cipherProc configure -solvemethod fast|thorough
variant ciphers have two possible autosolve methods. The first method, fast, finds the best digram fit for the first and second columns. It then fixes the key for the first two columns and then finds the best digram fit for the second and third column. The third column's key is then fixed. This procedure is repeated for all of the columns in the cipher. This method is very quick, but has the drawback that if an error is made in the key for one of the first few columns, the error may propogate through and the resulting solution could be far from correct.

The second method, thorough, performs a brute force search through every possible key. This takes much longer since it must search the keyspace for 26period possible keys.

A digram frequency count is used to determine which key is the most likely.

cipherProc cget option
Look up the value for a given option. Valid options are:

cipherProc cget -type
Returns the type of this cipher. In this case, variant

cipherProc cget -ciphertext
cipherProc cget -ct
Return the ciphertext for this cipher.

cipherProc cget -plaintext
cipherProc cget -pt
Return the plaintext for this cipher based on the current key setting.

cipherProc cget -key
Returns the current key setting for this cipher. The result can be passed back to this cipher instance or another cipher with the cipherProc restore subcommand.

cipherProc cget -keyword
Returns the keyword for this cipher based on the current key.

cipherProc cget -length
Returns the length of the ciphertext for this cipher. 0 is returned if the ciphertext has not been set.

cipherProc cget -period
Return the period for this cipher.

cipherProc cget -stepinterval
Returns the current value of the stepinterval.

cipherProc cget -stepcommand
Returns the name of the procedure currently set for the stepcommand. An empty string is returned if no stepcommand is set.

cipherProc cget -bestfitcommand
Returns the name of the procedure currently set for the bestfitcommand. An empty string is returned if no bestfitcommand is set.

cipherProc cget -language
Returns the name of the language used for this cipher.

cipherProc cget -solvemethod
Returns the current setting for the solvemethod option, either fast or thorough.

cipherProc substitute ct pt column
Substitutes the ct string for pt starting at column. pt does not need to appear in the ciphertext. ct and pt must be the same length. The substitute command calculates what key letter(s) would produce the specified ct from the pt and enters it in the cipher's key. After performing a substitution, you can use the cipherProc cget -plaintext command to look at the rest of the substitutions that the key change produced.

cipherProc undo column
The undo command erases the key entry for the specified column.

cipherProc restore ct pt
The restore command restores the cipher's key to a previously stored state. The output from cipherProc cget -key can be passed back into the restore command to implement a crude save feature. Example:

set key [$firstCipher cget -key]
$secondCipher restore [lindex $key 0] [lindex $key 1]

It operates the same as if you had run cipherProc substitute ct pt 0.

cipherProc locate tip ?ct?
Locate a possible position for the tip in the ciphertext. The tip is dragged along the ciphertext until a valid substitution is found. If the ct argument is specified, the tip is dragged along starting where ct appears in the ciphertext.

cipherProc locatebest tip
This routine drags the tip through all of the positions in the ciphertext and returns the one that produces the best plaintext, as determined by digram frequencies.

cipherProc fit column
This routines tries all 26 possible keys for the given column and returns the one that produces the best single-letter frequency count.

cipherProc solve
Solve the current cipher. Solutions are found by looping through a set of keys and calculating the frequency of the digrams in the resulting plaintext. The key that produces the highest digram frequency count will be listed as being the most likely solution. In order to provide some user feedback (to let you know that it's actually running), the solve method can be set to call a user-defined procedure at every nth key that is tried. See the descriptions for -stepcommand and -stepinterval on how to use this feature. The solve routine will also call a user-defined procedure every time it finds a solution better than the currentbest. The -bestfitcommand option describes this in more detail.
When this command returns, it will set the current key for the cipher to the best one that was found.

Back to the Index
wart@kobold.org
Created on Wed Mar 31 08:18:24 PST 2004
SourceForge.net Logo