Download Document

Document related concepts

Group (mathematics) wikipedia , lookup

Transcript
Arab Open University - AOU
T209
Information and Communication
Technologies: People and Interactions
Fifth Session
1
Dr. Saatchi, Seyed Mohsen
Reference Material

This session is based on the following references:
–
–
–
–

More references:
–
–
2
Module 5: Security, Book S: Security
Module 5: Security, Book N: Numeracy Skills
Module 5: Security, Book E: Experiments
Module 5: Security, (Text Book) Monograph: Security
Techniques in Digital Systems
http://www.cacr.math.uwaterloo.ca/hac/
http://en.wikipedia.org/wiki/Cryptography
Dr. Saatchi, Seyed Mohsen
Topics to be covered in this session

Part 2 (Encryption) of Book S
–

1. (S.2.3.2) Breaking a code
Chapter 2 (Encryption) of Book M (Monograph)
–
2. (M.2.2) Working with codes




Part 2 (Encryption) of Book S
–
–
3
(M.2.2.1) Cracking a code
(M.2.2.3) Diagraphs
(M.2.2.4) Encoding
3. Solve some activities in (S.2.3.2) Breaking a code
4. (S.2.3.3) Encryption using modular multiplication
Dr. Saatchi, Seyed Mohsen
Continue

Part 3 (Modular arithmetic) of Book N
–
5. (N.3.3) Modular multiplication



4
(N.3.3.1) Performing multiplication in modular
arithmetic
(N.3.3.2) The properties of modular multiplication
(N.3.3.3) Summary of Section (N.3.3)
Dr. Saatchi, Seyed Mohsen
Topic 1: (S.2.3.2) Breaking a code

Brute force attack:
–
5
The method of cracking a code by trying all
possible combinations until the correct one is found
is known as a brute force attack
Dr. Saatchi, Seyed Mohsen
Continue

Activity 2.7 (exploratory)
–
How many different arrangements would be possible using the
seven letters of the word article?



Each letter in the word article appears only once
Taking one letter at a time, the first can appear in any of the seven
positions; the second in any of the 6 remaining positions; the third in
any of the five remaining positions; and so on
This gives the total possible number of combinations as:
–

6
7 × 6 × 5 × 4 × 3 × 2 × 1= 5040
An expression giving the product of all the integers from 1 to n is
known as factorial n and is expressed in mathematical notation as n!
Note that the exclamation mark is part of the mathematical expression
Dr. Saatchi, Seyed Mohsen
Continue

Activity 2.8 (self-assessment)
–
Using a computer that can perform one million calculations per
second, calculate how long it would take to try all possible
combinations of:

(a) 10 different letters
–

(b) 15 different letters
–

15! ÷ 106 = 1 307 674 368 000 ÷ 106 seconds = 1 307 674 seconds
= 15.13 days
(c) 20 different letters
–
7
10! ÷ 106 = 3 628 800 ÷ 106 seconds = 3.6 seconds
20! ÷ 106 = 2.432902008177 × 1018 ÷ 106 seconds
= 2.432902008177 × 1012 seconds
= 2 432 902 008 177 seconds
which is approximately 77 147 years
Dr. Saatchi, Seyed Mohsen
Continue

This account of my attempt to ‘crack a cipher’
illustrates a couple of important points:
–
–
8
Attempting to break a cipher by brute force attack can be a
very lengthy process. Often the content of the message is
redundant long before the cipher has been broken. If the
enciphered message ‘Attack tomorrow at dawn’ takes a week
to break then the sender is using an encryption algorithm with
an appropriate level of security for the purpose
An alternative, and usually quicker, method of breaking a code
is through assumptions derived from a knowledge of the
language used in the plaintext message
Dr. Saatchi, Seyed Mohsen
Topic 2: (M.2.2) Working with codes




