Crypto Lab Project
Winter 2007-2008
Submitted by
Alexander Grechin
and
Zohar Rogel
Under supervision of
Zvika Berkovich
Software Systems Laboratory
Contents
1. Abstract - 3 -
2. Introduction - 4 -
3. Design - 7 -
4. Summary - 17 -
5. Appendix A: Definitions - 19 -
6. Appendix B: Command Line Language - 20 -
7. Appendix C: Use case description - 21 -
8. Appendix D: Sequence diagram - 28 -
9. Appendix E: Ciphers - 33 -
10. Appendix F: User Manual - 35 -
11. References - 43 -
1. Abstract
For thousands of years, kings, queens and generals have relied on efficient communication in order to govern their countries and command their armies. At the same time, they have all been aware of the consequences of their messages falling into the wrong hands, revealing precious secrets to rival nations and betraying vital information to opposing forces. It was the threat of enemy interception that motivated the development of codes and ciphers: techniques for disguising a message so that only the intended recipient can read it.
The main goal of this project is to create a demonstration program that allows the user to encrypt and decrypt the messages, and helps to break encrypted messages. The application contains several ciphers and allows adding supplementary ciphers.
By product purposes of the project are: to acquire programming skills in C# language, to practice usage of reflection mechanism and graphics issues, to meet .net framework technology and its features, to understand and apply modular extensible design.
2. Introduction
2.1. General explanation
There are two logical parts in our program. The first one is a framework program that will supply to user convenient way to work with ciphers. The second one is a set of ciphers which attached to the framework program.
Framework program
Framework program includes two different applications which use the same core module.
· The core module supplies to the applications the next possibilities:
o Attach ciphers
o Work with each specific cipher
o Create and execute strategies (see definition in Appendix A)
o Receive feedback from ciphers such as log messages and results of performed operations.
· GUI Application (Windows Forms Application) allow the user to:
o Input-output texts
o Create and execute strategies
o Get log of executed operations
o Get results of performed operations
· Console Application
o User should run it from command line (see command set in Appendix B)
o It intended for creation and execution of strategies only
Example of usage: if computation process takes a lot of time, user may reveal some required parameters (secret key) using the GUI application and then call the console application with these parameters for “pure computation”.
Ciphers
· There are 4 ciphers (see chosen ciphers in Appendix E).
· Each cipher implemented as independent library that attached to framework program.
· User may add his own ciphers to the framework program by implementing these ciphers as additional library satisfying some requirements.
2.2. Requirements
· The program will be written using C# programming language and .NET framework 2.0
· The program will consist of framework program and set of ciphers attached to framework program
· For each cipher a module will be written (one shift cipher, one substitution cipher and one transposition cipher at least. In any case Vigenere cipher will be one of them).
· Modules should implement interfaces that will allow:
o Encryption
o Decryption
o Automatic cracking
o User aided cracking
o Provide info (icon, properties for toolbox and strategy windows)
· Each cipher will provide interactive window for user aided crack. It will contain additional information about encrypted text and will help to find some secret parameters.
· Modules are added to the project by a simple file copy. No registration.
· The project should use .NET reflection to identify available modules and invoke them.
· The program will contain GUI application and Command line utility
· The program will allow strategy (see definition in Appendix A) building and execution
· Command line utility works independent of GUI - may not necessarily have all options that are in GUI.
· For automatic crack - display Hollywood effects - letters changing, patterns appear and disappear on screen, add some delays when needed so that the effect will be seen nicely.
· Manual process should be more interesting. E.g. in Caesar cipher the user can drag one histogram on the other in a cyclic way. In "railway cipher" the user can drag a slide bar causing the text to split to more lines.
· Log window allows cipher modules to log their actions.
· Important: GUI application will provide an easy way to generate strategy and call the console application for its execution.
2.3. Main working scenario
· User builds strategy using graphic tool of GUI application
· User chooses to continue working in command line
· Program transfers created strategy from GUI application to console application format
· Program calls cmd.exe application and passes control to user
· User can run the strategy with some input file from command line
3. Design
3.1. Use cases
· Dynamic model that relies on requirements
· Shows all main scenarios of the program
· See use cases in Appendix C
3.2. Module division
· At the design level all program divided into 3 parts:
o User interface part (GUI application and Console application). At the below diagram WinFormApp Package and ConsoleApp Package.
o Core program part (module that serves applications from user interface part). At the below diagram Engine Package.
o Ciphers part (each cipher implemented as single module and attached to the core program during run time). At the below diagram Cipher Packages.
· Module diagram
Here, each package represents single assembly (dll or exe file).
· At this figure we can see two applications as mentioned earlier. GUI Application (WinFormApp Package) and Command Line Application (ConsoleApp Package).
· Both applications use the same core (Engine package).
· Engine package implements two interfaces – one for each application. Its inner structure will be described later.
· Cipher Package is one of the cipher modules that may be attached to Engine. In general, number of such modules is unlimited
· Interaction between Engine and Ciphers:
o Engine package includes InterfaceCipher Package.
o InterfaceCipher Package contains one interface only - ICipher.
o This interface supplies to the Engine the standard set of functions – cipher abilities (described latter).
o Each cipher must implement this interface in order to be attached to cipher collection of the engine.
3.3. Engine Package
· Object of the Engine class contains:
o CipherList – collection of ciphers pointed through ICipher interface.
o StrategyEntryList (representation of current strategy) – a collection of StrategyEntry objects, where each such object represents a single action in the strategy sequence.
· The class itself implements two interfaces:
o IWinFormEngin – interface for GUI application
o IConsoleEngine – interface for Console application.
· StrategyEntery and Cipher are used to interchange data with GUI application
· Class diagram of Engine package.
· IWinFormEngine interface:
o During initialization GUI receive attached to engine ciphers (names, icons) using GetAttachedCiphers() function.
o If user works with single cipher (Encrypt(), Decrypt(), AutoCrack(), ManualCrack(), ShowParameterWindow(), ShowAboutWindo() functions) GUI transfers to Engine the name of the cipher and the input text for operation. See the figure below:
o If user operates with strategies (ApplyStrategy(), EraseStrategy() functions) GUI transfers to Engine the sequence of triples (cipher, operation, parameter list) and the input text. See the figure below:
· IConsoleEngine interface:
o The Console application presents to the user information about attached ciphers and their possible parameters (see set of commands in Appendix B) using GetAttachedCiphers() and GetCipherDetails() functions.
o CreateStrategy() function creates empty text file strategy.conf that will contain strategy.
o AddAction2Strategy() function adds line to this file.
o ApplyStrategy() function parses the file and execute the strategy.
3.4. InterfaceCipher Package
· ICipher interface contained in InterfaceCipher package:
public interface ICipher
{
//cipherName – must be the single word
string GetName();
//image that represents the cipher in GUI
System.Drawing.Bitmap GetImage();
//returns pairs of parameterName - parameterValue
//for each function call returns NEW copy of //parameter list
//parameterName must be the single word
Dictionarystring, string> GetParameters();
//merges parameters from received list into internal //parameter list
void SetParameters(Dictionarystring, string> paramList);
//encypts received plaintext using parameters of the //cipher and returnes ciphertext
string Encrypt(string plaintext);
//decrypts received ciphertext using parameters of the //cipher and returnes plaintext
string Decrypt(string ciphertext);
//decrypts received ciphertext with different //parameters (looking for optimal parameters)
//returns best received plaintext
string AutoCrack(string ciphertext);
//shows to user auxiliary window that presents
//additional information and allows to select //parameters
//returns received plaintext
string ManualCrack(string ciphertext);
//show to user window that allows to select parameters
void ShowParameterWindow();
//show to user some information about this cipher
void ShowAboutInfo();
//returns to user string with description of the //cipher, all parameters and their default values
string GetDetails();
//event raised in order to transfer log message
event LogDelegate LogEvent;
//event raised in order to transfer temporary result //of computation
event ResultDelegate TempResultEvent;
}
· All the ciphers must implement this interface.
3.5. Sequence Diagram
In order to understand all the scenarios in the dynamic way and to start implementation we made the sequence diagram (see Appendix D).
3.6. Extensible design
· The program should have ability to add new ciphers without any need to be changed.
· It means that engine assembly can't include ciphers at compilation time and must attach them dynamically during runtime.
· For this purpose the Reflection mechanism was used.
· Cipher attaching process:
o Engine is looking in the current directory for dll files which name contains prefix "Cipher" (for example CipherShift).
o For each such assembly it tries to instantiate class with the same (as assembly name) name using Reflection.
o Each such received object referenced through ICipher interface contained in InterfaceCipher package.
o At the end of attaching operation, engine contains collection of references to ICipher interface, where each reference points to another cipher.
· Cipher development process:
o Developer creates new assembly which name contains prefix “Cipher” (for example CipherShift).
o The assembly contains public class named as the assembly.
o The class must implement ICipher interface.
o Finished dll copied into working directory (the same directory with Engine.dll).
o The framework program automatically finds new cipher and attaches it.
4. Summary
4.1. Possible extensions and improvements
· The main extension that may be done is, of course, development of additional ciphers. The framework program was designed and implemented taking into account this capability.
· Currently, the program is rather demonstration than the serious encoding instrument. For example, in Julius Caesar cipher we don't eliminate white spaces during encoding. It done for readability of the message decrypted back from cipher text. At the same time, it makes the cipher text more breakable. So, a possible improvement is to make the program "encoding machine" that will emit hard breakable cipher texts.
· It follows that break tools in our program could be improved. Proceeding with above example, we must include additional tool into GUI application that will automatically add white spaces between words. It may be implemented using simple dictionary of the most frequent English words.
· Possible extension is advanced strategy builder that will allow generation of more complicated strategies (for example tree with input text in the root and different results in leaves).
· Currently the program window contains 4 sub-windows (input, output, strategy and log). Possible extension is to make those sub-windows optional and sizable. It will allow the user to choose what to display. Using this feature one can get strategy window only. It may be done with minimal changes in GUI module.
· Graphics improvements.
· The application may contain an internet browser in order to get fast help about some hard breakable cipher text
· Some ciphers are more difficult to break then others. Some improvements could be made with the heuristic strategy for using in auto-crack functionality.
· The decryption (manual or auto-crack) could make more use of the most common words in English to help the decryption process, making it faster and more reliable.
4.2. Purchased knowledge and skills
· We got knowledge about some known ciphers and their history; people that used to develop them, used them to encrypt and decrypt messages and others who broke them.
· Experience in application development from the beginning (meeting with user, requirement composition) to the end (code writing and presentation of ready product).
· Additional skills in C# programming language and working with Microsoft Visual Studio.
· We learned about Reflection mechanism and applied our knowledge in practice.
· We learned more build-in abilities of C# such as drag-drop feature and simple graphic generation.
4.3. Encountered problems
· We met some technical problems with calling to cmd.exe program from the C# code and making it to execute some code. It was solved due to example from internet.
· Some ciphers were harder to implement, especially the automatic crack figure. We used some internet examples to solve this difficult.
4.4. Project workflow
· Requirements composition and understanding
· Cipher choosing
· Use case composition (Appendix C)
· Building module diagram (Design)
· Building class diagram (Design) and sequence diagram (Appendix D)
· Implementation of the framework program with dummy cipher
· Algorithm choosing for each specific cipher (Appendix E)
· Implementation of ciphers
5. Appendix A: Definitions
Plaintext – the natural language message that intended for encryption.
Cipher text – the sequence of symbols which represent encrypted plaintext.
Strategy – (in CryptoLab application) a sequence of cipher-action-parameters triples, where cipher is one of available ciphers, action is one of {encrypt, decrypt, crack}, and parameters as defined for each specific cipher.