You are on page 1of 17

A.

Historical Ciphers

A.1. Cesar Cipher
1. Decipher the following message knowing that the plain-text was written in Romanian:
QDQBYPQ IFUSJHQBQ Q IUCDQBUBEH QDQBEWYSU

Simplest way to decipher a Cesar cipher-based cipher text is based on cipher text’s histogram (i.e., letters’
frequency) analysis. By doing this, one can observe that the most frequent symbol within the cipher text
is the letter ´Q´. With the highest probability, ´Q´ replaces ´A´ (i.e., the most frequent symbol in Romanian
plain-texts1). Now the displacement between ´A´ and ´Q´ is 16.

Symbol Q B U D E, H, I, S, Y C, F, J, P, W
Frequency 25.00% 13.88% 11.11% 8.33% 5.55% 2.77%

R: ANALIZA SPECTRALA A SEMNALELOR ANALOGICE, KEY=´Q´ (i.e., in alphabets’ symbols) or 16

2. Decipher the following message knowing that the plain-text was written in English:
VKRIMHLRLMXF'L LXVNKBMR TGW KHUNLMXGLL PTL TLLXLLXW PBMA MAX TBW
HY OTKBHNL FXMAHWL LNVA TL DXR LITVX TGW DXR'L LXGLBMBOBMR MH LFTEE
VATGZXL TGTERLXL, WBYYXKXGMBTE TGW LMTMBLMBVTE TGTERLXL XMV. TGW
MAX VHKKXLIHGWBGZ XQIXKBFXGMTE KXLNEML LAHPXW MATM MAX IKHIHLXW
BFTZX VKRIMHLRLMXF ATL T WXLBKTUEX EXOXE HY LXVNKBMR.

Under the same methodology, screening cipher text’s histogram, one can observe that the most frequent
symbol within the cipher text is the letter ´L´. Thus, as ´E´ is the most frequent symbol in English plain-texts
one can jump to the conclusion that the deciphering key is 7 (i.e., value of the displacement between the
two symbols). But, with the deciphering of the cipher text, it will be proved that this conclusion is false,
as the result will be still illegible:

KZGXBWAGABMU'A AMKCZQBG IVL ZWJCABMVAA EIA IAAMAAML EQBP BPM IQL WN
DIZQWCA UMBPWLA ACKP IA SMG AXIKM IVL SMG'A AMVAQBQDQBG BW AUITT
KPIVOMA IVITGAMA, LQNNMZMVBQIT IVL ABIBQABQKIT IVITGAMA MBK. IVL BPM
KWZZMAXWVLQVO MFXMZQUMVBIT ZMACTBA APWEML BPIB BPM XZWXWAML
QUIOM KZGXBWAGABMU PIA I LMAQZIJTM TMDMT WN AMKCZQBG.

Symbol L X T M B G, H, K W E, R …
Frequency 14.28% 12.40% 9.39% 9.02% 6.01% 4.88% 4.51% 4.13% …

However, with a more careful analysis of cipher text’s histogram, someone else observes that there are
two symbols with quite close frequencies. Thus, it might say that the correct key lies somewhere between
these two symbols, i.e., ∈ {′ ′, ′ }. Thus, at the second iteration, it will be proved once again that
the achieved conclusion in false, as the result will be still illegible:

YNULPKOUOPAI'O OAYQNEPU WJZ NKXQOPAJOO SWO WOOAOOAZ SEPD PDA WEZ
KB RWNEKQO IAPDKZO OQYD WO GAU OLWYA WJZ GAU'O OAJOEPEREPU PK OIWHH
YDWJCAO WJWHUOAO, ZEBBANAJPEWH WJZ OPWPEOPEYWH WJWHUOAO APY. WJZ
PDA YKNNAOLKJZEJC ATLANEIAJPWH NAOQHPO ODKSAZ PDWP PDA LNKLKOAZ
EIWCA YNULPKOUOPAI DWO W ZAOENWXHA HARAH KB OAYQNEPU.

1 see APPENDIX E