9
An encryption system that is intended to obfuscate a plaintext
should not be easy to crack
It can be disadvantageous to use an encryption procedure that
does not have a known method for breaking it since it is then
impossible to estimate the effort involved on the part of
crackers and impossible to weigh up the costs they face in
attempting to break the code
Because of the value of knowing how hard it is to crack a code, it
has become commonplace to publish the methods of encryption
and to encourage their investigation
This doctrine is perhaps less relevant for military applications,
but is significant for encryption schemes for pervasive, publicly
accessible systems
Dr. Saatchi, Seyed Mohsen
Continue
Sub-Topic 2.1: (M.2.2.1) Cracking a code


Crackers may know the encryption methods, but initially
do not know the key that decrypts or encrypts
messages and they do not know what the messages are
Example:
–
–
10
For the Caesar code, there are 26 possible keys. One
key, however, leaves the message unaltered (when k = 0)
so there are 25 usable keys
Sometimes, the first key tried might, by chance, decrypt
the message, but on other occasions it would be
necessary to try all 25 possible keys in turn before the
message was revealed
Dr. Saatchi, Seyed Mohsen
Continue
–
–
11
On average, therefore, it would take 12.5 attempts to
find the key
Another way of putting this is to say that the
probability of cracking the code with one attempt
is one in twenty-five or 1/25 = 0.04
Dr. Saatchi, Seyed Mohsen
Topic 2.2: (M.2.2.3) Digraphs

There are three sources of weakness in the Caesar
code:
–
–
–
12
1- The calculations involved in all the encryption, decryption
and cracking processes are fairly simple and easily performed,
especially with a computer on hand
2- The number of possible keys is small so it would be
straightforward to try each of the usable 25 keys until a
recognizable message emerged
3- The statistics of the original message are not camouflaged.
Therefore, knowledge of the kind of message and its
language helps a potential cracker
Dr. Saatchi, Seyed Mohsen
Continue

More Keys the better:
–
–
–
–
13
An encryption system that had more potential keys would
discourage a cracker from using the brute force approach
of trying all the conceivable keys
The Caesar code can be extended to provide more keys
A simple extension would be to encrypt pairs of letters,
which are known as digraphs
There are 26 possible first letters in the pair and for each of
these there are 26 possible second letters giving a total of
26 × 26, which is often written as 262, combinations and
which turns out to be 676
Dr. Saatchi, Seyed Mohsen
Continue

Some modulo 676 Maths:
–
–
–
14
Now to encrypt a pair of letters with 676 combinations it is
possible to work modulo 676 and to draw the codes from
Z676
As with modulo 26 addition, modulo 676 addition means
adding numbers together as usual, but if the result is 676 or
greater, repeatedly subtracting 676 until the result is less
than 676
The key is, therefore, a number between 0 and 675, say
637, then encrypting the coded letters ‘DO’ involves adding,
using modulo 676 addition, the key to the code for the
letter pair, which was calculated to be 92
Dr. Saatchi, Seyed Mohsen
Continue
15

The ciphertext is given by:

Then, using the properties of modulo 676
addition,
Dr. Saatchi, Seyed Mohsen
Continue

To convert the result to a letter pair, divide it by 26:
–

16
53/26 = 2.03846
The whole number part is 2. According to the coding
scheme devised in this section, the first letter of the pair
is given by 2, which encodes the letter C. The 2
accounts for 2 × 26 = 52 of the original code of 53. The
remainder is therefore 53 – 52 = 1. This gives the
second letter of the pair as the second letter of the
alphabet, B. The encrypted pair is then ‘CB’
Dr. Saatchi, Seyed Mohsen
Continue

To decrypt the message the pair ‘CB’ is first encoded
again which gives, as expected,
–
17
2 x 26 + 1 = 53

The decryption key added to the encrypted message
should restore the original plaintext message. For the
Caesar code and in this case, the decryption key, , is
given by the expression:

For a key of 637:

Therefore,
, since
Dr. Saatchi, Seyed Mohsen
Continue

