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 texts 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 texts 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 texts 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
Guessing can continue; however, the problem is much simpler than it looks. Looking at the cipher text one
can find the singular T symbol (i.e., 5th row). So, we should wonder: (i) which are the symbols more likely
to appear alone (e.g., a, as in a car or I, as in I am) in an English plain-text (i.e., as long as possible);
(ii) between these symbols which has the highest probability (i.e., to appear alone in a plain-text, as long
as possible). Answering these two questions, one can correctly conclude that, with the highest probability,
T replaces A. 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, DIFFERENTIAL AND STATISTICAL ANALYSES ETC. AND THE
CORRESPONDING EXPERIMENTAL RESULTS SHOWED THAT THE PROPOSED IMAGE
CRYPTOSYSTEM HAS A DESIRABLE LEVEL OF SECURITY.

OBS: To counteract the final case (i.e., where the link between the plain-text and the cipher text is
betrayed by a single symbol), usually, the cipher text: (i) is divided into equal size blocks (with the final
one padded, if it hasnt the proper size); (ii) is given as a single, continuous, block.

3. 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, KEY=F (i.e., in alphabets symbols) or 5

A.2. Playfair Cipher


1. Decipher the following message knowing that the chosen password was PASSWORD:
PM MP QL PF HQ HV

(i) PM Shape: rectangle; Rule: pick the opposite corners; Result: AL


(ii) MP Shape: rectangle; Rule: pick the opposite corners; Result: LA
(iii) QL Shape: on the same row; Rule: pick items left to each letter (i.e., wrap to left); Result: NT
(iv) PF Shape: on the same column; Rule: pick items up to each letter (i.e., wrap to up); Result: UR
(v) HQ Shape: rectangle; Rule: pick the opposite corners; Result: IN
(vi) HV Shape: rectangle; Rule: pick the opposite corners; Result: GX (i.e., with padded X)

P A S W O

R D B C E

F G H I,J K

L M N Q T

U V X Y Z

R: ALLAN TURING
2. Decipher the following message knowing that the chosen password was POVESTE:
BM CI AS AB

(i) BM Shape: rectangle; Rule: pick the opposite corners; Result: AN


(ii) CI Shape: on the same column; Rule: pick items up to each letter; Result: EC
(iii) AS Shape: rectangle; Rule: pick the opposite corners; Result: DO
(iv) AB Shape: on the same row; Rule: pick items left to each letter; 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.3. Vigenre Cipher


1. 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. 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
WIEVIVVRSWKDCMECQHSSTCBTKMEVPTUSIVPTYRGCZIVJIQUPUMRKVCVVKJETZXVTVBVPUCD
XHTZEBJYIJSCTTSLPBPPRFWAGLKZQVLPXYGBWUSXTIEOMTVZPKMKKWCZXYCBAPZVQVJUECV
MGLHSWKDCMECAIHRUUWJAFVEIJZIFHQIZHPPIBPGKQCGPWKKKPJXZXQIFXYCVZZTIKUPYMCA
BDPXJOWCHWKGZXLWKJMUPZVOWCHWKGZXLWNKBWLBKGZXVVGCQCAMEIEWPGYYMGLEUF
MSASKJMLVVCFBDBVZUBXJLVTQIHKVRZTZIIXMIOIZTKWHVREBTYMJVQRZEWVMGTSIGBW
HRWQCGOYEFZTKEEFNXMXPAMPYW
Assuming that we have enough cipher text, breaking Vigenre assumes:
(i) Find the length of the key:
For = 1, , where represents the largest likely key length, perform a -positions right
cyclic shift of the cipher text and count the number of positions in which they are the same.

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.e., computed for = 1,10), as most matches are found for a
shift of six positions, we can assume that the length of the key KL = 6.

(ii) Find the elements of the key:


