Cypher Implementation Manual

Introduction

Table of Contents

1. Introduction:A brief overview of the software

 Table of Contents

2.Frequency Analysis:Classes used for analysis purposes

 QuickSort

 H_table

 Statistics

3. Spell Check:Classes performing dictionary checking

 Dictionary

  1. Transposition:Classes used as tools for transpositions

 Transposition

 BlockCipher

 CList

5. Text Editor:Classes editing the cipher and plain text

 Key_table

 DecryptData

 Cypher_text_editor

6.Interface:Classes responsible for the interface

 Cypher

 Defs

 Edit

 FileMenu

 HelpMenu

 StatMenu

7. Class Dependencies:Dependencies of classes

8. Index by Type:Classes and Modules are listed by type

9. Index Alphabetically: Classes and Modules are listed alphabetically

Frequency Analysis

The object of frequency analysis is to analyze the frequencies of characters or multiple-characters in the cipher text. Both storage classes and working classes are needed for this.

QuickSort / Small class used soley for quicksorting types of h_table_entry
swap(h_table_entry &x, h_table_entry &y) return void
Procedure taking two references of h_table_entry’s and swaps each with the other.
sort3(h_table_entry &x, h_table_entry &y, h_table_entry &z) return void
swap3(h_table_entry &x, h_table_entry &y, h_table_entry &z) return void
Procedure taking three references of h_table_entry’s and swaps them such that the first is the third, the second is the first, and the third is the second.
alphasort3(h_table_entry &x, h_table_entry &y, h_table_entry &z) return void
Procedure taking three references of h_table_entry’s and sorts them in increasing order.
AlphaQuickSort(h_table_entry *&a, int n) return void
AlphaQuickSortAux(h_table_entry *a, int n) return void
QuickSort(h_table_entry *a, int n) return void
Procedure taking an array of h_table_entry’s and an integer representing the size of the array. QuickSort then sorts the array in increasing order.
QuickSort_reverse(h_table_entry *a, int n) return void
Procedure taking an array of h_table_entry’s and an integer representing the size of the array. It then uses QuickSort to sort the array in increasing order, but then reorders them in decreasing.
H_table / Hash Table class for quick access and growability
H_table (int num_buckets) constructor
Constructor constructing a hash table of h_table_entry with the specified number of buckets given by the integer parameter num_buckets.
hash ( const string & name) return int
Function taking a reference to a string and hashing that string to an integer.
insert (string h_input) return void
Procedure taking a string and inputting into the H_table, the hash table. If the string is not in the H_table, then it is inputted in and its frequency set to one. Else if the string is in the H_table, then the entry already there is increased in its frequency by one.
print_Table() return void
Procedure taking nothing, and outputting the contents of H_table to the command line.
array_implement() return void
Procedure taking nothing, but takes the private member “d_table,” representing the actual hash table, and converts it into an array and points the private member “d_array_head” to it. All this is done with out erasing the “d_table.”
get_top_entries(int num_top_entries) return h_table_entry *
Function takes the an integer that is the number of top entries you would like out of the hash table, and it then returns an array with those entries.
table_analysis(char key_name)
Returns table analysis data.
Statistics / Analyze text for statistics on occurrence of letters.
Statistics( const char* input_file, bool ig_nonalpha)
default constructor
initialize() return void
Initialize data_1char values to 0
Initialize data_2char values to 0
Initialize data_3char H_table
~Statistics() destructor
Destructor freeing up the memory used by the Statistics object at the time it is killed.
Deletes “data_3char,” and sets the pointer to NULL.
single_analysis( bool alphasort ) return void
Function returning single character frequencies.
double_analysis() return void
Function returning double character frequencies.
triple_analysis() return void
Function returning triple character frequencies.
table_analysis()
Reallocate memory and initialize.
Go through trigram data and fill data.
analyze( const char * input, const bool ig_nonalpha) return void
return_size ( int which_freq ) return int
Returns size of statistical data ( 1, 2, 3 )
return_data ( int which_data, int index )
returns data ( 1, 2, 3 ) / index #
analyze( const char * input, const bool ig_nonalpha ) return void
Tallies single, digram, and trigram frequencies and total counts in text input and stores results in sample_space[] and data_1char[], data_2char[], and data_3char.