The decrypted message is then given by adding the
decryption key to the encrypted message modulo 676:
–

18
92 is the encoded version of the original plaintext ‘DO’
An advantage of using digraphs is that there are a
larger number of keys to try. The arithmetic too is
becoming a little more involved, though not daunting,
especially if a computer is available
Dr. Saatchi, Seyed Mohsen
Sub-Topic 2.3: (M.2.2.4) Encoding




19
Lets look at encrypting more than one or two letters
Characters can be grouped together in digraphs or
much larger blocks and encrypted in these larger
blocks using potentially larger keys
Consider a black and white picture of a key as in Figure
1
If black is denoted by a one and white by a zero we can
draw out the key on a grid with the numbers highlighting
the different areas as shown in Figure 2 (unencrypted)
Dr. Saatchi, Seyed Mohsen
Continue
Figure 1 A picture of a key sampled for use in a computer
20
Dr. Saatchi, Seyed Mohsen
Continue
21
Figure 2 The picture of the key encoded in 0s and 1s
Dr. Saatchi, Seyed Mohsen
Continue

The picture is not yet in a form that can be
encrypted using the Caesar code. A convention
is needed to sweep up the 1s and 0s into groups
of 5:
–

The numbers representing the above codes are
(shown in Figure 3):
–
22
00000, 00000, 00011, 11111, 10000, 00000, 00000,
00000, 00000, 00000, 00000, 00000, 00000, 00000,
00000
0, 0, 3, 31, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
Dr. Saatchi, Seyed Mohsen
Continue
23
Figure 3 Black and white data grouped into five bit groups
and encoded (still unencrypted)
Dr. Saatchi, Seyed Mohsen
Continue


24
Each number corresponding to a group of five bits can
be encrypted separately and the entire picture encrypted
as the string of numbers taken row after row
Figure 4 shows how the data encrypted using modulo 32
addition would appear if the encrypted data were treated
as a picture when the key is 22 and is the same for each
block of data
Dr. Saatchi, Seyed Mohsen
Continue
Figure 4 The encrypted image reproduced as a picture
25
Dr. Saatchi, Seyed Mohsen
Continue


26
The image is obfuscated but the original image still shows
through. It needs to make the obfuscation more
thorough
Figure 5 shows the image encrypted in blocks of five bits
using modulo 32 addition with a key selected at random
for each successive block. The encryption appears to
be very successful since the original image has been
obscured completely. Of course, to decrypt the
encrypted image, the corresponding random sequence
of decryption keys must also be sent to the recipient,
presumably in secret
Dr. Saatchi, Seyed Mohsen
Continue
Figure 5 The image encrypted using a random
succession of keys
27
Dr. Saatchi, Seyed Mohsen
Continue

28
End of section 2.2 from the Monograph study
material
Dr. Saatchi, Seyed Mohsen
Topic 3: Solve some activities in (S.2.3.2)
Breaking a code

Activity 2.12 (self-assessment)
–
–
Using a Caesar code and a digraph coding similar to the
one described by Monk, what would be:
(a) the ciphertext for the letter pair M E using an encryption
key of 576?


29
M is the 13th letter and E the 5th letter of the alphabet, so they will
be coded as 12 and 4 respectively. The numerical code for the
letter pair is:
12 × 26 + 4 = 316
c p+K mod 676
316+576 mod 676
892 mod 676
216 mod 676
216 = 8 × 26 + 8, A code of 8 is given to the letter in the 9th
position in the alphabet.So using a key of 576 the ciphertext for the
letter pair ME is II
Dr. Saatchi, Seyed Mohsen
Continue
–
(b) the plaintext for the ciphertext 376 which was
encoded with a key of 149?