Rule: pick the opposite corners. Rule: pick the opposite corners. Rule: pick items up to each letter (i. (ii) between these symbols which has the highest probability (i. Result: GX (i. usually. AND THE CORRESPONDING EXPERIMENTAL RESULTS SHOWED THAT THE PROPOSED IMAGE CRYPTOSYSTEM HAS A DESIRABLE LEVEL OF SECURITY...e. Rule: pick the opposite corners.. block.e. KEY=´F´ (i. however. as in ‘a car’ or ‘I’..e. as long as possible). So. Rule: pick the opposite corners. Rule: pick items left to each letter (i.Guessing can continue.J K L M N Q T U V X Y Z R: ALLAN TURING . Result: AL (ii) MP – Shape: rectangle. Answering these two questions. as in ‘I am’) in an English plain-text (i.. Decipher the following message knowing that the chosen password was ´PASSWORD´: PM MP QL PF HQ HV (i) PM – Shape: rectangle.e.. OBS: To counteract the final case (i. where the “link” between the plain-text and the cipher text is “betrayed” by a single symbol). ‘a’...e.e. Now the displacement between ´A´ and ´T´ is 19 and the deciphered text is: CRYPTOSYSTEM'S SECURITY AND ROBUSTNESS WAS ASSESSED WITH THE AID OF VARIOUS METHODS SUCH AS KEY SPACE AND KEY'S SENSITIVITY TO SMALL CHANGES ANALYSES.. as long as possible). wrap to left).e. DIFFERENTIAL AND STATISTICAL ANALYSES ETC. Looking at the cipher text one can find the singular ´T´ symbol (i.e. continuous. wrap to up).g. if it hasn’t the proper size). Playfair Cipher 1. Result: UR (v) HQ – Shape: rectangle.2. Decipher the following message knowing that the plain-text was written in English: JAJSN SHWDU YTQTL DXNQJ SHJNX LTQIJ SCCCC R: EVEN IN CRYPTOLOGY SILENCE IS GOLDEN. (ii) is given as a single. we should wonder: (i) which are the symbols more likely to appear “alone” (e. with the highest probability. Result: IN (vi) HV – Shape: rectangle. the cipher text: (i) is divided into equal size blocks (with the final one padded. Result: LA (iii) QL – Shape: on the same row. the problem is much simpler than it looks. Result: NT (iv) PF – Shape: on the same column. 3. one can correctly conclude that. in alphabets’ symbols) or 5 A. 5th row). with padded X) P A S W O R D B C E F G H I. ´T´ replaces ´A´. to appear “alone” in a plain-text.

Vigenère Cipher 1. Rule: pick the opposite corners. Result: AN (ii) CI – Shape: on the same column. Result: EC (iii) AS – Shape: rectangle. Result: TA P O V E S T A B C D F G H I.J K L M N Q R U W X Y Z R: ANECDOTA A. Result: DO (iv) AB – Shape: on the same row. Decipher the following message knowing that the chosen password was ´DASHLINE´: JRSWSQP HHSANY (i) − 26 = ( 9 − 3) 26 = 6 ≡ (ii) − 26 = (17 − 0) 26 = 17 ≡ (iii) − 26 = (18 − 18) 26 = 0 ≡ (iv) − 26 = (22 − 7) 26 = 15 ≡ (v) − 26 = (18 − 11) 26 = 7 ≡ (vi) … 2. Rule: pick the opposite corners. 2. Rule: pick items up to each letter. Find the password with which the following cipher text was obtained: KVGLGVPBNLEIUZDTEEKIWHWSGKDTIRHIKVYIKBTKIJVQCHXZQVUVVDCVNWIFRTTYMMCTXU KRPLQLMEIQCJSDRMIPXZQVLPXYEWJUXIKMHZYTJIHIYCIIGPEXTMTJIZVIAFSIUXPPRSNIRRWVC ZTZSIVAHBGYCABHQRKIDSMDRVTWXLPAPAYIPDTUYJCVSTEEIIAPERTMPTSEIBWLQRKVIVYIK AIPGRVBGHGKKWCZSWVPTZYDOMGZIRUWCPRNKVILVKJMHRMIGADYXJHZDTXYGXGHLFXIKH PCGGPUHGQQPUESTIHVZRTMIOIWCDDBVZVMSLWKKVPAMFPADMXFWZXZXJFCTASKJMXYQVF QTCECCBBVWGJMGLSIVWIOIEGIGICTCAISIJOICFXICVHFPMCVXHRKQECZWLEPPZWZDQJIVRUW KZMXJQHVEICKABNECXDJEFTBPYKLOCGLWYCDTIITQUTPQGQZIHRKRTPJIJQNXUXVTMHAJFTB DBVZUBHYITGVISCIWZPSXFWZXZQYCAPSWFFMKLPFRMSHRUKBUVGLUMHVRGTWBVXZPOUV PBNWGLEEFBGHHZVQDUWKJMBHMECBIYETVQDUWRTMIOISTICJEJVTTALVRIXUXVFUDUEJVM GPIJKVCVVKJMGUQFNLPCMRVZPUWPNDPUMRUEDVHVPKWBVTJMHVVKJMBLVIAKTTIKGZNPR JCXPUXRTWBHRZCPPZECUWCHXLTIAASLTQHAMTCBIYETVQDUWJWKWHWKJMSHRLDMSLPKC BWLMIQVVHXVUARHVZUWPYETCDTHRUQBWLVTCDTZMEVPTHTLUMCPQFWVIHMEUBWYSLI PXAWTQUESIOHCCJXZQVHALIQCVOMKUXDZMKKWCPRKJMRVYEVZNHRUVPTUYDGZDBWFDRT JXZXMHVJYKAIVVZEIAHRUCZROMKGKIBVRNDPSYVCVSMSIOICFSKJMGYIRUWCZFLEPPYIJVQHV RVQNIOIDCQCASLTQHAGVPBTYWFHZDTEEKIQBGYCZTZXZUKWHVREBTYMQGLQFEEGKALGKK KBPBFHIGJLZVMRAYICTHACCGAUYSDVPTVPUEWJYXMGAIPKVUWUALVHQUAIVPBWJIEVCGFTR NIRLSWXTPKXYGQBWECGZLOSNCAIOIWQCCKIIQNIOITKBNHRUYPDPWRNADALVUWJYGVQNX UWGKZPAMFPNDYHICKJSEKQWGALFFWMJLLTKWLWJGKDUHVOXXYIJVGALZZNTPZLVCDNZXR NQCPWKCZROMKGKIBVVQNIOITQUBBRZUBELVZQLPUHVPLXUKNKBWALVRIAHGVQNIOIGCZA PEDGVIHLLIMQBMCFQCNAZVPHPBKJWJZEEFZDVQJVPTZITQVSSEIIMHAAFTTSDMUGIUAIIVPT . Rule: pick items left to each letter. Decipher the following message knowing that the chosen password was ´POVESTE´: BM CI AS AB (i) BM – Shape: rectangle.3.

