Computer Security Decypher

Page 1

Page |1

Panayiotis Georgiou URN: 6034221 Computer Science Level 3 Computer Security COM3009 Coursework 1

Exercise 1,2,3……………………………………………p.3-11 Source code……………………………………………..p.12-16 Charts(figures)……………………………………….p.16-27

Panayiotis Georgiou | Computer Security Coursework 1


Page |2

Exercise 1: Decrypt Caesar Cipher Cipher Text: XLIC AIVI WIRX XS XLI LSYWI SJ ER SPH TVSJIWWSV ALS PMZIH MR XLI LIEVX SJ XLI GSYRXVC XIR QMPIW JVSQ XLI RIEVIWX VEMPAEC WXEXMSR

Firstly, Caesar cipher is one from the simplest and earliest known ciphers. Also is a substitution cipher which each plaintext letter shifted in a fixed position down to the alphabet. For example, if we have a shift of four positions then a will be replaced by e. The first thing I have done to my cipher text is to get letter frequency analysis. From the frequency analysis (Fig.1-0) I assumed that letter ‘I’ in cipher text corresponds to letter ‘e’ because in the English language frequency analysis the most frequent letter is ‘e’.

Mathematical Description Alphabet is translated to characters of number a=0, b=1 … z=25. Where k=shift of the key x=letter for encryption Encryption function: e(x) = (x+k) (mod26) Decryption function: e(x) =(x-k) (mod26)

Implementation I implemented a java program to decrypt the Caesar Cipher text. The shift for the cipher text is four. Source Code in Appendices A.

Solution THEY WERE SENT TO THE HOUSE OF AN OLD PROFESSOR WHO LIVED IN THE HEART OF THE COUNTRY TEN MILES FROM THE NEAREST RAILWAY STATION

Panayiotis Georgiou | Computer Security Coursework 1


Page |3

Exercise 2: Decrypt - Simple Monoalphabetic Substitution Cipher Ciphetext FS YLP BRLDW'P ELJ VMN SGLS YOWM GFK FS YLP ALFDFDN GFK YORPM SGLD MHMR FD GFP OVJ LNM Simple monoalphabetic substitution cipher is a method of encryption where every letter of a plaintext is substituted with a corresponding cipher text. E : {A, . . . , Z} → {A, . . . , Z}

Encoding function:

F

S

Y

G F K

L

P

B

R

F S

Y

L

M H M R

F

D

L

D

P

W ‘

A

G F

L F

P

P

E

D F

L

J

D N

O V J

L

V

M N

G F

K

S

G L

S

Y O R P M

Y O W M

S G L D

N M

(*The upper letters in the above table is the cipher text an below is the plaintext that will be decrypted)

Step 1: The first thing I did to decipher the monoalphabetic cipher is to use the frequency analysis (Fig.2-0) and then guess high frequent letters. F and L letters have the highest frequency and I assumed comparing with the English frequency analysis that one of those it is likely to be ‘e’ to the plaintext. Step 2: Then I looked in the cipher text for double letter word such as FS and FD. I assumed that F is not ‘e’ because few double words start with e. Therefore, I figured out that F corresponds to it/is/in/if/as/an. Hence, F should be either ‘A’ or ‘I’. In addition, L took the second highest frequency and L is likely to be ‘e’. However, while substituting in I saw that YLP, ELJ, LNM words. The most frequent three letter word in English is ‘the’. Therefore, the L appears in the middle and in the begging of the words so I assumed that L is not ‘e’. After that, I saw again the frequency analysis and the letter M is the third most frequent letter and maybe corresponds to LNM. I replace M→E. In addition, I noticed the single quote after the word BRLDW’P it was P, I guessed that P maybe t, s. Therefore, I substitute P → S because most English words ending with s after single quote. F

S

G F K

Y

L

P s

B

R

F S

Y

L

L

P s

D

W ‘

A

L F

P s

D F

E

L

J

D N

V

M N e

G F

K

S

G L

S

Y O R P M s e

Y O W M e

S G L D

Panayiotis Georgiou | Computer Security Coursework 1


Page |4