30
K+
676 mod 676, So
676 - K mod 676
676-149 mod 676
527 mod 676
p c+ mod 676 376+527 mod 676
903 mod 676
227 mod 676, So the coded plaintext letter pair is 227
26 divides into 227 8 times leaving a remainder of 19
So the plaintext letters have been coded as 8 and 19
respectively
These codes represent the letters in the 9th and 20th
positions of the alphabet = IT
Dr. Saatchi, Seyed Mohsen
Continue

Activity 2.13 (self-assessment)
–
–
How many possible keys would there be if we
encrypted the plaintext using:
(a) trigraphs?

–
(b) four-letter groupings?

31
A trigraph (a group of three letters) would result in 263 = 17 576
keys
A four-letter grouping would result in 264 = 456 976 keys
Dr. Saatchi, Seyed Mohsen
Continue

Activity 2.14 (self-assessment)
–
What is the probability of cracking the Caesar
cipher in one attempt when a three-letter key is
used?

32
Between 1 and around 263 = 17 576 attempts would be
needed, giving a probability of 1 / 17576 = 0.0000569 of
cracking it in one attempt
Dr. Saatchi, Seyed Mohsen
Topic 4: (S.2.3.3) Encryption using modular
multiplication

Book N: Numeracy
–
33
Students should work through all of Section 3.3
‘Modular multiplication’ in Book N. A summary follows
Dr. Saatchi, Seyed Mohsen
Topic 5: (N.3.3) Modular multiplication
Sub-Topic 5.1: (N.3.3.1) Performing multiplication in
modular arithmetic


Multiplication in modular arithmetic is carried out in a
similar manner to addition
Example: Calculate 6 × 7 mod 8
–
First multiply the two integers in the conventional way:

–
Then divide the result by 8:

–
–
42 ÷ 8 = 5, remainder 2
Express the answer as the remainder (or residue).
In mathematical language I can express this as:

34
6 × 7 = 42
6×7
2 mod 8
Dr. Saatchi, Seyed Mohsen
Sub-Topic 5.2: (N.3.3.2) The properties of
modular multiplication



35
Figure 6 shows multiplication tables for
modulos 4, 5, 6 and 7
To multiply two numbers together, find the first
number in the top horizontal number line and
the second number in the left vertical number
line
The result of modular multiplication is in the
matrix where the column and row of the
numbers intersect
Dr. Saatchi, Seyed Mohsen
Continue
Figure 6 Multiplication tables for modulos 4, 5, 6 and 7
36
Dr. Saatchi, Seyed Mohsen
Continue

Example: Find 3 × 4 mod 7, Use the modulo 7 table (in
Figure 7)
–
–

1- The property of closure
–
37
Read from the 3 in the top horizontal number line and right
from the 4 in the left vertical number line
The result (5) is shown in the grid where the column and row
intersect
Looking at Figure 6 and Figure 7, we can see that every
operation produces a result that is a member of the set, so the
tables indicate that modular multiplication has the property
of closure
Dr. Saatchi, Seyed Mohsen
Continue
38
Figure 7 Multiplication tables for modulos 4 to 11, with identity highlighted
Continue
Dr. Saatchi, Seyed Mohsen

2- Identity Property (Activity 28 (exploratory))
–
Remember that the identity is defined as e in the
general equation:

–
–
It is that element of the set which when combined
mathematically with any other element of the set will
leave that element unaltered
Here we can replace the symbol º (the symbol used to
denote any mathematical operation) with the
multiplication symbol × giving:

39
a º e = a mod n or e º a = a mod n
a×e
a mod n or e × a
Dr. Saatchi, Seyed Mohsen
a mod n
Continue
–
What the question is asking is: is there an element
within each set which, if multiplied by a, leaves a
unaltered? Yes there is




40
If any element of the set is multiplied by 1 it remains
unaltered
Thus 1 is the identity in modular multiplication
You can check this for yourself from the tables (in Figure 6
and Figure 7) by locating 1 in the top horizontal number line
and looking down its column
Every number in it should be identical to the number
appearing in the left-hand vertical number column of the
same row
Dr. Saatchi, Seyed Mohsen
Continue

