Crypto Lab Project Winter 2007-2008 Submitted by Alexander Grechin and Zohar Rogel Under supervision of Zvika Berkovich Software Systems Laboratory Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ -1- Contents 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. Abstract ................................................................................................. - 3 Introduction ........................................................................................... - 4 Design ................................................................................................... - 7 Summary ............................................................................................. - 16 Appendix A: Definitions ....................................................................... - 19 Appendix B: Command Line Language ............................................... - 20 Appendix C: Use case description ...................................................... - 21 Appendix D: Sequence diagram.......................................................... - 28 Appendix E: Ciphers ........................................................................... - 32 Appendix F: User Manual .................................................................... - 38 References .......................................................................................... - 46 - Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ -2- 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. Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ -3- 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 Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ -4- 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 o o o o Encryption Decryption Automatic cracking User aided cracking 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. Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ -5- 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 Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ -6- 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. Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ -7- 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. Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ -8- 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 Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ -9- Class diagram of Engine package. Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ - 10 - 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: Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ - 11 - 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. Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ - 12 - 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 Dictionary<string, string> GetParameters(); //merges parameters from received list into internal //parameter list void SetParameters(Dictionary<string, 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); Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ - 13 - //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. Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ - 14 - 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. Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ - 15 - 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 Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ - 16 - 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. Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ - 17 - 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 Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ - 18 - 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. Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ - 19 - 6. Appendix B: Command Line Language In order to use the CryptoLab command line application, type its executable file name with command (e.g. : >>CryptoLab.exe help). Commands: help – prints all commands with description into command line cipherlist – prints the list of ciphers into the command line cipher cipherName – prints description of the cipher and its possible parameters strategy – prints the strategy sequence into the command line strategy –create – creates empty strategy and saves it in the configuration file (overrides previously created strategy) strategy –add cipherName command (proprtyName propertyValue)* – adds action to created previously strategy (where command in {encrypt, decrypt, crack}), changes are saved to the configuration file strategy –apply fileInput fileOutput – applies the strategy created in the configuration file on the text from the fileInput and puts the result into the fileOutput Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ - 20 - 7. Appendix C: Use case description GUI Application Use Cases: Run GUI Application Encryption Decryption Auto Crack Manual Crack Cipher Settings Cipher About Save Input Text Load Input Text Save Output Text Create Strategy Apply Strategy Erase Strategy From GUI to Command Line Command Line Application Use Cases: CL Help CL Cipher List CL Cipher CL Strategy CL Strategy Create CL Strategy Add CL Strategy Apply Operational Use Cases: Developer Add Cipher Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ - 21 - Name: Run GUI Application Actors: User Goal: Run and initialize graphic application Pre-conditions: User runs the application Description: 1. The application attaches files with ciphers 2. (Optionally) the application loads the log file Post-conditions: The application is waiting for user Name: Encryption Actors: User Goal: Encrypt the input text Pre-conditions: 1. There is an input text 2. User has chosen a cipher 3. (Optionally) User has chosen cipher parameters Description: Run the encryption algorithm over the input text Post-conditions: The result of the encryption is presented to the user Name: Decryption Actors: User Goal: Decrypt the input text Pre-conditions: 1. There is an input text 2. User has chosen a cipher 3. (Optionally) User has chosen cipher parameters Description: Run the decryption algorithm over the input text Post-conditions: The result of the decryption is presented to the user Name: Auto Crack Actors: User Goal: Decrypt the input text without a key Pre-conditions: 1. There is an input text 2. User has chosen a cipher Description: Run the automatic crack algorithm over the input text Post-conditions: The result of the cipher cracking is presented to the user Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ - 22 - Name: Manual Crack Actors: User Goal: Decrypt the input text without a key Pre-conditions: 1. There is an input text 2. User has chosen a cipher Description: 1. Run the auxiliary algorithm that presents to the user some information about the input cipher text and allows him choosing some crack parameters 2. Get the final crack result from the auxiliary algorithm Post-conditions: The result of the cipher cracking is presented to the user Exceptions: 1 .a. User cancels working of the auxiliary algorithm 1. b. User returned from the use case without any presented result Name: Cipher Settings Actors: User Goal: Allow the user to look at cipher parameters and change them Pre-conditions: User has chosen a cipher Description: The application presents to the user the current values of the cipher parameters (user has an option to change the values and to load defaults) Post-conditions: Changed parameters of chosen cipher are saved Name: Cipher About Actors: User Goal: Allow the user to look at some information about the chosen cipher Pre-conditions: User has chosen a cipher Description: The application presents to the user some information about the cipher Post-conditions: Changed parameters of a chosen cipher are saved Name: Save Input Text Actors: User Goal: Save input text to disk Pre-conditions: User has typed some text in the application Description: 1. The application allows the user to choose filename 2. The application saves text into the file Post-conditions: File saved Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ - 23 - Name: Load Input Text Actors: User Goal: Load input text from disk Pre-conditions: Exists text file that contains English text Description: 1. The application allows the user to choose filename 2. The application loads text from the file into input section Post-conditions: Text presented to user as input Name: Save Output Text Actors: User Goal: Save output text to disk Pre-conditions: Output text was received by applying some algorithm on an input text Description: 1. The application allows the user to choose filename 2. The application saves text into the file Post-conditions: File saved Name: Create Strategy Actors: User Goal: Create a sequence of actions Pre-conditions: The application is running Description: User builds a sequence of ciphers, adding them from a cipher list presented to him (for every cipher in the sequence user chooses one of three actions: encrypt, decrypt or automatic crack) Post-conditions: There is a strategy chain built by user Name: Apply Strategy Actors: User Goal: Apply the strategy created in “Create Strategy” use case Pre-conditions: 1. There is a strategy that was created 2. There is an input text Description: 1. Apply the first action in action strategy on the input text 2. Every next action is applied on the result of the previous one Post-conditions: The result of the last action is presented to the user as an output text Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ - 24 - Name: Erase Strategy Actors: User Goal: Clean created strategy Pre-conditions: There is a strategy that was created Description: Application erases the strategy that was previously created by user Post-conditions: There is no strategy Name: From GUI to Command Line Actors: User Goal: Transition from GUI application to Command Line application Pre-conditions: 1. User worked with GUI application 2. User wants switch to Command Line application Description: 1. User creates a strategy in GUI using results (parameters) of previous work with GUI 2. User uses “Call Command Line for this strategy option” 3. System creates strategy configuration file with specified strategy on hard drive 4. System calls Windows CMD application 5. System passes control to the user Post-conditions: 1. A strategy file created 2. User may continue working with Command Line application Name: CL Help Actors: User Goal: Present to the user some information about possible commands and their description Pre-conditions: None Description: 1. The application runs itself 2. The application presents information to user 3. The application finishes Post-conditions: The presented information remains available for the user Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ - 25 - Name: CL Cipher List Actors: User Goal: Present to the user some information about available ciphers Pre-conditions: None Description: 1. The application runs itself 2. The application presents to user information 3. The application finishes Post-conditions: The presented information remains available for the user Name: CL Cipher Actors: User Goal: Present to the user some information about specified cipher and its parameters Pre-conditions: None Description: 1. The application runs itself 2. The application presents to the user some information 3. The application finishes Post-conditions: The presented information remains available for the user Name: CL Strategy Actors: User Goal: Present to the user some information about the strategy Pre-conditions: None Description: 1. The application runs itself 2. The application presents to the user some information 3. The application finishes Post-conditions: The presented information still available to the user Name: CL Strategy Create Actors: User Goal: Creates an empty strategy and saves it to the disk Pre-conditions: None Description: 1. The application runs itself 2. The application creates an empty strategy and saves it to a configuration file 3. The application finishes Post-conditions: The configuration file with empty strategy is saved Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ - 26 - Name: CL Strategy Add Actors: User Goal: Add an action to existence sequence of actions and save it to the disk Pre-conditions: A strategy exist (empty or not) Description: 1. The application runs itself 2. The application loads existent strategy from configuration file 3. The application adds an action specified by the user to the existent strategy 4. The application saves the created strategy to a configuration file 5. The application finishes Post-conditions: The configuration file with strategy is saved Name: CL Strategy Apply Actors: User Goal: Apply created strategy Pre-conditions: 1. A strategy exist (empty or not) 2. User specified input and output filenames Description: 1. The application runs itself 2. The application applies the strategy on the input file and saves the result into the output file 3. The application finishes Post-conditions: None Name: Developer Add Cipher Actors: Developer Goal: Add new cipher to existent CryptoLab Pre-conditions: 1. Developer wants to add a new cipher to the system Description: 1. Developer writes a dll that implements ICipher interface 2. The name of the dll file started with word "Cipher" (example CipherShift) 3. Dll is copied into the application directory (no registration needed) 4. When restarting the UI, the new cipher appears as button that can be added to a strategy 5. When running CL, new cipher and its properties are added to displayed list Post-conditions: New cipher ready for use in CryptoLab. Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ - 27 - 8. Appendix D: Sequence diagram Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ - 28 - Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ - 29 - Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ - 30 - Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ - 31 - 9. Appendix E: Ciphers 9.1. Shift cipher (Julius Caesar cipher) In cryptography, a Caesar cipher, also known as a Caesar's cipher, the shift cipher, Caesar's code or Caesar shift, is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. For example, with a shift of 3, A would be replaced by D, B would become E, and so on. The method is named after Julius Caesar, who used it to communicate with his generals. Parameter: shift value in [0, 25] – number of positions to shift the letters in text. Encryption algorithm: shift left all letters to “shift value” positions. Decryption algorithm: shift right all letters to “shift value” positions. Description of automatic breaking algorithm: The automatic breaking is done by comparison of the letters distribution in typical English text and distributions of letters in 26 different (shifted relatively to original cipher text) texts. Shifted cipher text with the most similar distribution will be returned as a plain text. Appropriate shift value will be returned as a key. Two histograms compared by summarizing of squared difference between values of appropriate columns. Received number is grade for this comparison. The comparison with the smallest grade supposed to be between the most similar histograms. Manual crack window: Allows the user to shift the cipher text with different shift values and presents result of the operation. Also, a histogram of the shifted text and a histogram of typical English text are presented. User can drag one histogram into another in order to compare them. Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ - 32 - 9.2. Transposition cipher (Rail fence transposition) The Rail Fence Cipher is a form of transposition cipher that gets its name from the way in which it is encoded. In the rail fence cipher, the plaintext is written downwards on successive "rails" of an imaginary fence, then moving up when we get to the bottom. The message is then read off in rows. For example, if we have three "rails" and a message of 'WE ARE DISCOVERED. FLEE AT ONCE', the cipherer writes out: W E E R A C R L T E D S O E E F E A O C I V D E N And then reads off as: WECRL TEERD SOEEF EAOCA IVDEN Parameter: number of lines in [1, 256] to write the plaintext during encryption. Encryption algorithm: write plaintext on “number of lines” lines as described above. Decryption algorithm: reversing the encryption process. Description of automatic breaking algorithm: The program contains dictionary with 2000 English words - GLS (The General Service List, see http://jbauman.com/gsl.html). Algorithm decrypts received cipher text with all possible parameter values. For every received decryption the algorithm looking for words from GLS in it. As found word is longer so the match receive higher grade. The sum of all such grades for given decrypted text is the grade of the decryption. After that the algorithm chooses the decryption with the highest grade and returns it as decrypted cipher text, the parameter of the decryption is returned as a key. Manual crack window: Allow the user to choose parameter value. Presents cipher text and its decryption with chosen parameter. Also, paints the transposition. Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ - 33 - 9.3. A Simple Substitution cipher A substitution cipher is a method of encryption by which units of plaintext are substituted with ciphertext according to a regular system; the "units" may be single letters, pair of letters and so on. In a simple substitution cipher the system uses a single letters and substitutes them by other single letters. Traditionally the new alphabet for encryption is created by first writing out a keyword, removing repeated letters in it, and then writing all the remaining letters in the alphabet. For example: Using this system, the keyword "zebras" gives us the following alphabets: Plaintext alphabet: abcdefghijklmnopqrstuvwxyz Ciphertext alphabet: ZEBRASCDFGHIJKLMNOPQTUVWXY And the message: will be encrypted as: "flee at once. We are discovered!" "SIAA ZQ LKBA. VA ZOA RFPBLUAOAR!" Parameter: a keyword for creating the ciphertext alphabet. Encryption algorithm: writing the plaintext, writing a keyword to create ciphertext alphabet. Encrypt the plaintext as described above. Decryption algorithm: reversing the encryption process using the same keyword and same ciphertext alphabet. Description of automatic breaking algorithm: The program uses a distribution of typical English text and a calculated distribution of the ciphertext. The program compares those two distributions, and matches the letters according to the distribution percentages. For example: the letter E is the most common letter in the English language. It is very likely that in the calculation of the distribution of ciphertext, the most common letter in this calculation was substituted by the letter E. Manual crack window: Allow the user to choose one of two heuristics: the first one is trying to guess the keyword without any other help. The second one is trying to guess the ciphertext alphabet by displaying the distribution histogram of the ciphertext. Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ - 34 - 9.4. Vigenere cipher A Vigenère cipher is a method of encrypting alphabetic text by using a series of different Caesar ciphers based on the letters of a keyword. It is a simple from of polyalphabetic substitution. The method was originally described by Gibson Battista Bellaso in 1553. However the scheme was later misattributed to Blaise de Vigenère in the 19th century and it is now widely known as the "Vigenère cipher". This cipher is well known because while it is easy to understand and implement, it is often appears to beginners to be unbreakable; this earned it the description le chiffre indéchiffrable (French for 'the unbreakable cipher'). In Caesar cipher, each letter of the alphabet is shifted along some number of places. The Vigenère cipher consists of several Caesar cipher in sequence with different shift values. To encipher, a table of alphabets is used, termed a Vigenère table. It consist of the alphabet written out 26 times in different rows, each alphabet shifted cyclically to the left compared to the previous alphabet, corresponding to the 26 possible Caesar ciphers. At different points on the encryption process, the cipher uses different alphabet from one of the rows. The alphabet used at each point depends on a repeating keyword. Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ - 35 - For example: suppose that the plaintext to be encrypted is: ATTACKATDAWN The one who is sending the message chooses a keyword and repeats it until it matches the length of the plaintext. For this example we will use the keyword "LEMON". LEMONLEMONLE The first letter of the plaintext, A, is enciphered using the alphabet in row L, which is the first letter of the key. This is done by looking at the letter in row L and column A of the Vigenère table. Similarly, for the second letter of the plaintext, the second letter of the key is used; the letter at row E and column T is X. The rest of the plaintext is enciphered in a similar fashion: Plaintext: ATTACKATDAWN LEMONLEMONLE Key: Ciphertext: LXFOPVEFRNHR Parameter: a keyword to use with the Vigenère table to encrypt or decrypt the plaintext. Encryption algorithm: writing the plaintext, writing the keyword in a cyclic form in a way the keyword repeat itself for as long as the plaintext size is. Using the Vigenère table the program substitute each letter according to the row and column in the table and the letters in the keyword. Encryption example is shown above. Decryption algorithm: reversing the encryption process by using the same keyword and same Vigenère table. In the reverse process the program searches for the letters encrypted with the keyword by column and row (reverse to row and column as in encryption process). Description of automatic breaking algorithm: The program uses an algorithm for breaking the Vigenère cipher, known as Kasiski test. First, the algorithm tries to find the keyword length. The algorithm searches for repeated sequences of letters, and calculate the spaces between those repeated sequences. Then, the algorithm takes the spaces and calculates the factors of every space number it found earlier. The most common factor found in this process is probably the keyword length. The algorithm then uses a Caesar cipher decryption to indentify each letter of the keyword. For every letter in the cracked keyword, the algorithm Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ - 36 - shifts the letters and searches for the best suitable shift value, by using comparison between distribution of the ciphertext (for each letter a new ciphertext is created) and the normal English distribution. Once the algorithm founded the best shift value for a letter, it continues to the next letter as so on, until it finds all the letters of the keyword. Once the algorithm found all the letters, it uses them as a cracked keyword at tries to decrypt the original ciphertext with the cracked keyword. Manual crack window: Allow the user to crack the keyword with the same algorithm as in the automatic crack. The user needs to find the keyword length, and then he tries to find the letters by shifting the letters. The user may try to compare the distribution of the ciphertext of each letter to the normal English distribution. The user will see on screen the ciphertext changes according to his letter shifting, and he can indentify when the ciphertext does really cracked. Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ - 37 - 10. Appendix F: User Manual 10.1. General In order to run the program user should install Microsoft .Net framework version 2.0 or higher (download from Microsoft official site: http://www.microsoft.com/downloads/details.aspx?FamilyID=0856EACB4362-4B0D-8EDD-AAB15C5E04F5&displaylang=en). The program contains following files: o CryptoLab.exe o CLCryptoLab.exe o Engine.dll o InterfaceCipher.dll o CipherShift.dll o CipherRailfence.dll o CipherSubstitution.dll o CipherVigenere.dll o CrackTools.dll In order to run the GUI application, click on the "CryptoLab.exe" file. In order to execute commands of command line application type in command line "CLCryptoLab.exe" followed by command and parameters if needed (see possible commands in Appendix B). Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ - 38 - 10.2. Working with GUI application Initial view of GUI application. Now it’s ready to use. Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ - 39 - Using file menu the user can load text (plaintext or cipher text) from a hard drive into the input window or save text from input, output windows to a hard drive. Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ - 40 - Log window presents information about operations performed by application. Strategy window allows building strategy with attached to application ciphers. Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ - 41 - Work with a cipher: o Using menu of each specific cipher the user can perform basic operations (“Encrypt”, “Decrypt”, “Auto Crack”) over text from input window. o Click “Parameters…” option in order to choose parameters used in the execution of the operations. o Click to “About…” option in order to get some information about the cipher. o “Manual Crack…” option calls the auxiliary window. It helps to find parameters used in cipher text decryption. Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ - 42 - After the encryption, the result – encrypted text, presented in the output window. New log message added to the message list in log window. Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ - 43 - Strategy: o Drag ciphers from the list of attached ciphers into strategy area. o For every additional cipher the user can choose operation (encrypt, decrypt, auto) and parameters. o Operation and parameters may be changed after the strategy was built. o User can apply the strategy and erase it from the window using appropriate buttons. o “Call command line for this strategy…” option will copy created strategy into strategy.conf file and will open command line. Here user can continue working with created strategy. Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ - 44 - 10.3. Console application How to use: o Run cmd.exe application o Enter the program directory o Type “CLCryptoLab.exe command” (see possible commands in Appendix B), see following example: Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ - 45 - 11. References [1] Simon Singh. “The Code Book” - 1st edition. 2000 [2] Wikipedia – the web free encyclopedia – www.wikipedia.org [3] The General Service List – http://jbauman.com/gsl.html [4] MSDN – Microsoft Development Network, C# and .NET help and Code exemples - http://msdn.microsoft.com/en-us/default.aspx [5] Simon Singh, The Black Chamber .net edition – Vigenere cipher cracking Example: http://www.simonsingh.net/The_Black_Chamber/cracking_example.html Semester Winter 2007-2008 Software Systems Laboratory http://softlab.technion.ac.il/ - 46 -