Analyzing the “signature” of the first group of sampled cipher text symbols. we can assume that the length of the key KL = 6. Unique. as shown in the following). . groups in which the letters have all been encrypted with a common keyword letter are computed. as for the entire “signature”. Thus.In our example: The “signature” for groups of the sampled cipher text symbols...e. For the group containing these cipher text letters. (ii) Find the elements of the key: . wrapping from the left edge of the graph to the right when necessary. perform a -positions right cyclic shift of the cipher text and count the number of positions in which they are the same. shifting the “signature” of a group.. computed for = 1. ´C´ = 2 … ´Z´ = 25. one can continue and find each and every letter of the key (i.e.e. the cipher text is resampled at each position. for a particular keyword letter. Match. screening more carefully group’s “signature”. high frequency.e. resp. visually. as it is the most frequent symbol in English plain-texts). i.. k 1 2 3 4 5 6 7 8 9 10 matches 13 8 8 13 11 19 10 7 10 6 Screening the table above (i. . the “signature” of the sampled cipher text symbols with the one of a usual English written plain-text2. Doing this for each group should allow the entire keyword to be determined one letter at a time.e.e.132 value marked with red) and jump to the false conclusion that it matches letter ´E´ (i. with a two-position left circular shift) the “signature” of a usual English written plain-text for the same interval. as most matches are found for a shift of six positions.. looking for where it aligns as closely as possible with the one of ordinary English. 2 With the correspondences ´A´ = 0. where represents the largest likely key length. b. In fact. if the “signature” of the group is shifted to the left the same number of positions.10).e.. ´B´ = 1. c.e.. [Example given in Appendix A].. WIEVIVVRSWKDCMECQHSSTCBTKMEVPTUSIVPTYRGCZIVJIQUPUMRKVCVVKJETZXVTVBVPUCD XHTZEBJYIJSCTTSLPBPPRFWAGLKZQVLPXYGBWUSXTIEOMTVZPKMKKWCZXYCBAPZVQVJUECV MGLHSWKDCMECAIHRUUWJAFVEIJZIFHQIZHPPIBPGKQCGPWKKKPJXZXQIFXYCVZZTIKUPYMCA BDPXJOWCHWKGZXLWKJMUPZVOWCHWKGZXLWNKBWLBKGZXVVGCQCAMEIEWPGYYMGLEUF MSASKJMLVVCFBDBVZUBXJLVTQIHKVRZTZIIXMIOIZTKWHVREBTYMJVQRZEWVMGTSIGBW HRWQCGOYEFZTKEEFNXMXPAMPYW Assuming that we have enough cipher text. of the sampled cipher text symbols) is plotted.. the 0. . Applying the same reasoning. For each group. For = 1. . the histogram (i. for a usual English written plain-text are plotted. the frequencies pattern which starts with the 3rd position and finishes with the 11th one matches better (i. breaking Vigenère assumes: (i) Find the length of the key: For = 1. the “signature” should be as closely aligned as possible with the one of ordinary English written plain- text. Thus. can help identify the keyword letter that produced the shift. all cipher text’s letters encrypted with will be shifted to the right the corresponding number of positions. first keyword’s letter is ´C´. i. one can notice a unique high frequency peak on the 3rd position (i.Graphical method: a. peaks or frequencies pattern are tracked within the matching procedure. OBS: This method proves to be inefficient in case of small size cipher texts in which case is quite difficult to match cipher text’s histogram with typical English text’s histogram.

074 0.5% 1.010 E 0.030 F 0.000 0.051 0.068 U 0.8% 4.027 J 0.091 R 0.037 0.003 0.088 0.101 0.105 W 0.112 0.024 0.000 0.020 0.003 0.085 0.000 0.101 0.3% 9.027 0.0% 6.098 0.034 0.2% 1.088 0.061 0.081 0.010 0.057 0.003 0.088 0.024 P 0.000 0.003 0.003 0.027 0.007 0.007 Z 8.112 0.047 0.030 0.081 H 0.041 0.057 0.1% 7.041 0.000 0.017 0.8% 1.003 0.081 L 0.034 0.125 0.003 0.014 0.014 0.1% 6.014 0.7% 7.027 0.007 0.010 0.020 0.020 0.068 V 0.024 0.7% 2.081 0.014 0.054 0.000 0.020 0.014 0.071 0.078 0.064 0.000 N 0.014 0.044 Q 0.8% 4.098 0.081 0.048 0.2% 0.027 0. A 0.000 0.010 0.010 0.000 0.078 0.024 I 0.095 0.000 0.0% 2.020 0.007 0.034 0.027 X 0.041 0.088 0.027 0.041 0.000 0.9% 0.068 0.034 0.000 0.2% 2.000 0.010 0.088 0.075 0.010 0.054 0.000 M 0.2% 0.007 0.017 Y 0.000 0.034 0.010 0.085 0.3% 12.132 C D 0.091 0.000 .014 0.4% 0.014 0.000 0.014 0.5% 2.0% 0.054 0.081 0.2% 2.071 0.088 0.1% 2.003 T 0.000 0.071 0.020 0.030 0.027 S 0.0% 6.020 0.041 0.014 0.027 0.071 0.088 0.003 0.041 0.108 0.010 B 0.030 0.041 G 0.000 0.027 0.027 0.010 0.0% 0.030 0.000 0.4% 6.000 0.010 0.108 0.078 0.054 K 0.074 0.105 0.003 0.003 0.030 O 0.0% 2.

0372. 0. 0. 0. compute the probabilities of each sampled cipher text symbols.0676.. 0.. we will measure how close these two vectors are:  For = 1.0225.1047.0439.0000. For the first group the maximum dot product between the two vectors is found at 3rd position and thus the first keyword’s letter is ´C´. = [0. 0.e.0034. 0. during the 3 ×90° clockwise rotation cycles.0254.In our example: The characters’ probabilities vectors for a usual English written plain-text and of the first group (i.0550. groups in which the letters have all been encrypted with a common keyword letter are computed. 0.0479.0304.0811.0013..0413. then value is the best guess of the key symbol (i.1318. 1. composed of 9 hatched/punched/transparent cells) these are the steps that must be followed: (i) Starting with the outer cells’ square.e. For = 1. 0. 0.0912.0446. i. 0.0361. 0. 0. 0. 0. 0. 0. all cells (i. the symbol associated with the group).0645.0402. This steps is showcased graphically in Fig.e. 0.0617. 26 circularly shift (i. If the procedure is repeated.0317. 0.0427.0150. 0. 0.0254. 0. the keyword letter associated to each group is found.0421. 0.0431. c.0676.0821.0319. 0.0006].0000. = [0.0009. 0..0676.0334..0767. 0. 0.e.0291. 0..0321.e.0236. 0. 0.0101.0270.0208.0163. .0362. 0. to the right) the vector and compute the dot product between the two vectors. R: CIPHER A.0320.0018. 0.0389. for = 1) are: = [0. 0. 0.0313.0405.0811.0270.Mathematical method3: a.0068. 0. 0. 0.0236. 0. .e. With and representing characters’ probabilities vectors for usual English written plain-text. 0. 0. b. 0.0270. 0.0419. 0.0195. resp.0349.0355.1237. a maximum of five hatches must be chosen so that. 0. 0. 0.0475. 3 Subsequent MATLAB R2014b is presented in APPENDIX B . 0. 0. 0. 0. 0.0230.0304. of the outer square) to be covered while avoiding overlapping them. 0. 0. 0.0351]. For each group. 0. 0. the cipher text is resampled at each position.0705.  If one value of makes the value of the product significantly larger than any other.0649. 0. 0.0393.0541..0169.0087. . 0. 0.0310. a group. 0.4. 0. 0.0000. 0. 0.0382. 0. Richelieu Cipher 1. no.0335.0000].0430. Design you own encryption grid and cipher the following plain-text: ARGHEZI A FOST UN MARE POET NATIONAL Being given an 6 ×6 Richelieu encryption grid and knowing that for 3 ×90° clockwise rotation cycles all grid’s cells should be covered by the chosen pattern (i.0921.0087. 0. 0. 0. 0. 0. 0. 0.0101. 0. 0. 0.

e. This steps is showcased graphically in Fig. . no. the cells of the inner square to be covered while avoiding overlapping them. Fig. 2 – 2nd outer square: a). gray color) and their “image” during the rotation cycles (i. red color): b)...e. during the clockwise rotation cycles.g. the cells of the 2nd outer square to be covered while avoiding overlapping them. no.e. a) b) c) Fig. outcome of the second step (i... chosen hatches (i. Reading / writing is going through rows. 3.e. gray color) and its “image” during the rotation cycles (i. chosen hatches (i. a) b) c) d) e) Fig.e. no. no. as shown below. during the 3 ×90° clockwise rotation cycles.e. outcome of the third step (i. during the decryption process) of multiple consecutive blank spaces.e. starting with a 0° rotation)..e. red color): b) ÷ d). outcome of the first step: e) (ii) Starting with the 2nd outer cells’ square. red color): b).e.e. an underscore or backslash) in order to simplify the reading (i.. a maximum of three hatches must be chosen so that. 1 – outer cells’ square: a). This steps is showcased graphically in Fig. This procedure applies for all 3 ×90° clockwise rotation cycles (i.. from up to down and from left to right. only one hatch remains to be chosen so that.e. including the first one): c) (iii) Starting with inner cells’ square.. chosen hatch (i. a) b) c) Fig. including the first two): c) Encryption process itself involves overlapping the encryption grid (i. no. For each read of a blank space.c)) over the plain-text grid and reading / writing letter that are overlapped by hatches.. no. a marker in inserted (e. 3 – inner square: a). 3... gray color) and their “image” during the rotation cycles (i.. 2.

APPENDIX F) . det( ) = 7.. i.. removing spaces within...5. is computed as follows: = [87 69 76 79 86 69 77 65 84 72]. 12 5 20 8 (iii) Multiply. i. hereafter denoted E. Message’s associate matrix. = [23 5 12 15 22 5 13 1 20 8 8 8].. i.e. 26) → [1. modulo 26. 7 is invertible5 modulo 26 → E is invertible. −11. as to verify the hypothesis ‘det(E) is invertible’: 13 22 10 = 9 3 16 . R: ARA_FSMEIGHZIONR_NE__PET_AL_TUAOATON A. ] = gcd(7. cipher the message: WE LOVE MATH Encryption with the Hill Cipher4: (i) Choose an encryption matrix and verify that it is invertible Being given the encryption matrix.e. Using a 3×3 encryption key.. 23 15 13 8 = 5 22 1 8. (ii) Format the message (i.e. the encryption matrix with message’s associated matrix The resulted cipher text’s associated matrix. 26) → 7 ≡ −11( 26) ≡ 15 (i.e. det(E) must be computed. 4 6 22 26 4 Subsequent MATLAB R2014b is presented in APPENDIX C 5 [ .e. hereafter denoted M. twice. hereafter denoted EM is: 9 1 1 22 = 24 21 24 16 . padding if necessary and converting message chars to equivalent integer number) The length of the message does not factor by 3 and thus it is padded. 23 13 5 det( ) ( 26) ≡ 7.e. Hill Cipher 1. with the last char within. i. . Euclidian Algorithm. 3] = gcd(7.

. i. convert associated matrix’s elements from integer numbers to equivalent alphabet letters): The resulted cipher text is: R: IXDAUFAXVVPP 2 3 15 2.. −7.e. APPENDIX F) . the deciphering matrix must be computed 7 .. i. 19 5 5 15 16 21 = 17 4 9 2 25 1 .e..Compute det(E) and find its reciprocal.e. knowing the encryption matrix. 26) → 11 ≡ −7( 26) ≡ 19. convert associated matrix’s elements from integer numbers to equivalent alphabet letters): The resulted cipher text is: R: CRYPTOGRAPHYISCOOL 6 Subsequent MATLAB R2014b is presented in APPENDIX D 7 http://www.(iv) Format the cipher text (i.. i. 25 15 1 25 3 12 (iv) Format the plain text (i. (i. modulo 26: det( ) ( 26) ≡ 11. the decryption matrix with cipher text’s associated matrix The resulted plain text’s associated matrix. i.jsp?id=2de311966212471dec23077dd840840d 8 [ . ] = gcd(11. hereafter denoted DC is: 3 16 7 16 9 15 = 18 20 18 8 19 15 . 57/583 −23/583 1/583 57 23 1 . Compute the deciphering matrix. . 57 23 1 17 5 19 (ii) Format the cipher text message Cipher text’s associate matrix.e. (det( ) ∙ ( ))( 26): −124 183 −84 10 19 16 = 19 ∙ −8 −7 51 ( 26) = 4 23 7 ..e. Compute inv(E) and rationalize if necessary: −124/583 183/583 −84/583 −124 183 −84 inv( ) = −8/583 −7/583 51/583 = −8 −7 51 . modulo 26. Decipher the following message knowing that the encryption key was = 5 8 12 : 1 13 4 SQYEDXEIKOBLPYHUAX Decryption with the Hill Cipher6: (i) Firstly. 26) → [1. hereafter denoted C.e..com/widgets/view. 25 24 11 12 8 24 (iii) Multiply. Euclidian Algorithm.. i. . is computed as follows: = [83 81 89 69 68 88 69 73 75 79 66 76 80 89 72 85 65 88].e. 11 is invertible8 modulo 26.e.wolframalpha. 3] = gcd(11.