M H M R e e

F

D

G F

P s

O V J

L

N M e

Step 3: YLP occurs twice and maybe is: was, his, gas, has. Then let us see at word MHMR maybe is even, ever, eyes. In the English Frequency Analysis, letters ‘A’ and ‘T’ have also high frequency. By eliminating the ‘e’, letters ‘F’ and ‘L’ maybe corresponds to ‘A’ and ‘T’. Nevertheless, F cannot be T because of FD and FS the second letter changes. In addition, L cannot be t because see YLP because end with s and is unlikely to be ts. After that I assumed that L→A. F

S

G F K

Y

L a

P s

B

F S

M H M R e e

Y

F

R

L a

D W ‘

L P a

D

A

G F

L F a

P s

P s

E

L a

J

D F D N

O V J

L a

V

M N e

G F

K

S

G L a

S

Y O R P M s e

Y O W M e

S G L D a

N M e

Step 4: Now let us consider the word ‘LNM’ it could be substitute with age. So replace N→G. Then see word YLP and GFP again maybe it was, has. I guess that YLP is so I substitute Y→W. Then I cannot substitute has in GFP because I already used a so I replaced it with his. Moreover, I substitute F→I and G→H. F i

S

G F K h i

Y L w a

P s

B R

F S i

M H M R e e

L a

D W ‘

Y L P w a s

F i

D

P s

E

L a

J

A L F D F D N a i i g

G F h i

P s

O V J

V M N e g

G F K h i

L a

S

G L h a

S

Y O R P M w s e

Y O W M w e

S G L D h a

N M g e

Step 5: Look at the word ‘SGLS’. I assume that S must be substitute with ‘T’ for word that. Then look at ‘SGLD’, which has the same three letters and D can be substitute with N. This is correct because FD changes FS. F i

S t

Y L w a

P s

B R

L a

D W ‘ n

P s

E

L a

J

V M N e g

S t

G L h a

S t

Y O W M w e

Panayiotis Georgiou | Computer Security Coursework 1


Page |5 G F K h i

F S i t

M H M R e e

Y L P w a s

F i

D n

A L F D F D N a i n i n g

G F h i

P s

O V J

G F K h i

L a

Y O R P M w s e

S G L D t h a n

N M g e

Step 5: Next look at the word ‘ALFDFDN’. In=t can be paining, raining but not gaining. I replace it with P because in the cipher, text is low frequency and in the English frequency, analysis p is low. F i

S t

G F K h i

Y L w a

P s

B R

F S i t

M H M R e e

L a

D W ‘ n

Y L P w a s

F i

D n

P s

E

L a

J

A L F D F D N p a i n i n g

G F h i

P s

O V J

V M N e g

G F K h i

L a

S t

G L h a

S t

Y O R P M w s e

Y O W M w e

S G L D t h a n

N M g e

Step 5: Next look at the word ‘MHMR’ it cannot be even or eyes because I already choose n and s. So I substitute it with ever (R→R,H→V). After that look at the word ‘YORPM’ it seems that matches with worse so I substitute O→O. Furthermore, look at word ‘YOWM’. W is substitute with K. F i

S t

G F K h i

Y L w a

P s

B R r

F S i t

M H M R e v e r

L a

D W ‘ n

Y L P w a s

F i

D n

P s

E

L a

J

A L F D F D N p a i n i n g

G F h i

P s

O V J o

V M N e g

G F K h i

L a

S t

G L h a

S t

Y O R P M w o r s e

Y O W M w o e

S G L D t h a n

N M g e

Step 6: Furthermore look at word ‘YOWM’. W is substitute with K. Then ‘GFK’ is him. You can see now that the plaintext gets some meaning and you can easily guess the rest letters. F i

S t

G F K h i m

Y L w a

P s

B R r

F S i t

M H M R e v e r

L a

D W ‘ n k

Y L P w a s

F i

D n

G F h i

P s

E

L a

J

A L F D F D N p a i n i n g

P s

O V J o

V M N e g

G F K h i m

L a

S t

G L h a

S t

Y O R P M w o r s e