- Graphical method:
a. For = 1, , the cipher text is resampled at each position, i.e., groups in which the
letters have all been encrypted with a common keyword letter are computed;
b. For each group, the histogram (i.e., of the sampled cipher text symbols) is plotted;
c. Match, i.e., visually, the signature of the sampled cipher text symbols with the one of a
usual English written plain-text2. Unique, high frequency, 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 texts histogram with typical English texts histogram. [Example given in Appendix A].

- In our example:
The signature for groups of the sampled cipher text symbols, resp., for a usual English
written plain-text are plotted.

Analyzing the signature of the first group of sampled cipher text symbols, one can notice a
unique high frequency peak on the 3rd position (i.e., the 0.132 value marked with red) and
jump to the false conclusion that it matches letter E (i.e., as it is the most frequent symbol
in English plain-texts). In fact, screening more carefully groups signature, the frequencies
pattern which starts with the 3rd position and finishes with the 11th one matches better (i.e.,
with a two-position left circular shift) the signature of a usual English written plain-text for
the same interval, as for the entire signature. Thus, first keywords letter is C.

Applying the same reasoning, one can continue and find each and every letter of the key (i.e.,
as shown in the following).

2 With the correspondences A = 0, B = 1, C = 2 Z = 25, for a particular keyword letter, all cipher texts letters encrypted
with will be shifted to the right the corresponding number of positions. For the group containing these cipher text letters, if
the signature of the group is shifted to the left the same number of positions, wrapping from the left edge of the graph to
the right when necessary, the signature should be as closely aligned as possible with the one of ordinary English written plain-
text. Thus, shifting the signature of a group, looking for where it aligns as closely as possible with the one of ordinary English,
can help identify the keyword letter that produced the shift. Doing this for each group should allow the entire keyword to be
determined one letter at a time.
A
0.000 0.007 0.081 0.034 0.054 0.010

B
0.003 0.010 0.041 0.037 0.108 0.000
0.034 0.010 0.014 0.078 0.030 0.132 C
D

0.027 0.000 0.003 0.088 0.030 0.010


E

0.075 0.091 0.000 0.010 0.014 0.030


F

0.064 0.007 0.024 0.000 0.000 0.041


G

0.027 0.041 0.000 0.074 0.007 0.081


H

0.000 0.027 0.112 0.068 0.000 0.024


I

0.088 0.112 0.014 0.098 0.088 0.027


J

0.061 0.010 0.041 0.034 0.000 0.054


K

0.105 0.020 0.020 0.014 0.057 0.081


L

0.048 0.041 0.085 0.014 0.017 0.000


M

0.010 0.101 0.010 0.003 0.125 0.000


N

0.014 0.003 0.003 0.020 0.027 0.030


O

0.003 0.000 0.051 0.000 0.003 0.024


P

0.010 0.024 0.088 0.098 0.047 0.044


Q

0.003 0.027 0.000 0.014 0.078 0.091


R

0.071 0.071 0.007 0.027 0.003 0.027


S

0.020 0.071 0.034 0.030 0.000 0.003


T

0.054 0.014 0.030 0.108 0.027 0.068


U

0.034 0.000 0.081 0.027 0.020 0.068


V

0.095 0.071 0.085 0.010 0.081 0.105


W

0.020 0.088 0.014 0.054 0.074 0.027


X

0.010 0.101 0.000 0.057 0.020 0.017


Y

0.041 0.041 0.078 0.000 0.000 0.007


Z
8.2% 1.5% 2.8% 4.3% 12.7% 2.2% 2.0% 6.1% 7.0% 0.2% 0.8% 4.0% 2.4% 6.7% 7.5% 1.9% 0.1% 6.0% 6.3% 9.1% 2.8% 1.0% 2.4% 0.2% 2.0% 0.2%

0.081 0.014 0.088 0.003 0.088 0.000


