|
|
|
|
5
|
![](http://demo05.cloudimage.io/s/resize/215/i.imgur.com/TEk9bMp.png)
|
5
|
![](http://demo05.cloudimage.io/s/resize/215/i.imgur.com/TEk9bMp.png)
|
6
|
![](http://demo05.cloudimage.io/s/resize/215/i.imgur.com/3PV1IiK.png)
|
6
|
![](http://demo05.cloudimage.io/s/resize/215/i.imgur.com/3PV1IiK.png)
|
7
|
|
7
|
|
8
|
-[Verano 2016 - Ive]
|
|
|
|
|
8
|
+[Verano 2016 - Ive- Tatiana]
|
9
|
|
9
|
|
10
|
-One of the advantages of using computer programs is that we can easily implement repetitive tasks. Structures such as the `for`, `while`, and `do-while` allow us to repeat a block of instructions as many times as needed. In this lab experience you will use `for` loops to complete a simple ciphering application.
|
|
|
|
|
10
|
+One of the advantages of using computer programs is that we can easily implement repetitive tasks. Structures such as the `for`, `while`, and `do-while` allow us to repeat a block of instructions as many times as needed. In this lab experience, you will use `for` loops to complete a simple ciphering application.
|
11
|
|
11
|
|
12
|
##Objectives:
|
12
|
##Objectives:
|
13
|
|
13
|
|
|
|
|
|
29
|
|
29
|
|
30
|
5. Studied the concepts and instructions for the laboratory session.
|
30
|
5. Studied the concepts and instructions for the laboratory session.
|
31
|
|
31
|
|
32
|
-6. Taken the Pre-Lab quiz availabel in Moodle.
|
|
|
|
|
32
|
+6. Taken the Pre-Lab quiz, available in Moodle.
|
33
|
|
33
|
|
34
|
|
34
|
|
35
|
|
35
|
|
|
|
|
|
39
|
|
39
|
|
40
|
##Criptography
|
40
|
##Criptography
|
41
|
|
41
|
|
42
|
-Cryptography is the area of knowledge that studies the theory and methods that are used for protecting information so that non-authorized persons cannot understand it. A *cryptographic system* is a system that transforms a *cleartext message* (a message that is understandable to humans) to a *cyphered* text (text that is unintelligible to unauthorized persons). Authorized persons can *decypher* the *cyphered* text to obtain the original cleartext.
|
|
|
|
|
42
|
+Cryptography is the area of knowledge that studies the theory and methods that are used for protecting information so that non-authorized persons cannot understand it. A *cryptographic system* is a system that transforms a *clear text message* (a message that is understandable to humans) to a *cyphered* text (text that is unintelligible to unauthorized persons). Authorized persons can *decypher* the *cyphered* text to obtain the original cleartext.
|
43
|
|
43
|
|
44
|
###The Ceasar Cypher
|
44
|
###The Ceasar Cypher
|
45
|
|
45
|
|
46
|
-The Caesar Cypher is a substitution encryption technique that is said to have been used by Julius Caesar (100 BC - 44 BC), the Roman political and military leader, to communicate with his generals. To encrypt a message using the Caesar Cipher each letter of the cleartext message is substituted by the letter found a given number of positions ahead in the alphabet. You may think of this as a shift of the letter in the alphabet. Figure 1 illustrates a shift of 3 spaces within the alphabet. For instance, letter ‘B’ would be substituted by letter ‘E’.
|
|
|
|
|
46
|
+The Caesar Cypher is a substitution encryption technique that is said to have been used by Julius Caesar (100 BC - 44 BC), the Roman political and military leader, to communicate with his generals. To encrypt a message using the Caesar Cipher each letter of the clear text message is substituted by the letter found a given number of positions ahead in the alphabet. You may think of this as a shift of the letter in the alphabet. Figure 1 illustrates a shift of 3 spaces within the alphabet. For instance, letter ‘B’ would be substituted by letter ‘E’.
|
47
|
|
47
|
|
48
|
---
|
48
|
---
|
49
|
|
49
|
|
|
|
|
|
69
|
|
69
|
|
70
|
To convert an uppercase letter to a number in the [0,25] range we can apply our knowledge of the ASCII code. The code for the uppercase letters is in the range [65,90] (‘A’ is 65, ‘Z’ is 90). Thus, to convert an uppercase case to a number in the range [0,25], a simple subtraction by 65 does the trick (i.e. `’A’ - 65 = 0`, `’Z’ - 65 = 25`). Observe that to go from the [0,25] range to the ASCII code of its corresponding uppercase character we simply add 65 to the number. For instance, number 3 corresponds to the letter whose ASCII code is $3 + 65 = 68$, i.e. letter ‘D’.
|
70
|
To convert an uppercase letter to a number in the [0,25] range we can apply our knowledge of the ASCII code. The code for the uppercase letters is in the range [65,90] (‘A’ is 65, ‘Z’ is 90). Thus, to convert an uppercase case to a number in the range [0,25], a simple subtraction by 65 does the trick (i.e. `’A’ - 65 = 0`, `’Z’ - 65 = 25`). Observe that to go from the [0,25] range to the ASCII code of its corresponding uppercase character we simply add 65 to the number. For instance, number 3 corresponds to the letter whose ASCII code is $3 + 65 = 68$, i.e. letter ‘D’.
|
71
|
|
71
|
|
72
|
-Figure 3 shows the pseudocode of an algorithm for the Caesar cipher. Each letter ‘c’ in the cleartext message is converted to a number in the range [0,25] (by subtracting ‘A’). The displacement d is then added to the number (modulo 26) . Lastly, the result of the modular addition is converted back to its corresponding letter by adding the ASCII code of ‘A’.
|
|
|
|
|
72
|
+Figure 3 shows the pseudocode of an algorithm for the Caesar cipher. Each letter ‘c’ in the cleartext message is converted to a number in the range [0,25] (by subtracting ‘A’). The displacement `d` is then added to the number (modulo 26) . Lastly, the result of the modular addition is converted back to its corresponding letter by adding the ASCII code of ‘A’.
|
73
|
|
73
|
|
74
|
---
|
74
|
---
|
75
|
|
75
|
|
|
|
|
|
90
|
|
90
|
|
91
|
---
|
91
|
---
|
92
|
|
92
|
|
93
|
-The Caesar cipher is considered a weak encryption mechanism because it can easily be deciphered by using frequency analysis on the ciphered message. For example, we can use the fact that letter ‘e’ is the most frequent letter in most texts. If we find the most frequent letter in a ciphered text it very probably corresponds to the letter that was substituted by ‘e’. With this information we can compute the displacement that was used and decipher the rest of the message.
|
|
|
|
|
93
|
+The Caesar cipher is considered a weak encryption mechanism because it can easily be deciphered by using frequency analysis on the ciphered message. For example, we can use the fact that letter ‘e’ is the most frequent letter in most texts. If we find the most frequent letter in a ciphered text it probably corresponds to the letter that was substituted by ‘e’. With this information, we can compute the displacement that was used and decipher the rest of the message.
|
94
|
|
94
|
|
95
|
###The Vigenere Cypher
|
95
|
###The Vigenere Cypher
|
96
|
|
96
|
|
97
|
-A main weakness of the Caesar cipher is that every letter in the cleartext message is shifted by the same number of positions. The Vignere cipher is a somewhat stronger encryption method because the shift used on each letter is not constant. Whereas the Caesar cipher receives as input a cleartext message and a displacement, the Vignere receives the cleartext message and **keyword**. For now, lets assume that the keyword and the cleartext message have the same length. The Vignere cipher uses the keyword to determine the shift that will be applied to each letter of the cleartext message, i.e. the first letter of the keyword determines the shift number for the first letter of the message and so forth.
|
|
|
|
|
97
|
+A main weakness of the Caesar cipher is that every letter in the clear text message is shifted by the same number of positions. The Vigenere cipher is a somewhat stronger encryption method because the shift used on each letter is not constant. Whereas the Caesar cipher receives as an input a clear text message and a displacement, the Vigenere receives the clear text message and **keyword**. For now, let's assume that the keyword and the clear text message have the same length. The Vigenere cipher uses the keyword to determine the shift that will be applied to each letter of the cleartext message, i.e. the first letter of the keyword determines the shift number for the first letter of the message and so forth.
|
98
|
|
98
|
|
99
|
**Example 2.** Suppose that the cleartext is “PET” and the keyword is “BED”. Each letter in the **keyword** determines the shift amount of the corresponding letter in the cleartext: letter ‘A’ specifies a shift of 0, ‘B’ is a shift of 1, and so on. Thus, the ‘B’ in the keyword “BED” states that we shall shift the first letter of the cleartext by 1, the ‘E’ states that we will shift second the letter by 4 and the ‘D’ states that we will shift the last letter by 3.
|
99
|
**Example 2.** Suppose that the cleartext is “PET” and the keyword is “BED”. Each letter in the **keyword** determines the shift amount of the corresponding letter in the cleartext: letter ‘A’ specifies a shift of 0, ‘B’ is a shift of 1, and so on. Thus, the ‘B’ in the keyword “BED” states that we shall shift the first letter of the cleartext by 1, the ‘E’ states that we will shift second the letter by 4 and the ‘D’ states that we will shift the last letter by 3.
|
100
|
|
100
|
|
|
|
|
|
110
|
|
110
|
|
111
|
---
|
111
|
---
|
112
|
|
112
|
|
113
|
-Figure 5 shows a table that can be used to determine the Vigenere-ciphered letter, given the cleartext and keyword letter. Notice that each row contains the entire alphabet shifted by the amount specified by the letter at the beginning of the row.
|
|
|
|
|
113
|
+Figure 5 shows a table that can be used to determine the Vigenere-ciphered letter, given the clear text and keyword letter. Notice that each row contains the entire alphabet shifted by the amount specified by the letter at the beginning of the row.
|
114
|
|
114
|
|
115
|
---
|
115
|
---
|
116
|
|
116
|
|
|
|
|
|
120
|
|
120
|
|
121
|
---
|
121
|
---
|
122
|
|
122
|
|
123
|
-If the keyword is shorter than the cleartext, the Vigenere cipher simply repeats the keyword as many times as needed to account for all the letters of the cleartext. Figure 6, illustrates the keyword and cleartext pairing for an example.
|
|
|
|
|
123
|
+If the keyword is shorter than the clear text, the Vigenere cipher simply repeats the keyword as many times as needed to account for all the letters of the clear text. Figure 6, illustrates the keyword and cleartext pairing for an example.
|
124
|
|
124
|
|
125
|
---
|
125
|
---
|
126
|
|
126
|
|
|
|
|
|
171
|
|
171
|
|
172
|
## Laboratory session:
|
172
|
## Laboratory session:
|
173
|
|
173
|
|
174
|
-You will be completing an application to cipher a message using the Vigenere technique. To simplify coding, the keyword and cleartext must consist exclusively of letters. Furthermore, your program must change both the cleartext and keyword to uppercase before ciphering.
|
|
|
|
|
174
|
+You will be completing an application to cipher a message using the Vigenere technique. To simplify coding, the keyword and clear text must consist exclusively of letters. Furthermore, your program must change both the cleartext and keyword to uppercase before ciphering.
|
175
|
|
175
|
|
176
|
-### Exercise 1 - Keyword and cleartext of the same length
|
|
|
|
|
176
|
+### Exercise 1 - Keyword and Cleartext of the Same Length
|
177
|
|
177
|
|
178
|
-In this exercise you will implement a function that given a cleartext and keyword of equal length returns the cipher message.
|
|
|
|
|
178
|
+In this exercise, you will implement a function that given a cleartext and keyword of equal length returns the cipher message.
|
179
|
|
179
|
|
180
|
-#### Instructions:
|
|
|
|
|
180
|
+#### Instructions
|
181
|
|
181
|
|
182
|
1. Load the project `VigenereCypher` into `QtCreator`. There are two ways to do this:
|
182
|
1. Load the project `VigenereCypher` into `QtCreator`. There are two ways to do this:
|
183
|
|
183
|
|
|
|
|
|
191
|
3. After you implement the `cypher` function, go to the `main` function and uncomment the line that invokes `test_cypher1`. The `test_cypher1` function is a unit test for the `cypher` function. It calls the `cypher` function with various arguments to verify if it returns correct results. If any of the results is incorrect the program stops and reports the test case that failed. You will not see the application’s graphical user interface until the unit test passes all validations. Once you see the graphical user interface you may continue onto the next part of this lab experience.
|
191
|
3. After you implement the `cypher` function, go to the `main` function and uncomment the line that invokes `test_cypher1`. The `test_cypher1` function is a unit test for the `cypher` function. It calls the `cypher` function with various arguments to verify if it returns correct results. If any of the results is incorrect the program stops and reports the test case that failed. You will not see the application’s graphical user interface until the unit test passes all validations. Once you see the graphical user interface you may continue onto the next part of this lab experience.
|
192
|
|
192
|
|
193
|
|
193
|
|
194
|
-### Exercise 2 - Keyword and cleartext of arbitrary lengths
|
|
|
|
|
194
|
+### Exercise 2 - Keyword and Cleartext of Arbitrary Lengths
|
195
|
|
195
|
|
196
|
-In this exercise you will modify the code for the cypher function from Exercise 1 so that the application can now cipher a message using a keyword of arbitrary length.
|
|
|
|
|
196
|
+In this exercise, you will modify the code for the cypher function from Exercise 1 so that the application can now cipher a message using a keyword of arbitrary length.
|
197
|
|
197
|
|
198
|
-#### Instructions:
|
|
|
|
|
198
|
+#### Instructions
|
199
|
|
199
|
|
200
|
1. Modify the implementation of the `cypher` function so that it can cipher a message with a keyword of any (non-zero) length. For this exercise the message may contain any character (including non alphabetical characters). The keyword must consist exclusively of letters.
|
200
|
1. Modify the implementation of the `cypher` function so that it can cipher a message with a keyword of any (non-zero) length. For this exercise the message may contain any character (including non alphabetical characters). The keyword must consist exclusively of letters.
|
201
|
|
201
|
|
|
|
|
|
209
|
| ciphered text | H | Y | @ | X | K | * | T | | K | 8 | A | Z |
|
209
|
| ciphered text | H | Y | @ | X | K | * | T | | K | 8 | A | Z |
|
210
|
|
210
|
|
211
|
|
211
|
|
212
|
- **Figure 7.** Example Vignere cipher of the cleartext `“PR@GR*M T8IS”` using the keyword `SHORT”`.
|
|
|
|
|
212
|
+ **Figure 7.** Example Vigenere cipher of the cleartext `“PR@GR*M T8IS”` using the keyword `SHORT”`.
|
213
|
|
213
|
|
214
|
---
|
214
|
---
|
215
|
|
215
|
|
|
|
|
|
222
|
## Deliverables
|
222
|
## Deliverables
|
223
|
|
223
|
|
224
|
|
224
|
|
225
|
-Use "Deliverable" in Moodle to upload the `cypher.cpp` file that contains the `cypher` function that you created in Exercise 2. Remember to use good programming techniques, include the names of the programmers involved, and to document your program.
|
|
|
|
|
225
|
+Use "Deliverable" in Moodle to upload the `cypher.cpp` file that contains the `cypher` function that you created in Exercise 2. Remember to use good programming techniques, include the names of the programmers involved, and document your program.
|
226
|
|
226
|
|
227
|
|
227
|
|
228
|
---
|
228
|
---
|
|
|
|
|
231
|
|
231
|
|
232
|
## References
|
232
|
## References
|
233
|
|
233
|
|
234
|
-http://www.nctm.org/uploadedImages/Classroom_Resources/Lesson_Plans/
|
|
|
|
|
234
|
+http://www.nctm.org/uploadedImages/Classroom_Resources/Lesson_Plans/
|