Y O W M w o k e

S G L D t h a n

N M g e

Panayiotis Georgiou | Computer Security Coursework 1


Page |6

Solution of the Monoalpabetic Substitution Cipher Text F i

S t

G F K h i m

Y L P w a s

B R f r

F S i t

M H M R e v e r

L a

D W ‘ n k

Y L P w a s

F i

D n

G F h i

P s

E L J b a d

A L F D F D N p a i n i n g

P s

O V J o l d

V M N l e g

G F K h i m

L a

S t

G L S h a t

Y O R P M w o r s e

Y O W M w o k e

S G L D t h a n

N M g e

Panayiotis Georgiou | Computer Security Coursework 1


Page |7

Decrypt Vigenere Cipher Code Cipher text:

LYYDRYHKKGEGLEZWJOQKFMPRRLBANTGZREVROSCBUKVZEVBLWYCKBBHEYVGHHKUMRT PVYVQZKVCIEZKNFMAKYVPQOXLEEKYUXUQWIKUKFMRGUKFIAJWYCZNOQSMENVSVYZFO QKFMPRRLBAVCLCJZRSHDZMESBTMDRTDERJRZZVCVZKDEBGBADEBIYROZTQAMFICIGAUV QWSKYVPGXOQULMIKUREIVTZZJTGNHNYBRXVSCKBSHRDTBUGKMLRYWIMGNROCGNRCK VLMIKUKFMEGLEZWJGSGCIEYLERPRIOFSLFOZZJTFKHZRIAJUVKMZHHIRPRKYVPTNYWZLOP UYVLIAZEVRERKQXMLNTGRJTYOYZLOPXHRRCEKVFDMIKUPIQAJRERPRKDIRP Vigenère Cipher is a Polyalhabetic Cipher, which can be encipher in different ways and it use more than one cipher alphabet. Vigenere has 26 different alphabets. It is difficult to decipher because of their resistance to letter frequency analysis. Vigenere cipher is a combination of Caesar cipher shift combined with a keyword. Step1: The first thing to do is to find the length of the keyword. How to establish this? By using Method of Coincidence. The plaintext is shifted against itself and the important is to find the number of matches between letters occurrence. A random shift will give a low number a shift, which is multiple of the key length, will give a high number. This happens because in English language some letters are more frequent than others are and a letter is more likely to match copy of it, which has been coded with the same key letter. Method of Coincidence: I looked at the sequence of letters that are repeated. If we find repeats then we would count the distance between the repeats. This would be a multiple of the key length.

EGL GLE LEZ EZW OQK QKF KFM FMP IKU EGLEZWJ

Occurrences 2 2 2 2 2 2 4 2 4 2

Positions 10,274 11,275 12,276 13,277 17,131 18,132 19,103,133,271 20,134 100,214,268,376 10

Distance 264 264 264 264 114 114 84,114,252,30,168,138 114 114,168,276,54,162,108 264

Listing the distances between repeats, we have 264,114,84,252,30,168,138,276,54,162,108. These are all multiples of six. By this, I assumed that the key length is six. Finding the length of the keyword helps us because we can divide the cipher text into groups. Then each group enciphered by a Caesar shift.

Keyword: _ _ _ _ _ _

Panayiotis Georgiou |Computer Security Coursework 1


Page |8

Step2: Find the letters of the keyword and split the cipher text in groups of six. LYYDRY HKKGEG LEZWJO QKFMPR RLBANT GZREVR OSCBUK VZEVBL WYCKBB - - - - - -(repeating six letter keyword) HEYVGH HKUMRT PVYVQZ KVCIEZ KNFMAK YVPQOX LEEKYU XUQWIK UKFMRG UKFIAJ WYCZNO QSMENV SVYZFO QKFMPR RLBAVC LCJZRS HDZMES BTMDRT DERJRZ ZVCVZK DEBGBA DEBIYR OZTQAM FICIGA UVQWSK YVPGXO QULMIK UREIVT ZZJTGN HNYBRX VSCKBS HRDTBU GKMLRY WIMGNR OCGNRC KVLMIK UKFMEG LEZWJG SGCIEY LERPRI OFSLFO ZZJTFK HZRIAJ UVKMZH HIRPRK YVPTNY WZLOPU YVLIAZ EVRERK QXMLNT GRJTYO YZLOPX HRRCEK VFDMIK UPIQAJ RERPRK DIRP If we want to find the letters of the keyword, we must find the frequencies of the first letters of the cipher text (groups) and then compare them with the frequency of the English chart. I will repeat these steps until I find the keyword. The corresponding decrypt method is:

