Lecture
26
Handouts
Encryption.html
Computer Dating Questionnaire
Light Bulb Jokes/Computer Dating
Today's Agenda
Drop-Down Menus
Computer Dating
The Encryption Program
Cryptology
and Computer Security
![]() |
![]() |
HTML/JavaScript Trick of the Day
Drop Down Menus
<HTML>
<HEAD>
<TITLE>Light Bulb Jokes</TITLE>
<SCRIPT LANGUAGE = "Javascript">
var A = new Array(5);
A[1] = "Five--one to change the light bulb and four to find the perfect J. Crew outfit to wear for the occasion";
A[2] = "One--he holds the bulb and the world revolves around him.";
A[3] = "None--Hanover does not have electricity." ;
A[4] = "Thirteen--one
to change the bulb and an a capella group to immortalize the event in song.";
function Begin()
{ var index, response;
index = document.MyForm.College.selectedIndex;
response = document.MyForm.College.options[index].value;
document.MyForm.Answer.value = A[response];
}
</SCRIPT>
</HEAD>
<BODY BGCOLOR = "white">
<FORM NAME = "MyForm" >
<H2>How many students at your favorite college does it take to change a light bulb?
<H3>Select a College:
<SELECT NAME = "College" >
<OPTION VALUE = "1" SELECTED >Middlebury
<OPTION VALUE = "2">Harvard
<OPTION VALUE = "3">Dartmouth
<OPTION VALUE = "4">Amherst
</SELECT>
<P>
Answer:<BR>
<TEXTAREA NAME = "Answer" ROWS = 5 COLS = 100> </TEXTAREA>
</P>
<INPUT TYPE = "button" VALUE = "Click for Answer" SIZE = "20"
ONCLICK = "Begin()" >
</FORM>
</BODY>
</HTML>
CX 103 Computer Dating Questionnaire
Name
Answer Each of the following Questions with a "YES" or a "NO"
You may check the appropriate
box:
Question | Yes | No |
Do you prefer raw carrots to cooked carrots? | ||
Do you prefer black jelly beans to other colors? | ||
Do you like Burger King more than McDonald's? | ||
Do you prefer to squeeze toothpaste from the bottom of the tube? | ||
Do you like the morning more than the evening? | ||
Do you prefer cats to dogs? | ||
Do you prefer the Red Sox to the Yankees? | ||
Do you prefer jazz to opera? | ||
Do you prefer pickup trucks to SUV's? | ||
Do you enjoy sleeping with the window open? |
Arrays and Computer Dating Services
#1 | #2 | #3 | #4 | #5 | #6 | #7 | #8 | #9 | #10 | |
Andrew | Yes | No | No | Yes | Yes | Yes | Yes | No | No | No |
Annalise | Yes | Yes | Yes | No | No | Yes | No | No | Yes | Yes |
Beth | Yes | Yes | No | No | Yes | No | Yes | Yes | Yes | Yes |
Bob | No | Yes | Yes | Yes | No | No | No | Yes | No | No |
Brendan | Yes | No | Yes | Yes | Yes | No | No | Yes | Yes | Yes |
Casey | Yes | No | Yes | Yes | No | Yes | Yes | No | Yes | Yes |
Charles M | Yes | No | No | Yes | Yes | No | Yes | Yes | No | Yes |
Charles R | No | Yes | No | Yes | Yes | No | No | Yes | No | No |
Colin | Yes | Yes | Yes | No | No | No | Yes | Yes | Yes | Yes |
David M | Yes | No | Yes | Yes | No | Yes | No | Yes | Yes | No |
David R | No | No | No | No | No | Yes | Yes | Yes | Yes | No |
David S | Yes | No | No | Yes | No | Yes | No | No | No | Yes |
Eliza | Yes | Yes | No | Yes | Yes | No | No | Yes | Yes | Yes |
John | No | Yes | No | Yes | Yes | No | Yes | No | No | Yes |
Jordan | Yes | Yes | No | Yes | Yes | No | Yes | No | Yes | No |
Kate | Yes | No | No | No | No | No | Yes | Yes | No | Yes |
Kennan | Yes | Yes | No | No | No | No | No | Yes | No | Yes |
Liz | No | Yes | No | Yes | Yes | No | No | No | Yes | Yes |
Louisa | Yes | No | No | Yes | No | No | Yes | Yes | No | No |
Matt | No | Yes | No | No | Yes | Yes | No | Yes | Yes | No |
Megan | Yes | No | No | Yes | Yes | Yes | Yes | No | Yes | No |
Missy | No | No | No | Yes | No | No | No | Yes | No | No |
Nathaniel | Yes | No | No | No | Yes | No | No | Yes | No | Yes |
Rada | No | No | Yes | Yes | Yes | No | Yes | Yes | Yes | Yes |
Rebecca | No | Yes | No | Yes | No | No | No | Yes | No | Yes |
Ryan B | Yes | No | Yes | Yes | Yes | Yes | No | No | Yes | No |
Ryan P | Yes | Yes | No | No | Yes | No | No | No | Yes | Yes |
Ted | Yes | No | Yes | Yes | No | Yes | Yes | Yes | Yes | Yes |
Tejas | Yes | No | Yes | Yes | No | No | Yes | Yes | Yes | No |
Trevor | No | Yes | No | Yes | No | Yes | Yes | No | No | Yes |
Tyler | No | Yes | No | No | No | No | Yes | Yes | Yes | No |
Veljko | No | Yes | Yes | Yes | No | No | Yes | No | No | Yes |
Consider an array with 33 elements with elements 1 through 32 corresponding to the individual students in the class. The element in cell 0 is the instructor, but his answers to the questions are not known.
Each element Student[i] is itself an array with 12 cells. In cell 0 is the student's name. In cells 1 - 10 are the "Yes" or "No" answers to each question.
Cell 11 is reserved for
saving the number of matches with some other prescribed student
Rebecca | No | Yes | No | Yes | No | No | No | Yes | No | Yes | |
David S | Yes | No | No | Yes | No | Yes | No | No | No | Yes | 6 |
Rebecca | No | Yes | No | Yes | No | No | No | Yes | No | Yes | |
Tyler | No | Yes | No | No | No | No | Yes | Yes | Yes | No | 6 |
Rebecca | No | Yes | No | Yes | No | No | No | Yes | No | Yes | |
Veljko | No | Yes | Yes | Yes | No | No | Yes | No | No | Yes | 7 |
<HEAD> <TITLE>Computer Dating </TITLE>
<SCRIPT LANGUAGE = "JavaScript" >;
var Student = new Array(5);
for (i = 0; i <= 32; i = i + 1)
Student[i] = new Array(12);
Student[1] = ["Andrew", "Yes", "No", "No", "Yes", "Yes", "Yes", "Yes", "No", "No", "No",0];
Student[2] = ["Annalise", "Yes", "Yes", "Yes", "No", "No", "Yes", "No", "No", "Yes", "Yes",0];
Student[3] = ["Beth", "Yes", "Yes", "No", "No", "Yes", "No", "Yes", "Yes", "Yes", "Yes",0];
Student[4] = ["Bob", "No", "Yes", "Yes", "Yes", "No", "No", "No", "Yes", "No", "No",0];
Student[5] = ["Brendan", "Yes", "No", "Yes", "Yes", "Yes", "No", "No", "Yes", "Yes", "Yes",0];
Student[6] = ["Casey", "Yes", "No", "Yes", "Yes", "No", "Yes", "Yes", "No", "Yes", "Yes",0];
Student[7] = ["CharlesM", "Yes", "No", "No", "Yes", "Yes", "No", "Yes", "Yes", "No", "Yes",0];
Student[8] = ["CharlesR", "No", "Yes", "No", "Yes", "Yes", "No", "No", "Yes", "No", "No",0];
Student[9] = ["Colin", "Yes", "Yes", "Yes", "No", "No", "No", "Yes", "Yes", "Yes", "Yes",0];
Student[10] = ["DavidM", "Yes", "No", "Yes", "Yes", "No", "Yes", "No", "Yes", "Yes", "No",0];
Student[11] = ["DavidR", "No", "No", "No", "No", "No", "Yes", "Yes", "Yes", "Yes", "No",0];
Student[12] = ["DavidS", "Yes", "No", "No", "Yes", "No", "Yes", "No", "No", "No", "Yes",0];
Student[13] = ["Eliza", "Yes", "Yes", "No", "Yes", "Yes", "No", "No", "Yes", "Yes", "Yes",0];
Student[14] = ["John", "No", "Yes", "No", "Yes", "Yes", "No", "Yes", "No", "No", "Yes",0];
Student[15] = ["Jordan", "Yes", "Yes", "No", "Yes", "Yes", "No", "Yes", "No", "Yes", "No",0];
Student[16] = ["Kate", "Yes", "No", "No", "No", "No", "No", "Yes", "Yes", "No", "Yes",0];
Student[17] = ["Kennan", "Yes", "Yes", "No", "No", "No", "No", "No", "Yes", "No", "Yes",0];
Student[18] = ["Liz", "No", "Yes", "No", "Yes", "Yes", "No", "No", "No", "Yes", "Yes",0];
Student[19] = ["Louisa", "Yes", "No", "No", "Yes", "No", "No", "Yes", "Yes", "No", "No",0];
Student[20] = ["Matt", "No", "Yes", "No", "No", "Yes", "Yes", "No", "Yes", "Yes", "No",0];
Student[21] = ["Megan", "Yes", "No", "No", "Yes", "Yes", "Yes", "Yes", "No", "Yes", "No",0];
Student[22] = ["Missy", "No", "No", "No", "Yes", "No", "No", "No", "Yes", "No", "No",0];
Student[23] = ["Nathaniel", "Yes", "No", "No", "No", "Yes", "No", "No", "Yes", "No", "Yes",0];
Student[24] = ["Rada", "No", "No", "Yes", "Yes", "Yes", "No", "Yes", "Yes", "Yes", "Yes",0];
Student[25] = ["Rebecca", "No", "Yes", "No", "Yes", "No", "No", "No", "Yes", "No", "Yes",0];
Student[26] = ["RyanB", "Yes", "No", "Yes", "Yes", "Yes", "Yes", "No", "No", "Yes", "No",0];
Student[27] = ["RyanP", "Yes", "Yes", "No", "No", "Yes", "No", "No", "No", "Yes", "Yes",0];
Student[28] = ["Ted", "Yes", "No", "Yes", "Yes", "No", "Yes", "Yes", "Yes", "Yes", "Yes",0];
Student[29] = ["Tejas", "Yes", "No", "Yes", "Yes", "No", "No", "Yes", "Yes", "Yes", "No",0];
Student[30] = ["Trevor", "No", "Yes", "No", "Yes", "No", "Yes", "Yes", "No", "No", "Yes",0];
Student[31] = ["Tyler", "No", "Yes", "No", "No", "No", "No", "Yes", "Yes", "Yes", "No",0];
Student[32] = ["Veljko", "No", "Yes", "Yes", "Yes", "No", "No", "Yes", "No", "No", "Yes",0];
client1 = parseInt(window.prompt("Enter number of first client","") );
client2 = parseInt(window.prompt("Enter number of second client","") );
document.writeln("<H2>");
Matches = 0;
for (j = 0; j <= 10; j = j + 1)
{ document.writeln( Student[client1][j] + " <FONT COLOR = red > " + Student[client2][j] +"</FONT><BR>");
if ( Student[client1][j] == Student[client2][j] ) Matches = Matches + 1
}
document.writeln("<BR>" + "Number of matches " + Matches);
</SCRIPT>
</HEAD> <BODY BGCOLOR = "linen"); </BODY> </HTML>
ENCRYPTION ASSIGNMENT
Encryption.html
Original:
Break message into pairs of consecutive characters.
Replace each pair by 4 digit number made up of their ASCII values
Add 7 % 10 to each digit.
Reverse the digits.
1. | <HTML> |
2. | <HEAD> |
3. | <TITLE>Stage One of Encryption</TITLE> |
4. | <SCRIPT LANGUAGE = "Javascript"> |
5. | |
6. | var W, i, S; |
7. | |
8. | |
9. | function Begin() |
10. | { var i, A,B,S, T, Number, Length, M, First, Second, Third, Fourth; |
11. | W = document.EncryptForm.Phrase.value; |
12. | |
13. | Length = W.length; |
14. | |
15. | S = "It has " + Length + " characters."; |
16. | Append = "That
is an odd number. I will append an X to the end and
proceed with the encryption." |
17. | |
18. | |
19. | |
20. | if (W.length % 2 == 1) |
21. | { S = S + Append; |
22. | W = W + "X"; |
23. | Length = Length + 1 } |
24. | |
25. | var Originals = new Array(Length/2); |
26. | |
27. | document.EncryptForm.Comment.value = S; |
28. | |
29. | T = "Its original numerical representation is "; |
30. | document.EncryptForm.Digits.value = T; |
31. | |
32. | for (i = 0; i < Length ; i = i + 2) |
33. | { A = W.charCodeAt(i) ; |
34. | B = W.charCodeAt(i+1) ; |
35. | Number = 100*A + B; |
36. | Originals[i/2] = Number; |
37. | } |
38. | |
39. | document.EncryptForm.plain.value = Originals.join(" ");; |
40. | |
41. | var Scrambleds = new Array (Length/2); |
42. | var Digits = new Array(4) |
43. | |
44. | function power(k) |
45. | { var i, N; |
46. | N = 1; |
47. | for (i = 1; i <= k; i = i+ 1) N = N * 10; |
48. | return N; |
49. | } |
50. | |
51. | for (i = 0; i < Length/2; i = i + 1) |
52. | { |
53. | M = Originals[i]; |
54. | for (j = 0; j <= 3; j = j+ 1) |
55. | { Digits[j] = Math.floor(M/power(j)); |
56. | Digits[j] = ( Digits[j] + 7) % 10; } |
57. | M = 0; |
58. | for (j = 0; j <= 3; j = j+ 1) |
59. | M = M + Digits[j] * power(3-j); |
60. | |
61. | |
62. | Scrambleds[i] = M |
63. | } |
64. | |
65. | document.EncryptForm.Scrambled.value = Scrambleds.join(" "); |
66. | |
67. | |
68. | } |
69. | |
70. | |
71. | </SCRIPT> |
72. | </HEAD> |
73. | <BODY BGCOLOR = "white"> |
74. | <FORM NAME = "EncryptForm"> |
75. | Enter a word or phrase <INPUT NAME = "Phrase" SIZE = 80 TYPE = "text"> |
76. | <BR> |
77. | <INPUT TYPE = "button" VALUE = "Click to Encrypt" SIZE = "20" |
78. | ONCLICK = "Begin()" > |
79. | <BR> |
80. | <TEXTAREA
NAME = "Comment" ROWS =4 COLS = 50 TYPE =
"text"> </TEXTAREA> |
81. | <BR> |
82. | <INPUT NAME = "Digits" SIZE = 50 TYPE = "text"> |
83. | <BR> |
84. | <TEXTAREA NAME = "plain" ROWS = 5 COLS = 50 TYPE = "text"> </TEXTAREA> |
85. | <BR> |
86. | <H2>The encrypted message is: |
87. | <BR> |
88. | <TEXTAREA
NAME = "Scrambled" ROWS = 5 COLS = 50
TYPE = "text"> |
89. | </TEXTAREA> |
90. | </FORM> |
91. | </BODY> |
92. | </HTML> |
How secure is this method?
How can we make it more secure?
(1) Use a different number other than 7 to add mod 10. Keep that digit secret.
(2) Try some other rearrangment of the digits. (also secret)
How many possibilities are there?
( 10 numbers ) * (4! = 24 rearrangements) = 240
Could we "crack" a secret
message by brute force?
(3) Use a different number to add to each digit
Example: Add 2 % 10 to First Digit
Add 9 % 10 to Second Digit
Add 5 % 10 to Third Digit
Add 7 % 10 to Fourth Digit
How many possibilites are there now?
10 * 10 * 10 * 10 * 4! = 240, 000
(4)
Use triples of characters to make up six digit numbers.
How many possibilites are there now?
( 10 * 10 * 10 * 10 *
10 * 10) * 6! = 720,000,000
We are a little ahead of the game.
For now, let's continue to add 7 % 10 to each digit and reverse the digits when we are done, but we'll work with 6 digit numbers instead of 4 digit numbers:
Example:
MIDDLEBURY_COLLEGE
Triple | ASCII | + 7 % 10 | Reverse |
MID | 777368 | 444035 | 530444 |
DLE | 687669 | 354336 | 633453 |
BUR | 668582 | ||
Y_C | 893267 | ||
OLL | 797676 | ||
EGE | 697160 | ||
M | I | D | D | L | E | B | U | R | Y | C | O | L | L | E | G | E | |
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |
77 | 73 | 68 | 68 | 76 | 69 | 66 | 85 | 82 | 89 | 32 | 67 | 79 | 76 | 76 | 69 | 71 | 69 |
Programming Issues:
(1)
W is "plaintext" character string
Length of W is W.length
If W.length is not a multiple of 3, we need to pad on extra X's at the end.
How many X's ?
W.length % 3 | Number of X's |
0 | 0 |
1 | 2 |
2 | 1 |
Extensions: If we plan to break up message into blocks of k letters, then length must be a multiple of k.
Example: k = 6
W.length % 6 | Number of X's | |
0 | 0 | |
1 | 5 | 6 - 1 |
2 | 4 | 6 - 2 |
3 | 3 | 6 - 3 |
4 | 2 | 6 - 4 |
5 | 1 | 6 - 5 |
Issue (2): Getting the
six digit number
32. | for (i = 0; i < Length ; i = i + 2) |
33. | { A = W.charCodeAt(i) ; |
34. | B = W.charCodeAt(i+1) ; |
35. | Number = 100*A + B; |
36. | Originals[i/2] = Number; |
for (i = 0; i < Length ; i = i + 3)
{ A = W.charCodeAt(i) ;
B = W.charCodeAt(i+1);
C = W.charCodeAt(i+2);
Number = 10000*A + 100*B+ C;
Originals[i/3] = Number; }
Questions:
What if we use blocks of 6 consecutive characters?
k consecutive characters where k is specified by user when program runs?
Issue (3) Getting the
individual digits:
51. | for (i = 0; i < Length/2; i = i + 1) |
52. | { |
53. | M = Originals[i]; |
54. | for (j = 0; j <= 3; j = j+ 1) |
55. | { Digits[j] = Math.floor(M/power(j)); |
56. | Digits[j] = ( Digits[j] + 7) % 10; } |
57. | M = 0; |
58. | for (j = 0; j <= 3; j = j+ 1) |
59. | M = M + Digits[j] * power(3-j); |
Issue (4) reporting the
results:
41. | var Scrambleds = new Array (Length/2); |
62. | Scrambleds[i] = M |
63. | } |
64. | |
65. | document.EncryptForm.Scrambled.value = Scrambleds.join(" "); |
86. | <H2>The encrypted message is: |
87. | <BR> |
88. | <TEXTAREA
NAME = "Scrambled" ROWS = 5 COLS = 50
TYPE = "text"> |
The Output
65. | document.EncryptForm.Scrambled.value = Scrambleds.join(" "); |
produces
530444 633453 952533 439065
343464 638463 50490 546490 649063 159074 906394 56333 349015 633304 342395
952390 900515 346443 846334 900563 905404 639415 312590 553105
while
document.EncryptForm.Scrambled.value = Scrambleds.join("")
produces;
5304446334539525334390653434646384635049054649064906315907490639456333349015633304342395952390900515346443846334900563905404639415312590553105
Two computer programmers are driving on a Highway. They switch on the radio and there is a warning: Please note that a car is driving on highway 75 against the traffic. The programmer near the driver looks at him and says: One? There are hundreds of them. |
Cryptology
and Computer Security
Why Should You Be Interested in Cryptology?
Historical Importance
Military
Diplomatic
Contemporary Importance
Data Protection
Secure Communications
Vehicle to Study Mathematical Topics
|
|
|
|
|
|
|
|
Intellectual Stimulation
Many Open Research Questions
Links to Other Disciplines
Engineering
Linguistics
CRYPTOGRAPHY | CRYPTANALYSIS |
Hiding
the meaning
of messages |
Discovering
the meaning
of intercepted messages |
CRYPTOGRAPHY
A) HIDING THE EXISTENCE OF A MESSAGE
Steganography
Invisible Ink
Microdots
Pinholes
B) HIDING THE MEANING OF A MESSAGE
Transpositions
Substitutitons
CODES
CIPHERS
CODES
plaintext | ATTACK AT DAWN |
coded text | 15921 24586 49198 |
CIPHERS
Example: Replace each
letter by the next one in the alphabet
plaintext | ATTACK AT DAWN |
ciphertext | BUUBDL BU EBXO |
MONALPHABETIC SUBSTITUTION
POLYALPHABETIC SUBSTITUTION
POLYGRAPHIC
SYSTEMS
MONALPHABETIC SUBSTITUTION
Caesar Cipher: Replace
each letter of the message by the letter 3 places beyond it in the normal
alphabet.
plaintext | A | B | C | D | E | F | G | H | I | J | K | L | M |
ciphertext | D | E | F | G | H | I | J | K | L | M | N | O | P |
plaintext | N | O | P | Q | R | S | T | U | V | W | X | Y | Z |
ciphertext | Q | R | S | T | U | V | W | X | Y | Z | A | B | C |
AT T ACK AT DAWN
DWWDFN DW GD ZQ
of Caesar Cipher
1) Replace each letter by its position in the alphabet
2) Add 3 % 26 to the position
3) Replace resulting number
by its letter equivalent
M
--> 13 --> 16 --> P
In JavaScript
Phrase is variable name; it contains a character string.
The first character in Phrase is Phrase.charAt(0);
Its ASCII value is ascii = Phrase.charCodeAt(0);
Its position in the alphabet is position = ascii - 64
To add 3 mod 26: cipherPosition =(position + 3) % 26
Now cipherPosition is the position of new letter in the alphabet.
Its ASCII value is x = cipherPosition + 64.
The corresponding letter
is String.fromCharCode(x)
Summarizing:
ascii = Phrase.CharCodeAt(0);
position = ascii - 64;
cipherPosition =(position + 3) % 26
NewAscii = cipherPosition + 64
CipherCharacter = String.fromCharCode(NewAscii)
Caesar.html
PlainText
Character |
CipherText
Character |
PlainText
Character |
CipherText
Character |
|
A | D | N | Q | |
B | E | O | R | |
C | F | P | S | |
D | G | Q | T | |
E | H | R | U | |
F | I | S | V | |
G | J | T | W | |
H | K | U | X | |
I | L | V | Y | |
J | M | W | Z | |
K | N | X | A | |
L | O | Y | B | |
M | P | Z | C |
Note that the red letters are just a rearrangement of the blue letters.
Any rearrangement of the alphabet produces another substitutiton scheme.
Here is another way to get a rearrangement;
Pick a key word: VERMONT
Make the letters the heads of columns in a table.
Fill in the rest of the
alphabet into the table from left to right.
V | E | R | M | O | N | T |
A | B | C | D | F | G | H |
I | J | K | L | P | Q | S |
U | W | X | Y | Z |
Then read the letters out of the table, column by column
going from left to right, reading each column from top to bottom:
VAIU EBJW RCKX MDLY OFPZ
NGQ THS
This will be our arranged alphabet:
VAIUEBJWRCKXMDLYOFPZNGQTHS
The New Substiution Table
PlainText
Character |
CipherText
Character |
PlainText
Character |
CipherText
Character |
|
A | V | N | D | |
B | A | O | L | |
C | I | P | Y | |
D | U | Q | O | |
E | E | R | F | |
F | B | S | P | |
G | J | T | Z | |
H | W | U | N | |
I | R | V | G | |
J | C | W | Q | |
K | K | X | T | |
L | X | Y | H | |
M | M | Z | S |
How Many Rearrangements of the Alphabet are There?
26 * 25 * 24 * ... * 3
* 2 * 1 = 26!
26! is about 4 followed
by 26 0's
We can use any of these monoalphabetic substitutions to encipher a message.
Suppose we intercept a message that was enciphered by using one of these schemes.
We try to "crack the code" by checking every possible scheme.
Would this work in theory?
Would in work in practice?
Suppose we could check 1,000,000 per second.
How long would it take
to check them all?