5 6 1 4 3 2 R E Q U E S T R E I N F O R C E M E N T S I M M E D I A T E L Y X X X X The resulted cipher text is: R: QECSI XSFEM EXENM MTXUI EIAXR TONEL ERRTD Y . e. in our case) and extracts ciphertext by columns. 4. equal with key’s length.e. cipher the message: ELECTRIC HOTPLATE At its simplest. 2). columnar transposition enters the plaintext (i. 1.. Using the keyword ORANGE cipher the message: REQUEST REINFORCEMENTS IMMEDIATELY The numerical key associated with the keyword ORANGE is = (5. in the order determined by the numerical key.. 2 1 3 E L E C T R I C H O T P L A T E X X The resulted cipher text is: R: LTCTA XECIO LEERH PTX 2. is written horizontally) into a rectangle of a predetermined width (i.6. Numerically-Keyed Columnar Transposition 1. 1. 3). 3.e. 6. = 3..g. Using the numerical key = (2.A.

0222. 0. 0. 0.0000. 0. 0. 0. 0.0667. perform a -positions right cyclic shift of the cipher text and count the number of positions in which they are the same.0087.0013.0222.0369. 0.0329.1778.0645.0291. 0.0150.1333. 0. For the first group the maximum dot product between the two vectors is found at 3rd position and thus the first keyword’s letter is ´C´.0225.0163.0195. 0. 0.0821. APPENDIX A 1. 0.0254. 0.0270. 0.0444.0358. 0. 0. 0.e. 0. 0.1237. where represents the largest likely key length.0297.e.0444.0444. 0.0889. the keyword letter associated to each group is found. 0.0000.0302.10).0550. 0. . 0.0516.0479. 0. 0.0000. 0. . 0. 0. 0. 0. 0. 0. 0.0018. 0. 0. 0. 0.0208. = [0. 0.0397.0593. 0.0436.0393.0320. 0.0566.0358.0000.0222.0256. 0. 0.0254.0415.0676. 0. computed for = 1. 0. = [0. k 1 2 3 4 5 6 7 8 9 10 matches 13 8 8 13 11 19 10 7 10 6 Screening the table above (i. 0. 0. 0.0767.0889.0377.0413.Mathematical method: The characters’ probabilities vectors for a usual English written plain-text and of the first group (i.0000.0230.0341. 0. 0. 0. Find the password with which the following cipher text was obtained: EZNWXFUGHAIDUATJYIKBNHRUTWQBWKPMHZARUIHZIJUMSDMKJBWLEZFWUCEI KWJZQVVPDKWJWKWHWBGGHWETGICKOVAAHLRJKBXCMKABDZQRNTROEEIMHH RRNGHLWUKNULVVPBXHPRPLHAEKKAIPGRNICHPPUMHLXTCVSALVEWGYIJRWCK MEIMMWIIKUTUXRNZTZYCVAHOSNGLIOEKVPTWVFRWHLHZOIVLGIAXIVWPUBTTL RUISLWZTIQSICGDTSSWUMRBVZVG (i) Find the length of the key: For = 1. 0..0087.0006].0000.0000. 0.0362.Graphical method: Being difficult to match cipher text’s histogram with typical English text’s histogram the graphical method proves to be inefficient. 0. 0. 0.0667. 0. 0. 0. 0.0705. 0. 0. as most matches are found for a shift of six positions..0222. 0.0299].0427. R: CIPHER . 0. 0.0617.0222. 0.0320.0435. 0. If the procedure is repeated. 0. 0.0401.0444.0009. we can assume that the length of the key KL = 6. for = 1) are: = [0.0000]. 0. (ii) Find the elements of the key: . 0.0889. 0. 0. 0.0375.0000.0921.0000.0367. 0.

000 R 0.046 0.046 0.000 0.000 0.000 0.114 0.068 0.000 0.000 0.0% 2.000 I 0.023 0.000 0.022 0.000 0.8% 4.000 0.4% 6.022 K 0.8% 4.023 0.136 0.000 0.000 T 0.0% 0.7% 7.091 0.067 Q 0.8% 1.000 0.000 0.133 0.2% 0.0% 0.046 0.000 0.068 0.023 0.022 P 0.000 0.133 0.000 Z 8.044 0.022 0.000 0.182 0.023 0.046 0.068 0.000 0.000 0.068 0.023 0.0% 6.000 0.046 0.136 0.023 0.089 H 0.000 0.023 0.1% 6.022 0.023 0.000 0.046 0.000 0.000 0.250 0.000 0.2% 2.000 0.114 0.0% 2.068 0.2% 2.046 0.159 0.022 X 0.000 0.023 0.046 0.046 0.023 0.023 0.000 0.089 0.7% 2.044 J 0.000 0.023 0.000 Y 0.044 S 0.000 0.114 0.046 0.000 .023 0.5% 1.000 0.3% 9.3% 12.133 L 0.000 0.000 0.133 0.091 0.000 0.9% 0.136 0.044 U 0.000 0.000 0.000 0.068 0.091 0.089 W 0.022 0.2% 1.046 0.000 0.091 0.0% 6.023 0.089 O 0.046 0.000 0.4% 0.114 0.068 0.000 0.1% 2.046 0.091 0.000 0.022 C D 0.000 0.022 0.178 V 0.023 0.089 0.046 0.022 G 0.068 0.068 0.000 0.046 0.1% 7.023 0.133 0.044 F 0. A 0.000 0.5% 2.000 0.046 0.022 0.046 0.068 0.000 0.046 0.000 0.000 0.000 0.000 M 0.000 0.046 0.000 0.067 B 0.000 0.000 E 0.044 0.044 0.046 0.046 0.2% 0.000 N 0.022 0.046 0.023 0.023 0.000 0.

%Compute the Key Length. 26). 266). Cipher_Text = Cipher_Text'. %Open and read the cipher text.0. [0.0617.txt'. English_Text_Frequencies = circshift(English_Text_Frequencies.0195. Change file path if necessary Cipher_Text = textread('H:\Educational Activities\Applied Computer Sciences\ Criptograpy and Information Security\Vigenere\Short_Ciphertext.0.0676.0. Cipher_Text(j)-64) = Cipher_Text_Groups_Frequencies (i.0150. APPENDIX B clear.0. Cipher_Text(j)-64) + 1.0.0006].:)))+64)). 0. '%c'.0.0. for i = 1 : Key_Length for j = 1 : 26 Closeness_Matrix(i.0087.0479. 0. Closeness_Matrix = zeros(Key_Length.0.:) = Cipher_Text_Groups_Frequencies(i.char(find(Closeness_Matrix(i. English_Text_Frequencies).0393.0225.0087. k]))).0645.0009. 0.0254.0230.0208.0.0. 26).0. end Key_Length = find(Matches == max(Matches)). Cipher_Text = circshift(Cipher_Text.0163. end end %Compute the KEY KEY = 'The encryption key was: '.0.0254. [0.:)).:)==max(Closeness_Matrix(i.0. %Compute frequencies for the symbols within groups of resampled cipher text Cipher_Text_Groups_Frequencies = zeros(Key_Length. for i = 1 : Key_Length KEY = strcat(KEY.0550.0767.0. for i = 1 : Key_Length for j = 1 : Key_Length : length(Cipher_Text) Cipher_Text_Groups_Frequencies (i. clc.0.0. Cipher_Text = double(Cipher_Text).0. [0.0.:)/sum(Cipher_Text_Groups_Frequencies(i. here 10 is considered the maximum possible for k = 1 : 10 Matches (k) = length(find(Cipher_Text == circshift(Cipher_Text.0.0821.0921.j) = dot(Cipher_Text_Groups_Frequencies(i.0018.0. end %Measure 'closeness' within each group and typical English_Text_Frequencies English_Text_Frequencies = [0.0. -1]).0013. end Cipher_Text_Groups_Frequencies (i.0705.1237. 1]). end KEY .0291.:).0.

i. %%If this is so.e. 23 13 5]. Plain_Text(length(Plain_Text))]. Plain_Text(length(Plain_Text))]. Reciprocals(1. the encryption key) %Ciphering_Matrix = [2 3 15. Plain_Text(length(Plain_Text))]. 1 9 21 15 3 19 7 23 11 5 17 25]. 5 8 12.. Plain_Text = double(Plain_Text). for j = 1 : uint8(length(Plain_Text)/3) for i = 1 : 3 Cipher_Text = strcat(Cipher_Text. %For 'CRYPTOGRAPHYISCOOL' Ciphering_Matrix = [13 22 10. Plain_Text = Plain_Text'. associated with the plain-text) Plain_Text = Plain_Text . APPENDIX C clear.3) == 2 Plain_Text = [Plain_Text. Reciprocals =[1 3 5 7 9 11 15 17 19 21 23 25. pad the ending with the last charachter within the message. for i = 1 : uint8(length(Plain_Text)/3) Message_Matrix (:. '%c'. uint8(length(Plain_Text)/3)).64.j))+64). end %%Encrypt the message. end end Cipher_Text else end . 26).26)). multiply the two matrices Cipher_Matrix = Ciphering_Matrix*Message_Matrix. %%Open and read the plain-text Plain_Text = textread('H:\Educational Activities\Applied Computer Sciences\ Criptograpy and Information Security\Hill\Plain_Text.txt'. It should be a multiple of three. %Ciphering_Matrix = randi(26. if mod(length(Plain_Text). 3). Cipher_Matrix = mod(Cipher_Matrix.. %Random matrix generation %%Check if matrix determinant is invertible modulo 26. %%Format and display the cipher text Cipher_Text = 'The cipher text is: '. generate a new one.char(Cipher_Matrix(i.3) == 1 Plain_Text = [Plain_Text. clc. 266). %%If not. if ismember(CM_Determinant.:)) %%Verify the length of plain-text.. 1 13 4].e.i) = Plain_Text(((i*3)-2):(i*3))'.e. Message_Matrix = zeros (3. Plain_Text = [Plain_Text. %%Choose the ciphering matrix (i. use the matrix ! Else. elseif mod(length(Plain_Text). end %%Compute the message matrix (i. CM_Determinant = uint8(mod(det(Ciphering_Matrix). 9 3 16.

Cipher_Text = double(Cipher_Text). 9 3 16.e. 26). 23 13 5]. %%Format and display the cipher text Deciphered_Text = 'Deciphered text is: '. %%Multiply the Determinant_Rec with Ciphering_Matrix Deciphering_Matrix = mod(Determinant_Rec*Deciphering_Matrix. find(Reciprocals(1.:)==CM_Determinant)). %%Compute the cipher text's matrix Cipher_Text = Cipher_Text . %%Open and read the plain-text Cipher_Text = textread('H:\Educational Activities\Applied Computer Sciences\ Criptograpy and Information Security\Hill\Cipher_Text. end %%Decrypt the message. %%Compute the inv(Ciphering_Matrix).26)). '%c'. 1 13 4]. for i = 1 : uint8(length(Cipher_Text)/3) Cipher_Text_Matrix (:. i..j))+64). 5 8 12. Determinant_Rec=Reciprocals(2.e. %%Knowing the ciphering matrix (i..txt'. Set the format to 'rat' Deciphering_Matrix = inv(Ciphering_Matrix).64. clc. Deciphered_Matrix = uint8(mod(Deciphered_Matrix. %%Rationalize this matrix %%Use debugging mode to change '583' Deciphering_Matrix = Deciphering_Matrix * 5077. for j = 1 : uint8(length(Cipher_Text)/3) for i = 1 : 3 Deciphered_Text = strcat(Deciphered_Text. end end Deciphered_Text . multiply the two matrices Deciphered_Matrix = Deciphering_Matrix*Cipher_Text_Matrix. uint8(length(Cipher_Text)/3)). Cipher_Text = Cipher_Text'. the encryption key) compute its inverse %%Compute det(Ciphering_Matrix) CM_Determinant = uint8(mod(det(Ciphering_Matrix). %Ciphering_Matrix = [2 3 15. Ciphering_Matrix = [13 22 10. 26)). 266).i) = Cipher_Text(((i*3)-2):(i*3))'. clear.char(Deciphered_Matrix(i. clc. APPENDIX D clear. %%Find the determinant's reciprocal modulo 26 Reciprocals =[1 3 5 7 9 11 15 17 19 21 23 25. Cipher_Text_Matrix = zeros (3. 1 9 21 15 3 19 7 23 11 5 17 25].

41% O 9.26% N 6.75% O 7.62% I 7.14% C 5.87% E 13.59% I 12.25% U 6. APPENDIX E Engleză Frecvenţă Română Frecvenţă E 12.18% N 6.44% S 6.44% R 6.04% T 9.25% R 6.50% H 5.90% S 7.42% A 12.15% A 9.39% N 7.05% E 11.47% Franceză Frecvenţă Spaniolă Frecvenţă E 15.89% A 8.60% T 7.69% I 8.46% I 6.49% S 7.58% .31% A 13.15% R 6.24% L 5.34% D 5.95% N 7.94% L 5.19% T 6.03% S 5.59% U 6.94% R 7.

1 ≡ 7(−11) mod 26 ≡ mod 26. Then has a unique multiplicative inverse modulo and it can be computed using the Euclidean Algorithm (i. ) = . 1 ≡ 11(−7) mod 26 ≡ mod 26. as in the following example):  7 mod 26 26 = 7(3) + 5 5 = 26 − 7(3) 7 = 5(1) + 2 2 = 7 − 5(1) 5 = 2(2) + 1 1 = 5 − 2(2) 2 = (2) 1 = 5 − 2(2) = 5 − 7 − 5(1) (2) = 5 − 7(2) + 5(2) = 5(3) − 7(2). 1 = 26 − 7(3) (3) − 7(2) = 26(3) − 7(9) − 7(2) = 26(3) − 7(11) = 26(3) + 7(−11).e. . 1 = 26 − 11(2) (3) − 11(1) = 26(3) − 11(6) − 11(1) = 26(3) − 11(7) = 26(3) + 11(−7). two positive integers such that ( . APPENDIX F Let and .  11 mod 26 26 = 11(2) + 4 4 = 26 − 11(2) 11 = 4(2) + 3 3 = 11 − 4(2) 4 = 3(1) + 1 1 = 4 − 3(1) 1 = (1) 1 = 4 − 3(1) = 4 − 11 − 4(2) (1) = 4 − 11(1) + 4(2) = 4(3) − 11(1)..