Keyword letter: frequency of the cipher text letter X100 Observed Number of letters in cipher text First Letter Keyword LYYDRY HKKGEG LEZWJO QKFMPR RLBANT GZREVR OSCBUK VZEVBL WYCKBB HEYVGH HKUMRT PVYVQZ KVCIEZ KNFMAK YVPQOX LEEKYU XUQWIK UKFMRG UKFIAJ WYCZNO QSMENV SVYZFO QKFMPR RLBAVC LCJZRS HDZMES BTMDRT DERJRZ ZVCVZK DEBGBA DEBIYR OZTQAM FICIGA UVQWSK YVPGXO QULMIK UREIVT ZZJTGN HNYBRX VSCKBS HRDTBU GKMLRY WIMGNR OCGNRC KVLMIK UKFMEG LEZWJG SGCIEY LERPRI OFSLFO ZZJTFK HZRIAJ UVKMZH HIRPRK YVPTNY WZLOPU YVLIAZ EVRERK QXMLNT GRJTYO YZLOPX HRRCEK VFDMIK UPIQAJ RERPRK DIRP

Comparing the English Letter Frequency Analysis (Fig.0-1) with the first letter cipher text frequency analysis chart (Fig.3-1) it seems that the first letter of the keyword is D because the above chart was shifted three places.

Keyword: D _ _ _ _ _

Panayiotis Georgiou |Computer Security Coursework 1


Page |9 Second Letter Keyword LYYDRY HKKGEG LEZWJO QKFMPR RLBANT GZREVR OSCBUK VZEVBL WYCKBB HEYVGH HKUMRT PVYVQZ KVCIEZ KNFMAK YVPQOX LEEKYU XUQWIK UKFMRG UKFIAJ WYCZNO QSMENV SVYZFO QKFMPR RLBAVC LCJZRS HDZMES BTMDRT DERJRZ ZVCVZK DEBGBA DEBIYR OZTQAM FICIGA UVQWSK YVPGXO QULMIK UREIVT ZZJTGN HNYBRX VSCKBS HRDTBU GKMLRY WIMGNR OCGNRC KVLMIK UKFMEG LEZWJG SGCIEY LERPRI OFSLFO ZZJTFK HZRIAJ UVKMZH HIRPRK YVPTNY WZLOPU YVLIAZ EVRERK QXMLNT GRJTYO YZLOPX HRRCEK VFDMIK UPIQAJ RERPRK DIRP Comparing the English Letter Frequency Analysis (Fig.0-1) with the second letter cipher text frequency analysis chart (Fig.3-2) it seems that the second letter of the keyword is R because the above chart was shifted seventeen places.

Keyword: D R _ _ _ _ Third Letter Keyword LYYDRY HKKGEG LEZWJO QKFMPR RLBANT GZREVR OSCBUK VZEVBL WYCKBB HEYVGH HKUMRT PVYVQZ KVCIEZ KNFMAK YVPQOX LEEKYU XUQWIK UKFMRG UKFIAJ WYCZNO QSMENV SVYZFO QKFMPR RLBAVC LCJZRS HDZMES BTMDRT DERJRZ ZVCVZK DEBGBA DEBIYR OZTQAM FICIGA UVQWSK YVPGXO QULMIK UREIVT ZZJTGN HNYBRX VSCKBS HRDTBU GKMLRY WIMGNR OCGNRC KVLMIK UKFMEG LEZWJG SGCIEY LERPRI OFSLFO ZZJTFK HZRIAJ UVKMZH HIRPRK YVPTNY WZLOPU YVLIAZ EVRERK QXMLNT GRJTYO YZLOPX HRRCEK VFDMIK UPIQAJ RERPRK DIRP Comparing the English Letter Frequency Analysis (Fig.0-1) with the first letter cipher text frequency analysis chart (Fig.3-3) was difficult to guess the letter because it is not straightforward. From the first sight is seems that maybe letter C, but I did not choose it because it is unlikely to have dr and the c in English Language. After consideration, I saw letter Y compare to English frequency. The only thing that is difficult is that separated from ABC-Y. Taking everything into account, the third letter of the keyword is Y and it was shifted twenty-four places.