3- The multiplicative inverse:
–
–
41
You should recall from Section N.3.2.2 that under
modular addition every element in the set could be
combined with another to return a result equal to the
identity of the set
Figure 7 shows multiplication tables for modulos 4 to
11 with the identity highlighted
Dr. Saatchi, Seyed Mohsen
Continue

Activity 29 (exploratory)
–
–
42
Study the tables in Figure 7. Does every element in
every set have a multiplicative inverse? That is, for
any element of the set is there another element
which, when combined by multiplication, returns a
result equal to the identity of the set under
multiplication?
No. The identity of the set under multiplication is 1 and
not every element in every set can be multiplied with
another element to produce the result 1 mod n
Dr. Saatchi, Seyed Mohsen
Continue

Activity 30 (exploratory)
–
–
–
43
Can you see any pattern emerging in the tables of Figure 7?
Look closely at those elements that do produce a
multiplicative inverse. What is their relationship with the
modulus?
In all the tables the only elements that have a multiplicative inverse
are those that share a highest common factor of 1 with the
modulus. (In effect this means that the only factor they share with
the modulus is 1)
When the element and the modulus share a highest common
factor that is greater than 1, there is no multiplicative inverse
Dr. Saatchi, Seyed Mohsen
Continue

Concept of Coprime:
–
–
44
Two or more numbers whose highest common factor
is 1 are said to be coprime. (Often the expression
relatively prime is used as an alternative to coprime
but in this module I will stick with the term coprime)
Of course, when the modulus itself is a prime
number then it will be coprime with all the members
of the group, since, by definition, a prime number
has no factors other than 1 and itself
Dr. Saatchi, Seyed Mohsen
Continue

Significance of this multiplicative inverse property in
cryptography:
–
–
–
Unlike modular addition, modular multiplication doesn’t always
yield a single solution to the congruence a º x b mod n
Sometimes there is a single solution, sometimes there is more
than one solution, and sometimes there is no solution at all
One important point to note is that if the modulus is prime then
there will always be one single solution

45
Where a number is coprime with the modulus, multiplication by
any other number in the group produces a single solution. Thus
when the modulus itself is prime (so that all the elements in the set
are coprime with it) every element produces a single solution
Dr. Saatchi, Seyed Mohsen
Continue

Activity 31 (self-assessment)
–
How many solutions exist for the value of x in the
congruence 4 × x 2 mod n







46
(a) when n = 5?
(b) when n = 6?
(c) when n = 7?
(d) when n = 8?
(e) when n = 9?
(f) when n = 10?
(g) when n = 11?
1
2
1
0
1
2
1
Dr. Saatchi, Seyed Mohsen
Continue

Example:
–
Imagine I need to send you secretly the number 4 and
that we have already agreed between us an encryption
method whereby I will work in modulo 9 and encrypt
any number that I send you by multiplying it by 3:

–
3 mod 9
I send you the encrypted number 3. Would you be
able to decrypt my message?

47
4×3
If you look at the table in Figure 8 you will see that the result 3
arises from the congruence 4 × 3 mod 9 and the congruence
7× 3 mod 9. You couldn’t be sure whether my original
number had been 4 or 7
Dr. Saatchi, Seyed Mohsen
Continue
Figure 8 Multiplication table for modulo 9
48
Dr. Saatchi, Seyed Mohsen
Continue
–
If instead we had agreed to use one of the elements
that produces a single solution for multiplication
in modulo 9 this ambiguity would not have arisen.
Let’s say we had agreed on 7 as the multiplier:

–
49
4×7
1 mod 9
Since the result of 1 has no duplicates for the
solution of x in the congruence x×7 1 mod 9 you
could be confident that your decryption recovers
my original value
Dr. Saatchi, Seyed Mohsen
Continue

