The Cryptanalysis of a Three Rotor Machine Using a Genetic Algorithm
Total Page:16
File Type:pdf, Size:1020Kb
The Cryptanalysis of a Three Rotor Machine Using a Genetic Algorithm A J Bagnall G P McKeown and V J RaywardSmith Scho ol of Information Systems University of East Anglia Norwich NR TJ England Abstract Weshow that a genetic algorithm can b e used to suc cessfully search the very large discrete keyspace of a rotor machine of magnitude up to using a sim This pap er describ es a metho d of decipher ple statistical measure of suitability The metho d in ing messages encrypted with rotor machines volves nding the last rotor of a three rotor machine utilising a Genetic Algorithm to search the using a GA and then solving the resulting two rotor keyspace A tness measure based on the phi machine using the iterative technique describ ed in test for non randomness of text is describ ed The plaintext is assumed to be n indep endent reali and the results show that an unknown three sations of a random variable dened on alphab et Z q rotor machine can generally b e cryptanalysed with probability distribution derived from observation with ab out letters of ciphertext The of the single letter frequencies of English The distri results are compared to those given using a bution we use is that given in The statistical mea previously published technique and found to sure of tness is based on the fact that a two rotor ma b e sup erior chine with o dometerlike rotation is p erio dic with p e rio d q If we map the ciphertext through the correct last rotor with a known rotation pattern and split this new ciphertext into q ciphertext strings these INTRODUCTION strings will exhibit the characteristics of monoalpha b etically enciphered plaintext Based on the statis A cryptographic system eects an enciphering trans tic for testing the nonrandomness of text see the formation from plaintext x to ciphertext y bothof tness for any prop osed last rotor is the probabil which are vectors of n letters from a nite set of sym ity of having observed an average value at least as b ols an alphab et of size q whichwe call Z A key k q large as the value actually observed given and that for a cryptographic system is a parameter dened on a the text mapp ed through results from q monoal key space K with the prop erty that knowledge of the phab etic substitutions of the plaintext value of k will enable the recovery of plaintext from ciphertext Cryptanalysis is the pro cess of attempting to recover encrypted plaintext without knowledge of the key In this pap er we consider cryptanalysis with ROTOR MACHINES ciphertext only as opp osed to with known or chosen plaintext and ciphertext It is the former situation Rotor machines formed the basis for most military and which presents the hardest problem for the attacker commercial cryptography until the late s The Genetic Algorithms GAs have previously b een used German Enigma the Heb ern machine and the Con in cryptanalysis for solving simple substitution sys verter M all describ ed in are variations on the tems transp osition ciphers and knapsackbased basic machine weuse systems The cryptographic systems solved are all A rotor machine is a cryptographic device consist fairly straightforward and readily solvable by other ing of N rotors A rotor is a disk with a no de on metho ds For example gives various metho ds for each side for each letter in the appropriate alphab et solving knapsack problems larger than those solved size q and electrical contacts b etween the no des ef in fecting a substitution After eachsuch substitution th enciphering substitution for the i letter of plaintext en by A A is giv B B C C r i r i r i m m m S R i C C C m D D m r i r i r i E E m C C C F F verse G G and the deciphering substitution is the in H H r i r i r i r i S R i C C C C r i r i m m C C m t functions is usually assumed A The set of displacemen be known A common set of displacement func A to B B are those that follow an o dometerlike rotation C C tions has D D pattern suc E s r ibiq c sm i E s F F m rotor system with o dometerlike displacement G G An R is a polyalphabetic substitution system H H functions dened by the sequence of substitutions Figure A three rotor machine for an eight letter SR i j i alphab et b efore and after the rst rotor has rotated m one place with period P which divides q A rotor machine with a set of displacement functions which are not m o dometerlike can at most pro duce q dierent sub the contacts rotate in accordance with a rotation pat stitutions A fuller mathematical description of rotor tern while the no des remain in the same p osition or machines is given in vice versa Rotating a rotor a places yields another usually dierent substitution The key for a rotor machine must dene a a S a C C the numb er of rotors m S a is the comp osition of with the Caesar sub the initial rotor substitutions a a a stitutions C and C A Caesar substitution C is simply a shift of a places the displacement functions R C i i a a iq a We assume the numb er of rotors is known and that the setofdisplacement functions follow the o dometerlike Rotor machines are built by concatenating rotors Let pattern describ ed ab ove So the keyspace K is the set of all Ntuples of p ossible substitutions and a key f g m k is an element of a subset of K The cryptanalysis problem is to nd an estimate of k k given a string b e a set of substitutions representing a bank of m ro of ciphertext tors for encipherment of the rst letter and R fr r r g m CRYPTANALYSIS OF A THREE b e a set of displacement functions ROTOR MACHINE r Z Z s q q Our metho d of attack is to nd the last rotor of a r s three rotor machine using a Genetic Algorithm GA r i r i s mi s s and then to solve the resulting two rotor machine us th where r i is the rotational displacement of the s ing the iterativetechnique describ ed in s th rotor for the encipherment of the i elementofx The Each string results from monoalphab etic encipher GENETIC ALGORITHMS ment Mapping the ciphertext through the correct We implemented the problem on the XGAmeter last rotor of a rotor machine with periodic rotation toolkit develop ed at the UEA which enables the will pro duce a new ciphertext string with the prop erty m easy use of GAs on a variety of problems The deci that the q text strings will exhibit the nonrandom sions in implementing a GA for a particular problem prop erties of the plaintext distribution We can then are concerned with representation tness evaluation reduce the search space to the p ossible wirings of the and the select create and merge metho ds The stop last rotor and consider a tness measure for this non ping condition we use is to halt the GA if there had randomness b een no change in the b est solution so far in gen erations Phi test Representation Consider v indep endent observations of random vari able X with sample space of size q and with range The most obvious representation of a rotor is an array Z Supp ose that the observed frequencies of eachof q of m integers representing the wiring from each p osi the elements in is given by f f f If we q tion The subset of the keyspace containing correct dene the statistic as keys for a three rotor machine with known rotation q functions has magnitude q That is to say there are X f f multiple solutions to a rotor machine with more than i i i one rotor If we dene the set of rotors then f g E s v v where and the variance is b b q C v s s v s s s v s s s and b b C C b q where q q then if X X b s P X i and s P X i C i i r r r r r r C C C C C S R C See for further description of the statistic and b b r r b r pro of of the ab ove results If random variable X has a C C C C C C r b r r probability distribution given by our single letter fre C C C C quency distribution then r r r r r r C C C C C C E v v S R and This means that we can arbitrarily x a wiring in the we set last rotors For any prop osed solution v v v and For a p olyalphab etic substitution with p erio d P and ciphertext y of length n if we assume n is divisible Fitness by P for simplicity then the P strings of text y j of length nP can b e considered as P observations of The basis for our tness evaluation is that plaintext en random variable dened on the sample space of all ciphered by a monoalphab etic substitution will still ex nP p ossible letter combinations Then hibit characteristics of the original distribution Ape P rio dic p olyalphab etic substitution system with p erio d P i i P can b e reduced to a series of monoalphab etic sub P stitution systems by splitting the ciphertext y into P text strings y where and j y iy i P j for jP i nP j P By the Central Limit Theorem the limiting form Mutation of the distribution of In order to maintain diversityandavoid lo calised hill Z climbing it is desirable that when an ospring is cre ated there is a chance that it may mutate We used the following twomutation op erators is the standard normal distribution m So if welet t q the tness of a prop osed last randomly swap two rotor wirings ie eect a ran rotor is calculated as follows dom transp osition on an ospring shift a randomly selected substring of rotor let y b e the transformed ciphertext found by sub wirings to random p osition jecting ciphertext y to the sequence of substitu tions S r i for in offspring : 5 1 3 2 6 4 7 8 9 Let y b e substrings of y such that j random