- Mathematical method3:
a. For = 1, , the cipher text is resampled at each position, i.e., groups in which the
letters have all been encrypted with a common keyword letter are computed;
b. For each group, compute the probabilities of each sampled cipher text symbols;
c. With and representing characters probabilities vectors for usual English written
plain-text, resp., a group, we will measure how close these two vectors are:
For = 1, 26 circularly shift (i.e., to the right) the vector and compute the dot
product between the two vectors;
If one value of makes the value of the product significantly larger than any other,
then value is the best guess of the key symbol (i.e., the symbol associated with the
group).

- In our example:
The characters probabilities vectors for a usual English written plain-text and of the first
group (i.e., for = 1) are:

= [0.0821, 0.0150, 0.0230, 0.0479, 0.1237, 0.0225, 0.0208, 0.0645, 0.0676, 0.0018,
0.0087, 0.0393, 0.0254, 0.0705, 0.0767, 0.0163, 0.0009, 0.0550, 0.0617, 0.0921,
0.0291, 0.0087, 0.0254, 0.0013, 0.0195, 0.0006].

= [0.0101, 0.0000, 0.1318, 0.0101, 0.0304, 0.0405, 0.0811, 0.0236, 0.0270, 0.0541,
0.0811, 0.0000, 0.0000, 0.0304, 0.0236, 0.0439, 0.0912, 0.0270, 0.0034, 0.0676,
0.0676, 0.1047, 0.0270, 0.0169, 0.0068, 0.0000].

= [0.0313, 0.0382, 0.0649, 0.0402, 0.0320, 0.0319, 0.0431, 0.0317, 0.0362, 0.0427,
0.0361, 0.0321, 0.0372, 0.0419, 0.0413, 0.0430, 0.0421, 0.0475, 0.0349, 0.0310,
0.0335, 0.0389, 0.0334, 0.0355, 0.0446, 0.0351].

For the first group the maximum dot product between the two vectors is found at 3rd
position and thus the first keywords letter is C.

If the procedure is repeated, the keyword letter associated to each group is found.

R: CIPHER

A.4. Richelieu Cipher


1. 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
grids cells should be covered by the chosen pattern (i.e., composed of 9 hatched/punched/transparent
cells) these are the steps that must be followed:

(i) Starting with the outer cells square, a maximum of five hatches must be chosen so that, during the
3 90 clockwise rotation cycles, all cells (i.e., of the outer square) to be covered while avoiding
overlapping them. This steps is showcased graphically in Fig. no. 1.

3
Subsequent MATLAB R2014b is presented in APPENDIX B
a) b) c) d) e)
Fig. no. 1 outer cells square: a), chosen hatches (i.e., gray color) and their image during the rotation cycles (i.e., red
color): b) d), outcome of the first step: e)

(ii) Starting with the 2nd outer cells square, a maximum of three hatches must be chosen so that, during
the 3 90 clockwise rotation cycles, the cells of the 2nd outer square to be covered while avoiding
overlapping them. This steps is showcased graphically in Fig. no. 2.

a) b) c)
Fig. no. 2 2nd outer square: a), chosen hatches (i.e., gray color) and their image during the rotation cycles (i.e., red
color): b), outcome of the second step (i.e., including the first one): c)

(iii) Starting with inner cells square, only one hatch remains to be chosen so that, during the clockwise
rotation cycles, the cells of the inner square to be covered while avoiding overlapping them. This steps
is showcased graphically in Fig. no. 3.

a) b) c)
Fig. no. 3 inner square: a), chosen hatch (i.e., gray color) and its image during the rotation cycles (i.e., red color): b),
outcome of the third step (i.e., including the first two): c)

Encryption process itself involves overlapping the encryption grid (i.e., Fig. no. 3.c)) over the plain-text
grid and reading / writing letter that are overlapped by hatches. Reading / writing is going through rows,
from up to down and from left to right. For each read of a blank space, a marker in inserted (e.g., an
underscore or backslash) in order to simplify the reading (i.e., during the decryption process) of multiple
consecutive blank spaces. This procedure applies for all 3 90 clockwise rotation cycles (i.e., starting
with a 0 rotation), as shown below.
R: ARA_FSMEIGHZIONR_NE__PET_AL_TUAOATON