Spell Check

The object of spell check is to both rate the successfulness of the current cipher key and to help find the current cipher key by giving possible spellings of words. Both searchable storage classes and working classes are needed for this.

Dictionary / A container class that is searchable. Holds a dictionary of words in it.
Dictionary() constructor
~Dictionary() destructor
lookup( string word ) return int
Search for a word in the dictionary.
Returns length of match from start of word.

Transposition

Transposition / A compilation of all the transposition-cipher related functions.
init_matrix () return void
t_switch(Fl_Widget *w) return void
t_swap_cols(Fl_Widget *w) return void
t_resize(Fl_Widget *w) return void
t_redisplay() return void
t_reset(Fl_Widget *w) return void
t_swap_rows(Fl_Widget *w) return void
BlockCipher
BlockCipher (char* cipher, char* plain, int num_elem, int rws, int cols )
constructor
~BlockCipher()
destructor
get_elem(int i, int j)
get_plain()
get_cipher()
print_matrix() return void
resize(int rws, int cols) return int
swap_rows (int row1, int row2) return bool
swap_columns(int col1, int col2) return bool
transpose() return bool
CList
CNode( string name, CNode * next = NULL )
Constructor
CList()
Constructor
~CList()
Destructor
insert( string name ) return void
isGreaterThanOrEqual( string word1, string word2, int & highlight_match ) return bool
lookup( string name ) return int
size() return int
print() return void

Text Editor

Key_table / Initializes key table and inserts characters into the correct position.
Key_table()
Sets all elements of the table array to the null character.
insert(char insert_char, int index) return void
Inserts insert_char into index'th index.
insert(char replace_char, char std_char)
Inserts replaced character into index'th index.
print()
Prints Key_table.
DecryptData / Responsible for holding data for individual characters in the decryption window.
Cypher_text_editor / Text editor for Cypher program
Cypher_text_editor()
Constructor
Creates object of type Cypher text editor ... Data is set to data_ptr and elements initialized
init( char * data_ptr, int str_size ) return void
reinit( char * cipher, char* plain, int str_size ) return void
restat( bool ig_nonalpha ) return void
~Cypher_text_editor()
Destructor.
Destroys object of type Cypher text editor ... Pointers deallocated, memory freed.
change_text(char new_char, char old_char, bool use_wrap, bool swap, int space_between, int use_index ) return bool
Data_object.value_array is updated to contain new information.
clear_key( int key_number ) return void
Clears the key and erases locked status.
add_space(int index) return bool
Adds a space at the given index. Returns true if successful.
delete_space(int index) return bool
Adds a space at the given index. Returns true if successful.
operator []( int index )
Returns the value of decrypted data at given index location.
operator ()( int index )
Returns the encrypted data at given location.
Function
return_flag ( int index ) returns int
Returns the flag status of the element at index.
Function
return_key_entry( int index ) returns char
Returns key entry of given index.
return_size( bool use_wrap ) return int
Returns size of data, depending on word wrap boolean
Function
locked_status( int index ) returns bool
Returns the locked status of the element in index.
word_wrap( bool is_wrapped, int table_num ) returns bool
Sets decryption data according to word wrap being on or off.
change_lock( char character, bool update_table, int table_num ) return void
Swaps the locked value in the given array, also updates output.
clear_highlight() return void
Clears highlight flag from flag_array.
run_analysis( int type, bool alphasort ) return void
Runs statistical data to get frequency analysis of the cipher text.
sort_eng_data( int type, bool alphasort ) return void
get_analysis( int type, int index )
Returns type frequency analysis data at given index.
get_analysis_size( int type ) return int
Returns size of analysis data.
get_eng_data( int type, int index )
Returns english frequency analysis data at given index.
update_v_space( int space ) return void
load_v_key( int spacing, int table_num ) return void
return_shifted ( int key_num ) return int
swap_keys( int key_num, bool undo ) return void
shift_data ( int shift_amount, int space_between = 1, int use_index = 0, int low_bound = ASCII_OFFSET, int up_bound = TABLE_SIZE + ASCII_OFFSET ) return int
Shifts data specified amount.
convert_char( char check_char, char & return_char ) return bool
dict_lookup() return void
Parses through encrypt_data and iteratively searches words or sections of text
for the largest dictionary match or partial match, which is then highlighted.
Print() return void
Print to screen.