Keyword: D R Y _ _ _

Panayiotis Georgiou |Computer Security Coursework 1


P a g e | 10 Fourth Letter Keyword LYYDRY HKKGEG LEZWJO QKFMPR RLBANT GZREVR OSCBUK VZEVBL WYCKBB HEYVGH HKUMRT PVYVQZ KVCIEZ KNFMAK YVPQOX LEEKYU XUQWIK UKFMRG UKFIAJ WYCZNO QSMENV SVYZFO QKFMPR RLBAVC LCJZRS HDZMES BTMDRT DERJRZ ZVCVZK DEBGBA DEBIYR OZTQAM FICIGA UVQWSK YVPGXO QULMIK UREIVT ZZJTGN HNYBRX VSCKBS HRDTBU GKMLRY WIMGNR OCGNRC KVLMIK UKFMEG LEZWJG SGCIEY LERPRI OFSLFO ZZJTFK HZRIAJ UVKMZH HIRPRK YVPTNY WZLOPU YVLIAZ EVRERK QXMLNT GRJTYO YZLOPX HRRCEK VFDMIK UPIQAJ RERPRK DIRP Comparing the English Letter Frequency Analysis (Fig.0-1) with the fourth letter cipher text frequency analysis chart (Fig.3-4) it seems that the fourth letter of the keyword is I and was shifted eight places.

Keyword: D R Y I _ _ Fifth Letter Keyword LYYDRY HKKGEG LEZWJO QKFMPR RLBANT GZREVR OSCBUK VZEVBL WYCKBB HEYVGH HKUMRT PVYVQZ KVCIEZ KNFMAK YVPQOX LEEKYU XUQWIK UKFMRG UKFIAJ WYCZNO QSMENV SVYZFO QKFMPR RLBAVC LCJZRS HDZMES BTMDRT DERJRZ ZVCVZK DEBGBA DEBIYR OZTQAM FICIGA UVQWSK YVPGXO QULMIK UREIVT ZZJTGN HNYBRX VSCKBS HRDTBU GKMLRY WIMGNR OCGNRC KVLMIK UKFMEG LEZWJG SGCIEY LERPRI OFSLFO ZZJTFK HZRIAJ UVKMZH HIRPRK YVPTNY WZLOPU YVLIAZ EVRERK QXMLNT GRJTYO YZLOPX HRRCEK VFDMIK UPIQAJ RERPRK DIRP Comparing the English Letter Frequency Analysis (Fig.0-1) with the fifth letter cipher text frequency analysis chart (Fig.3-5) it seems that the fifth letter of the keyword is N and was shifted thirteen places. The only thing to consider here is that the last cipher word length is four(less than other groups). For frequency that is more accurate, we did not count the last cipher word and the sum of number of letters will be less than the previous times.

Keyword: D R Y I N _

Panayiotis Georgiou |Computer Security Coursework 1


P a g e | 11