To take this a step further, how would you have
decrypted this message?
–
–
–
–
50
You could have tested every element in modulo 9, multiplying it
with 7 until you found one that produced the result 1
Or instead you could have found the multiplicative inverse of
7 and multiplied 1 by this to recover my original value.
(Remember that successive multiplication of a number by a
multiplicative inverse pair will leave the number unaltered.)
The multiplicative inverse of 7 mod 9 is 4 (which you can
check in the table of Figure 8 if you need to reassure yourself of
this)
You would then evaluate the congruence 1 × 4 4 mod 9 to
recover the original value of 4
Dr. Saatchi, Seyed Mohsen
Continue

Activity 32 (exploratory)
–
–
–
51
In Figure 8 the multiplication table for modulo 9 is reproduced.
Do any of the elements in the set produce a single solution
when multiplied by each of the other set elements?
Yes. When I look at the columns under the numbers 1, 2, 4, 5, 7
and 8 in the modulo 9 multiplication table, I find that there are no
duplicates, so these six elements do produce a single solution
when multiplied by any other member of the set
The interesting characteristic of these six elements is that they
are all coprime with the modulus, which means they are also
elements which have a multiplicative inverse. The elements 3
and 6 share a common factor (3) with the modulus. These
elements all show duplicates in the column
Dr. Saatchi, Seyed Mohsen
Continue

Activity 33 (self-assessment)
–
Using multiplicative inverses find the solution for x in each of
the following:

(a) x × 3
–


9 mod 10
The multiplicative inverse of 7 mod 10 is 3, so the value of x can be found
from the congruence 9×3 7 mod 10. So x = 7
(c) x × 9
–
52
The multiplicative inverse of 3 mod 10 is 7, so the value of x can be found
from the congruence 5×7 5 mod 10. So x = 5
(b) x × 7
–
5 mod 10
6 mod 10
The multiplicative inverse of 9 mod 10 is 9, so the value of x can be found
from the congruence 6×9 4 mod 10. So x = 4
Dr. Saatchi, Seyed Mohsen
Continue

4- The associative property
–
Modular multiplication is associative. In other words:


a × (b × c) mod n
5- The commutative property
–
There is one more property to check before we leave modular
multiplication – the commutative property. You saw in Section
3.2.2 that in conventional arithmetic multiplication is
commutative. A simple example can be used to investigate
whether or not modular multiplication is commutative:


–
53
(a × b) × c
5×7
7×5
3 mod 8
3 mod 8
So,

5 × 7 mod 8
7 × 5 mod 8
Dr. Saatchi, Seyed Mohsen
Continue
–
This demonstrates that modular multiplication is
commutative. I can state this generally as:

54
a × b mod n
b × a mod n
Dr. Saatchi, Seyed Mohsen
Sub-Topic 5.3: (N.3.3.3) Summary of Section
(N.3.3)

1- The group has one element, the identity e such that
–
–
–

2- Within a group, any element (which we will call a) that
is coprime with the modulus n has a multiplicative
inverse (which we will call ) such that
–

55
a × e a or e× a a
For modular multiplication the identity e is 1
In modular multiplication the result of a × 0 mod n is
always 0
a×
e mod n
1 mod n
3- There is no single solution for x to the equation
a × x b mod n unless a is coprime with the
modulus
Dr. Saatchi, Seyed Mohsen
Continue


4- When the modulus itself is prime, it is
coprime with all elements of the group
5- When an element (which we will call x) of a
group is successively multiplied by a
multiplicative inverse pair (a and ) the result
is x:
x×a×


56
x mod n
6- Modular multiplication is associative
7- Modular multiplication is commutative
Dr. Saatchi, Seyed Mohsen
Topic 6: Preparation for next session
–
–
Continue reading about Module 5
Try to study hard for Quiz3 in next session

–
57
From 1st session to 4th session
The due date of TMA04 is Apr. 16
Dr. Saatchi, Seyed Mohsen