Interface

Cypher / Cypher Team Data file
full_ascii() return void
Option Menu Function
intro_exit() return void
Helper callback used upon loading of program.
Shows start window.
update_window() return void
Update window
shift_cb( Fl_Widget *w ) return void
fill_alph( Fl_Widget *w ) return void
clear_alph( Fl_Widget *w ) return void
Disregard any ASCII range setting; clear all table entries.
change_mode(int new_mode) return void
Hides and shows buttons and windows depending on the new decryption mode.
Also creates or delete data objects as appropriate when shifting modes.
shift_tools() return void
Shows shift counter and does updates
transpose_tools( Fl_Widget *w ) return void
open_notes_cb( Fl_Widget *w ) return void
v_cipher_cb( Fl_Widget *w ) return void
norm_tools_cb( Fl_Widget *w ) return void
v_space( Fl_Widget *w ) return void
cur_v_key( Fl_Widget *w ) return void
init_matrix () return void
Transposition Startup
Edit / Includes all definitions that manipulate the decryption window including
undo/redo.
word_wrap() return void
Procedure taking no arguments, that either wraps the text or unwraps the text depending on its state. The wrap inside the cipher working space text window makes sure the words either are jam packed or that no splitting of words occur.
lock(Fl_Widget *w, long int but_num) return void
Procedure taking a widget and a button number, that locks the contents of the button of that number. With these contents locked the user is unable to change the contents.
Locking Function
alpha_lock_cb(Fl_Widget *w, long int but_num) return void
Exchange Helper Function
change_alph_cb(Fl_Widget *w, long int but_num) return void
Helper callback function to exchange one element of the cypher alphabet.
Shows exchange window.
Locking Function
update_lock() return void
Updates locked boxes.
dictionary_cb() return void
Procedure taking no arguments, that looks up the current highlighted word in the cipher working space text.
Exchange Helper Function
inner_exchange(Fl_Widget *w, long int but_num) return void
Helper callback function to exchange one element of the cypher alphabet.
Shows exchange window from inside the window.
Exchange Helper Function
exch_close_cb() return void
Helper callback function that hides the exchange window on a cancel.
Exchange Helper Function
exchange_cb() return void
Helper callback function that exchanges character variables.
Exchange Helper Function
exch_cancel_cb() return void
Helper callback function that hides the exchange window on a cancel.
add_space_cb() return void
Helper callback function that adds a space in the current exchange index.
delete_space_cb() return void
Helper callback function that adds a space in the current exchange index.
undo_cb() return void
This procedure does the following:
Takes no arguments, undoes the last change made to the cipher text, plain text, or cipher key and also redoes an undo, meaning something that had been undone is now redone.
FileMenu / File to be included at the appropriate mark in Cypher.C
new_file_cb() return void
new_file() - callback used for 'New' in menu
open_file_cb() return void
open_file() - callback used for 'Open' in menu
Uses load_file() to do open.
close_file_cb() return void
close_file() - callback used for 'Close' in menu
save_cb() return void
save() - callback used for 'Save' in menu
Uses save_as() if filename doesn't exist.
Calls save_file() to do the work.
save_as_cb() return void
save_as() - callback used for 'Save_as' in menu & when save() has no filename
Calls save_file() to do the work.
quit_cb() return void
quit() - callback used for 'Quit' in menu
Requests save if changed is true, hides window.
cut_cb() return void
Function to be used in New File window.
copy_cb() return void
Function to be used in New File window.
paste_cb() return void
Function to be used in New File window.
File Helper Function
start_new() return void
Procedure taking no arguments, that takes information in the current file window and places it into the Cipher working enviroment, the cihper window.
File Helper Function
no_new_file() return void
Procedure taking no arguments, that disregards the information in the current file window and closes it. Nothing is placed into the Cipher working enviroment, the cipher window.
File Helper Function
check_save() return int
Helper file function that checks to see if the file has been saved before a quit.
File Helper Function
set_changed(int c) return void
Helper function that sets the changed variable.
File Helper Function
load_file(char *newfile) retun void
Helper function that does the meat of work for opening a file.
Loads information from file into the main window.
File Helper Function
save_file(char *newfile) return void
Helper function that does the meat of work for saving a file.
Writes information from the windows into a file format.
Help Menu / Help menu for interface class
Function
bg_info() return void
Function
glossary() return void
Procedure taking no arguments, that displays the glossary window, allowing use of it.
Function
about() return void
Procedure taking no arguments, that displays the start window, the window that credits and gives information about Cipher.
Function
find_cb() return void
This callback function asks for a search string using the fl_input() convenience
function and then calls the find_again_cb() function to find the string.
Function
find_again_cb() return void
This function will find the next occurrence of the search string.
If the search string is blank then we want to pop up the search dialog.
StatMenu / Implementation of callback functions from View menu
and all windows and functions brought about by it.
Fl_Menu_Item statmenulist[]
Statistical Analysis Window Menubar Declarations for frequency, histogram, and elements.
show_stats( int type ) return void
Procedure taking an integer representing either single, double, or triple analysis respectively. The procedure displays the specified analysis to a window.
single_freq() return void
Procedure taking no arguments, that calls into play various other subprograms as to get the single character frequencies on the current file and display them.
digram_freq() return void
Procedure taking no arguments, that calls into play various other subprograms as to get the double character frequencies on the current file and display them.
trigram_freq() return void
Procedure taking no arguments, that calls into play various other subprograms as to get the triple character frequencies on the current file and display them.
view_ten_freq() return void
Displays 10, single histogram
Displays 10, double histogram
Displays 10, triple histogram
view_twenty_freq() return void
Displays 20, single histogram
Displays 20, double histogram
Displays 20, triple histogram
view_thirty_freq() return void
Displays 30, single histogram
Displays 30, double histogram
Displays 30, triple histogram
view_all_freq() return void
Display all, single histogram
Display all, double histogram
Display all, triple histogram
single_histogram() return void
Displays 10, single histogram
Displays 20, single histogram
Displays 30, single histogram
Displays All, single histogram
table_histogram() return void
display_freq(int num_freq, int type) return void
Procedure taking the amount of frequencies to be displayed and the type of either single, double, or triple characters. The procedure gathers and makes the frequencies of the type and specified amount be displayed in a window.
stat_exch() return void
Exchanges values in plain text according to frequencies
close_stat() return void
Procedure taking no arguments, that closes the stat window.
stat_on_top() return void
If function is called by callback and not by stat_on_top2 then update statmenulist option value.
stat_on_top2() return void
stat_swap_cb() return void
Procedure taking no arguments, that within the current stat window takes the frequency arranged cipher characters and places them into their closest counter partner in the plain text characters, which are also arranged according to frequency. Thus the cipher key is filled partially or fully, but may or may not be correct.

Class Dependencies

FileIncludes

BlockCipher.CBlockCipher.h

CList.CCList.h

Cypher.C FLTK Libraries

BlockCipher.C

CList.C

Cypher_icon.xpm

Cypher_text_editor.C

DecryptData.h

Dictionary.C

Edit.C

FileMenu.C

HelpMenu.C

H_table.C

Key_table.C

QuickSort.C

StatMenu.C

Statistics.C

Transposition.C

Cypher_text_editor.CCypher_text_editor.h

iomanip.h

DecryptData.hNone

Dictionary.CDictionary.h

FileMenu.CNone

H_table.CH_table.h

HelpMenu.CNone

Key_table.CKey_table.h

QuickSort.CQuickSort.h

Statistics.CStatistics.h

StatMenu.CNone

Transposition.C

Index by Type

1.Containers:Classes used for storage and access

 Key_table

 DecryptData

 H_table

 Statistics

 Dictionary

 CList

2. Mini Modules:Classes performing minor tasks

 QuickSort

 BlockCipher

  1. Work Modules:Classes performing major tasks

4. Main Modules:Classes linking and using the modules as one

 Cyhper_text_editor

5.Interface Modules:Interface Modules

 Cypher

 Edit

 FileMenu

 HelpMenu

 StatMenu