Sixth Letter Keyword LYYDRY HKKGEG LEZWJO QKFMPR RLBANT GZREVR OSCBUK VZEVBL WYCKBB HEYVGH HKUMRT PVYVQZ KVCIEZ KNFMAK YVPQOX LEEKYU XUQWIK UKFMRG UKFIAJ WYCZNO QSMENV SVYZFO QKFMPR RLBAVC LCJZRS HDZMES BTMDRT DERJRZ ZVCVZK DEBGBA DEBIYR OZTQAM FICIGA UVQWSK YVPGXO QULMIK UREIVT ZZJTGN HNYBRX VSCKBS HRDTBU GKMLRY WIMGNR OCGNRC KVLMIK UKFMEG LEZWJG SGCIEY LERPRI OFSLFO ZZJTFK HZRIAJ UVKMZH HIRPRK YVPTNY WZLOPU YVLIAZ EVRERK QXMLNT GRJTYO YZLOPX HRRCEK VFDMIK UPIQAJ RERPRK DIRP Comparing the English Letter Frequency Analysis (Fig.0-1) with the sixth letter cipher text frequency analysis chart (Fig.3-6) it seems that the sixth letter of the keyword is N and was shifted six places. The only thing to consider here is that the last cipher word length is four. For frequency that is more accurate, we did not count the last cipher word and the sum of number of letters will be less than the previous times.

Keyword: D R Y I N G Then I implement a java program to decrypt the whole Vigenere cipher text. Java source code Appendices B. The cipher alphabet corresponding to each letter of the keyword is:

*The above method that used is Kasiski examination, which was the first successful attack on Vigenere cipher.

Solution IHAVESETMYRAINBOWINTHECLOUDSANDITWILLBETHESIGNOFTHECOVENANTBETWEENM EANDTHEEARTHWHENEVERIBRINGCLOUDSOVERTHEEARTHANDTHERAINBOWAPPEARSINT HECLOUDSIWILLREMEMBERMYCOVENANTBETWEENMEANDYOUANDALLLIVINGCREATURE SOFEVERYKINDNEVERAGAINWILLTHEWATERSBECOMEAFLOODTODESTROYALLLIFEWHENE VERTHERAINBOWAPPEARSINTHECLOUDSIWILLSEEITANDREMEMBERTHEEVERLASTINGCOV ENANTBETWEENGODANDALLLIVINGCREATURESOFEVERYKINDONTHEEARTH

Panayiotis Georgiou |Computer Security Coursework 1


P a g e | 12

Supplemental Reading -

Cryptography and Network Security: Principles and Practice, by William Stallings. The Handbook of Applied Cryptography, by Alfred J. Menezes, Paul C. van Oorschot and Scott A. Vanstone The Code Book, by Simon Singh COMPUTER SECURITY AND CRYPTOGRAPHY ALAN G. KONHEIM Copyright Š 2007 by John Wiley & Sons.

Panayiotis Georgiou |Computer Security Coursework 1


P a g e | 13