A.5. Hill Cipher


1. Using a 33 encryption key, 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, i.e., hereafter denoted E, det(E) must be computed, as to
verify the hypothesis det(E) is invertible:

13 22 10
= 9 3 16 , det( ) = 7.
23 13 5

det( ) ( 26) 7, 7 is invertible5 modulo 26 E is invertible.

(ii) Format the message (i.e., removing spaces within, 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, twice, with the last char
within. Messages associate matrix, i.e., hereafter denoted M, is computed as follows:

= [87 69 76 79 86 69 77 65 84 72].

= [23 5 12 15 22 5 13 1 20 8 8 8].

23 15 13 8
= 5 22 1 8.
12 5 20 8

(iii) Multiply, i.e., modulo 26, the encryption matrix with messages associated matrix
The resulted cipher texts associated matrix, i.e., hereafter denoted EM is:

9 1 1 22
= 24 21 24 16 .
4 6 22 26

4 Subsequent MATLAB R2014b is presented in APPENDIX C


5 [ , , ] = gcd(7, 26) [1, 11, 3] = gcd(7, 26) 7 11( 26) 15 (i.e., Euclidian Algorithm, APPENDIX F)
(iv) Format the cipher text (i.e., convert associated matrixs elements from integer numbers to equivalent
alphabet letters):
The resulted cipher text is:

R: IXDAUFAXVVPP

2 3 15
2. Decipher the following message knowing that the encryption key was = 5 8 12 :
1 13 4
SQYEDXEIKOBLPYHUAX

Decryption with the Hill Cipher6:


(i) Firstly, knowing the encryption matrix, the deciphering matrix must be computed 7
- Compute det(E) and find its reciprocal, i.e., modulo 26:

det( ) ( 26) 11, 11 is invertible8 modulo 26.

- 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 .
57/583 23/583 1/583 57 23 1

- Compute the deciphering matrix, i.e., (det( ) ( ))( 26):

124 183 84 10 19 16
= 19 8 7 51 ( 26) = 4 23 7 .
57 23 1 17 5 19

(ii) Format the cipher text message


Cipher texts associate matrix, i.e., hereafter denoted C, is computed as follows:

= [83 81 89 69 68 88 69 73 75 79 66 76 80 89 72 85 65 88].

19 5 5 15 16 21
= 17 4 9 2 25 1 .
25 24 11 12 8 24

(iii) Multiply, i.e., modulo 26, the decryption matrix with cipher texts associated matrix
The resulted plain texts associated matrix, i.e., hereafter denoted DC is:

3 16 7 16 9 15
= 18 20 18 8 19 15 .
25 15 1 25 3 12
(iv) Format the plain text (i.e., convert associated matrixs 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.wolframalpha.com/widgets/view.jsp?id=2de311966212471dec23077dd840840d
8 [ , , ] = gcd(11, 26) [1, 7, 3] = gcd(11, 26) 11 7( 26) 19, (i.e., Euclidian Algorithm, APPENDIX F)
A.6. Numerically-Keyed Columnar Transposition
1. Using the numerical key = (2, 1, 3), cipher the message:
ELECTRIC HOTPLATE

At its simplest, columnar transposition enters the plaintext (i.e., is written horizontally) into a rectangle of
a predetermined width (i.e., equal with keys length; e.g., = 3, in our case) and extracts ciphertext by
columns, 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. Using the keyword ORANGE cipher the message:
REQUEST REINFORCEMENTS IMMEDIATELY

The numerical key associated with the keyword ORANGE is = (5, 6, 1, 4, 3, 2).

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


APPENDIX A

1. 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, , where represents the largest likely key length, perform a -positions right
cyclic shift of the cipher text and count the number of positions in which they are the same.

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.e., computed for = 1,10), as most matches are found for a
shift of six positions, we can assume that the length of the key KL = 6.

(ii) Find the elements of the key:


- Graphical method:

Being difficult to match cipher texts histogram with typical English texts histogram the
graphical method proves to be inefficient.

- Mathematical method:

The characters probabilities vectors for a usual English written plain-text and of the first
group (i.e., for = 1) are:

= [0.0821, 0.0150, 0.0230, 0.0479, 0.1237, 0.0225, 0.0208, 0.0645, 0.0676, 0.0018,
0.0087, 0.0393, 0.0254, 0.0705, 0.0767, 0.0163, 0.0009, 0.0550, 0.0617, 0.0921,
0.0291, 0.0087, 0.0254, 0.0013, 0.0195, 0.0006].

= [0.0667, 0.0000, 0.0222, 0.0000, 0.0444, 0.0222, 0.0889, 0.0000, 0.0444, 0.0222,
0.1333, 0.0000, 0.0000, 0.0889, 0.0222, 0.0667, 0.0000, 0.0444, 0.0000, 0.0444,
0.1778, 0.0889, 0.0222, 0.0000, 0.0000, 0.0000].

= [0.0401, 0.0427, 0.0593, 0.0397, 0.0302, 0.0270, 0.0566, 0.0435, 0.0358, 0.0377,
0.0341, 0.0256, 0.0375, 0.0413, 0.0320, 0.0367, 0.0415, 0.0516, 0.0369, 0.0358,
0.0362, 0.0329, 0.0436, 0.0297, 0.0320, 0.0299].

For the first group the maximum dot product between the two vectors is found at 3rd
position and thus the first keywords letter is C. If the procedure is repeated, the keyword
letter associated to each group is found.

R: CIPHER
A
0.000 0.023 0.068 0.000 0.089 0.067

B
0.023 0.000 0.046 0.000 0.133 0.000
0.046 0.000 0.046 0.068 0.000 0.022 C
D

0.023 0.000 0.023 0.046 0.022 0.000


E

0.046 0.136 0.000 0.000 0.000 0.044


F

0.046 0.000 0.000 0.000 0.000 0.022


G

0.000 0.046 0.000 0.023 0.089 0.089


H

0.000 0.023 0.114 0.250 0.000 0.000


I

0.091 0.114 0.000 0.068 0.133 0.044


J

0.091 0.000 0.023 0.023 0.000 0.022


K

0.114 0.000 0.068 0.000 0.022 0.133


L

0.000 0.046 0.182 0.000 0.044 0.000


M

0.000 0.068 0.000 0.023 0.133 0.000


N

0.023 0.000 0.000 0.046 0.022 0.089


O

0.000 0.023 0.068 0.000 0.000 0.022


P

0.046 0.046 0.023 0.000 0.044 0.067


Q

0.000 0.046 0.000 0.046 0.000 0.000


R

0.159 0.068 0.000 0.046 0.000 0.044


S

0.000 0.046 0.046 0.068 0.000 0.000


T

0.046 0.000 0.023 0.136 0.022 0.044


U

0.046 0.000 0.023 0.046 0.022 0.178


V

0.091 0.068 0.023 0.023 0.022 0.089


W

0.023 0.136 0.091 0.046 0.133 0.022


X

0.000 0.068 0.000 0.046 0.022 0.000


Y

0.000 0.046 0.023 0.000 0.000 0.000


Z
8.2% 1.5% 2.8% 4.3% 12.7% 2.2% 2.0% 6.1% 7.0% 0.2% 0.8% 4.0% 2.4% 6.7% 7.5% 1.9% 0.1% 6.0% 6.3% 9.1% 2.8% 1.0% 2.4% 0.2% 2.0% 0.2%

0.091 0.000 0.114 0.000 0.044 0.000


APPENDIX B

clear; clc;

%Open and read the cipher text; Change file path if necessary
Cipher_Text = textread('H:\Educational Activities\Applied Computer Sciences\
Criptograpy and Information Security\Vigenere\Short_Ciphertext.txt', '%c', 266);

Cipher_Text = Cipher_Text';
Cipher_Text = double(Cipher_Text);

%Compute the Key Length, here 10 is considered the maximum possible


for k = 1 : 10
Matches (k) = length(find(Cipher_Text == circshift(Cipher_Text, [0, k])));
end
Key_Length = find(Matches == max(Matches));

%Compute frequencies for the symbols within groups of resampled cipher text
Cipher_Text_Groups_Frequencies = zeros(Key_Length, 26);
for i = 1 : Key_Length
for j = 1 : Key_Length : length(Cipher_Text)
Cipher_Text_Groups_Frequencies (i, Cipher_Text(j)-64) =
Cipher_Text_Groups_Frequencies (i, Cipher_Text(j)-64) + 1;
end
Cipher_Text_Groups_Frequencies (i,:) =
Cipher_Text_Groups_Frequencies(i,:)/sum(Cipher_Text_Groups_Frequencies(i,:));

Cipher_Text = circshift(Cipher_Text, [0, -1]);


end

%Measure 'closeness' within each group and typical English_Text_Frequencies


English_Text_Frequencies = [0.0821,0.0150,0.0230,0.0479,0.1237,0.0225,0.0208,
0.0645,0.0676,0.0018,0.0087,0.0393,0.0254,0.0705,0.0767,0.0163,0.0009,0.0550,
0.0617,0.0921, 0.0291,0.0087,0.0254,0.0013,0.0195,0.0006];

Closeness_Matrix = zeros(Key_Length, 26);

for i = 1 : Key_Length
for j = 1 : 26
Closeness_Matrix(i,j) =
dot(Cipher_Text_Groups_Frequencies(i,:), English_Text_Frequencies);

English_Text_Frequencies = circshift(English_Text_Frequencies, [0, 1]);


end
end

%Compute the KEY


KEY = 'The encryption key was: ';

for i = 1 : Key_Length
KEY =
strcat(KEY,char(find(Closeness_Matrix(i,:)==max(Closeness_Matrix(i,:)))+64));
end

KEY
APPENDIX C

clear; clc;

%%Open and read the plain-text


Plain_Text = textread('H:\Educational Activities\Applied Computer Sciences\
Criptograpy and Information Security\Hill\Plain_Text.txt', '%c', 266);

Plain_Text = Plain_Text';
Plain_Text = double(Plain_Text);

%%Choose the ciphering matrix (i.e., the encryption key)


%Ciphering_Matrix = [2 3 15; 5 8 12; 1 13 4]; %For 'CRYPTOGRAPHYISCOOL'
Ciphering_Matrix = [13 22 10; 9 3 16; 23 13 5];
%Ciphering_Matrix = randi(26, 3); %Random matrix generation

%%Check if matrix determinant is invertible modulo 26.


%%If this is so, use the matrix ! Else, generate a new one.

Reciprocals =[1 3 5 7 9 11 15 17 19 21 23 25; 1 9 21 15 3 19 7 23 11 5 17 25];


CM_Determinant = uint8(mod(det(Ciphering_Matrix),26));
if ismember(CM_Determinant, Reciprocals(1,:))

%%Verify the length of plain-text. It should be a multiple of three.


%%If not, pad the ending with the last charachter within the message.
if mod(length(Plain_Text),3) == 2
Plain_Text = [Plain_Text, Plain_Text(length(Plain_Text))];
elseif mod(length(Plain_Text),3) == 1
Plain_Text = [Plain_Text, Plain_Text(length(Plain_Text))];
Plain_Text = [Plain_Text, Plain_Text(length(Plain_Text))];
end

%%Compute the message matrix (i.e., associated with the plain-text)


Plain_Text = Plain_Text - 64;
Message_Matrix = zeros (3, uint8(length(Plain_Text)/3));
for i = 1 : uint8(length(Plain_Text)/3)
Message_Matrix (:,i) = Plain_Text(((i*3)-2):(i*3))';
end

%%Encrypt the message, i.e., multiply the two matrices


Cipher_Matrix = Ciphering_Matrix*Message_Matrix;
Cipher_Matrix = mod(Cipher_Matrix, 26);

%%Format and display the cipher text


Cipher_Text = 'The cipher text is: ';
for j = 1 : uint8(length(Plain_Text)/3)
for i = 1 : 3
Cipher_Text = strcat(Cipher_Text,char(Cipher_Matrix(i,j))+64);
end
end

Cipher_Text

else
end
APPENDIX D

clear; clc;

clear; clc;
%%Open and read the plain-text
Cipher_Text = textread('H:\Educational Activities\Applied Computer Sciences\
Criptograpy and Information Security\Hill\Cipher_Text.txt', '%c', 266);

Cipher_Text = Cipher_Text';
Cipher_Text = double(Cipher_Text);

Ciphering_Matrix = [13 22 10; 9 3 16; 23 13 5];


%Ciphering_Matrix = [2 3 15; 5 8 12; 1 13 4];

%%Knowing the ciphering matrix (i.e., the encryption key) compute its inverse
%%Compute det(Ciphering_Matrix)
CM_Determinant = uint8(mod(det(Ciphering_Matrix),26));

%%Find the determinant's reciprocal modulo 26


Reciprocals =[1 3 5 7 9 11 15 17 19 21 23 25; 1 9 21 15 3 19 7 23 11 5 17 25];
Determinant_Rec=Reciprocals(2, find(Reciprocals(1,:)==CM_Determinant));

%%Compute the inv(Ciphering_Matrix); Set the format to 'rat'


Deciphering_Matrix = inv(Ciphering_Matrix);

%%Rationalize this matrix


%%Use debugging mode to change '583'
Deciphering_Matrix = Deciphering_Matrix * 5077;

%%Multiply the Determinant_Rec with Ciphering_Matrix


Deciphering_Matrix = mod(Determinant_Rec*Deciphering_Matrix, 26);

%%Compute the cipher text's matrix


Cipher_Text = Cipher_Text - 64;
Cipher_Text_Matrix = zeros (3, uint8(length(Cipher_Text)/3));
for i = 1 : uint8(length(Cipher_Text)/3)
Cipher_Text_Matrix (:,i) = Cipher_Text(((i*3)-2):(i*3))';
end

%%Decrypt the message, i.e., multiply the two matrices


Deciphered_Matrix = Deciphering_Matrix*Cipher_Text_Matrix;
Deciphered_Matrix = uint8(mod(Deciphered_Matrix, 26));

%%Format and display the cipher text


Deciphered_Text = 'Deciphered text is: ';
for j = 1 : uint8(length(Cipher_Text)/3)
for i = 1 : 3
Deciphered_Text = strcat(Deciphered_Text,char(Deciphered_Matrix(i,j))+64);
end
end

Deciphered_Text
APPENDIX E

Englez Frecven Romn Frecven


E 12.31% A 13.04%
T 9.59% I 12.89%
A 8.05% E 11.75%
O 7.94% R 7.39%
N 7.19% T 6.62%
I 7.18% N 6.44%
S 6.59% U 6.44%
R 6.03% S 5.50%
H 5.14% C 5.47%

Francez Frecven Spaniol Frecven


E 15.87% E 13.15%
A 9.42% A 12.69%
I 8.41% O 9.49%
S 7.90% S 7.60%
T 7.26% N 6.95%
N 7.15% R 6.25%
R 6.46% I 6.25%
U 6.24% L 5.94%
L 5.34% D 5.58%
APPENDIX F

Let and , two positive integers such that ( , ) = . Then has a unique multiplicative inverse
modulo and it can be computed using the Euclidean Algorithm (i.e., 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),
1 7(11) mod 26 mod 26.
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),

1 = 26 11(2) (3) 11(1) = 26(3) 11(6) 11(1) = 26(3) 11(7) = 26(3) + 11(7),

1 11(7) mod 26 mod 26.

You might also like