Appendices A package caesarcipher; import javax.swing.JOptionPane; public class Cipher {

public static String encode(String message, int shift) { // declare constants final int ALPHABET_SIZE = 26; // wrap around A-Z(instead of putting number for ascii) String encrypt = ""; // return the encrypted message char letter; // each letter that is been processed

//taking each character from the plain text and processed it independently for (int index = 0; index < message.length(); index++) { // add the cipher value to the letter that is been processed letter = message.charAt(index); if (letter >='A' && letter <= 'Z') { // is A-Z, so add shift // determine whether result will be out of A-Z range if ((letter + shift) > 'Z') // need to wrap around to 'A' letter = (char)(letter - ALPHABET_SIZE + shift); else if ((letter + shift) < ' ') // need to wrap around to 'Z' letter = (char)(letter + ALPHABET_SIZE + shift); else letter = (char) (letter + shift); } // build encoded message string encrypt = encrypt + letter; } return encrypt; } public static String decode(String message, int shift) { // declare constants final int ALPHABET_SIZE = 26; // wrap around A-Z(instead of putting number for ascii) String decrypt = ""; // base for string to return char letter; // letter being processed

//taking each character from the ciphertext and processed it independently for (int index = 0; index < message.length(); index++) { // get letter and determine whether to subtract cipher value letter = message.charAt(index); if (letter >= 'A' && letter <= 'Z') {

Panayiotis Georgiou |Computer Security Coursework 1


P a g e | 14 // check if is A-Z, and then subtract // determine whether result will be out of A-Z range if ((letter - shift) < 'A') // wrap around to 'Z' letter = (char)(letter + ALPHABET_SIZE - shift); else if ((letter - shift) > 'Z') // wrap around to 'A' letter = (char)(letter - ALPHABET_SIZE - shift); else letter = (char) (letter - shift); } // build decoded message decrypt = decrypt + letter; } return decrypt; }

public static void main (String[] args){ int startCh,key; String keyword=""; String message=""; String text=""; String[] options = new String[] {"Encrypt", "Decrypt", "Exit"}; // Choice of whether to use the encrypt , decrypt or exit startCh = JOptionPane.showOptionDialog(null, "Please Choose:", "Caesar Cipher", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); //First Choice Encrypt send parameters message(palintext) and key (shift number) to method encode if(startCh == 0){ message = JOptionPane.showInputDialog(null, "Please input the plaintext:", "Input Message", JOptionPane.QUESTION_MESSAGE); message = message.toUpperCase(); keyword=JOptionPane.showInputDialog ( "Enter key to shift to plaintext(0-25):" ); key = Integer.parseInt ( keyword); text = encode(message, key); System.out.println("Encoded palintext is: " + text); } //Second Choice Decrypt send parameters message(ciphertext) and key (shift number) to method decode else if(startCh == 1){ message = JOptionPane.showInputDialog(null, "Please input the ciphertext:", "Input Message", JOptionPane.QUESTION_MESSAGE); message = message.toUpperCase(); keyword=JOptionPane.showInputDialog ( "Enter key to shift to plaintext(0-25):" ); key = Integer.parseInt ( keyword); text = decode(message, key); System.out.println("Decoded ciphertext is: " + text); } //Third Choice Exit else{ System.out.println("Thank you for using Caesar Cipher!!!!! ");

Panayiotis Georgiou |Computer Security Coursework 1


P a g e | 15 System.exit(0); } System.out.println("Thank you for using Caesar Cipher!!!!! "); } }

Appendices B package Vigenere; import javax.swing.JOptionPane; public class VigenereCipherComplete { public static void main(String[] args) { String key, message; String encrMessage = ""; String[] options = new String[] {"Encrypter", "Decrypter", "Cancel"}; int int int int int int int int

startCh; keyLen; length; keyChValue; mesChValue; enChValue; index = 0; keyIndex = 0;

char keyChar; char messageChar; char encrChar; boolean progType = true; // Choice of whether to use the encrypt , decrypt or exit startCh = JOptionPane.showOptionDialog(null, "Please Choose:", "Vigenere", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if(startCh == 0) progType = true; else if(startCh == 1) progType = false; else System.exit(0); // Input keyword key = JOptionPane.showInputDialog(null, "Please input the key:", "Input Key", JOptionPane.QUESTION_MESSAGE); key = key.toUpperCase(); // Input message message = JOptionPane.showInputDialog(null, "Please input the plaintext/ciphertext:", "Input Message", JOptionPane.QUESTION_MESSAGE); message = message.toUpperCase(); keyLen = key.length();// length = message.length();

Panayiotis Georgiou |Computer Security Coursework 1


P a g e | 16 while(index < length) { keyChar = key.charAt(keyIndex); keyChValue = (int)keyChar; messageChar = message.charAt(index); mesChValue = (int)messageChar; if(mesChValue >= 65 && mesChValue <= 90) { // encrypt letter if(progType) enChValue = (keyChValue - 65) + mesChValue; // decrypt letter else { if(mesChValue >= keyChValue) enChValue = (mesChValue + 65) - keyChValue; else enChValue = (((90 - keyChValue) + mesChValue) + 1); } // takes ascii values > 90 back from to 65 if(enChValue > 90) { enChValue = (enChValue - 90); enChValue = (enChValue + 65) - 1; } // converts the char value to a char and then add it to a converted string encrChar = (char)enChValue; encrMessage = encrMessage + encrChar; keyIndex++; } // char remain the same

and

then add it to the converted string

(not a letter) else { enChValue = mesChValue; encrChar = (char)enChValue; encrMessage = encrMessage + encrChar; } index++; if (keyIndex >= keyLen)// reset the key to loop for the full string to be converted keyIndex = 0; } // Result of encryption if(progType) System.out.println("Your key was:" + key + "\nYour encrypted message is:\t" + encrMessage); // Result of decrytion else System.out.println("Your key was:\t\t" + key + "\nYour decrypted message is:\t" + encrMessage); } }

Panayiotis Georgiou |Computer Security Coursework 1


P a g e | 17

English Letter Frequency(%) 14

12

10

8

6

4

2

0 a

b

c

d

e

f

g

h

i

j

k

l

m

n

o

p

q

r

s

t

u

v

w

x

y

Fig.0-1 English Letter Frequency Analysis Panayiotis Georgiou |Computer Security Coursework 1

z


P a g e | 18

Caesar Ciphertext Frequency(%) 18

16

14

12

10

8

6

4

2

0 a

b

c

d

e

f

g

h

i

j

k

l

m

n

o

p

q

r

s

t

u

v

w

x

y

Fig.1-0 Caesar Cipher text Frequency Analysis Panayiotis Georgiou |Computer Security Coursework 1

z


P a g e | 19

Monoalphabetic Ciphertext Frequency(%) 14

12

10

8

6

4

2

0 a

b

c

d

e

f

g

h

i

j

k

l

m

n

o

p

q

r

s

t

u

v

w

x

y

Fig.2-0 Monoalphabetic Substitution Cipher text Frequency Analysis

Panayiotis Georgiou |Computer Security Coursework 1

z


P a g e | 20

Vigenere Ciphertext Frequency(%) 10

9

8

7

6

5

4

3

2

1

0

a

b

c

d

e

f

g

h

i

j

k

l

m

n

o

p

q

r

s

t

u

v

w

x

Fig.3-0 Vigenere Cipher text Frequency Analysis Panayiotis Georgiou |Computer Security Coursework 1

y

z


P a g e | 21

First LetterFrequency(%) 16

14

12

10

8

6

4

2

0 a

b

c

d

e

f

g

h

i

j

k

l

m

n

o

p

q

r

s

t

u

v

w

x

y

Fig.3-1 First Letter Cipher text Frequency Analysis Panayiotis Georgiou |Computer Security Coursework 1

z


P a g e | 22

Second Letter Frequency(%) 20

18

16

14

12

10

8

6

4

2

0 a

b

c

d

e

f

g

h

i

j

k

l

m

n

o

p

q

r

s

t

u

v

w

x

y

Fig.3-2 Second Letter Cipher text Frequency Analysis

Panayiotis Georgiou |Computer Security Coursework 1

z


P a g e | 23

Third Letter Frequency(%) 16

14

12

10

8

6

4

2

0

a

b

c

d

e

f

g

h

i

j

k

l

m

n

o

p

q

r

s

t

u

v

w

x

y

Fig.3-3 Third Letter Cipher text Frequency Analysis

Panayiotis Georgiou |Computer Security Coursework 1

z


P a g e | 24

Fourth Letter Frequency(%) 18

16

14

12

10

8

6

4

2

0 a

b

c

d

e

f

g

h

i

j

k

l

m

n

o

p

q

r

s

t

u

v

w

x

y

Fig.3-4 Fourth Letter Cipher text Frequency Analysis

Panayiotis Georgiou |Computer Security Coursework 1

z


P a g e | 25

Fifth Letter Frequency(%) 14

12

10

8

6

4

2

0 a

b

c

d

e

f

g

h

i

j

k

l

m

n

o

p

q

r

s

t

u

v

w

x

y

Fig.3-5 Fifth Letter Cipher text Frequency Analysis Panayiotis Georgiou |Computer Security Coursework 1

z


P a g e | 26

Sixth Letter Frequency(%) 25

20

15

10

5

0 a

b

c

d

e

f

g

h

i

j

k

l

m

n

o

p

q

r

s

t

u

v

w

x

y

Fig.3-6 Sixth Letter Cipher text Frequency Analysis Panayiotis Georgiou |Computer Security Coursework 1

z


P a g e | 27

Fig.Occurrences of letters in the Vigenere cipher text

Panayiotis Georgiou |Computer Security Coursework 1


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.