3. • Divisibility and the Division Algorithm
• The Euclidean Algorithm
• Modular Arithmetic, Prime Numbers, Fermat’s and Euler’s Theorems,
Testing for Primality, The Chinese Remainder Theorem
• Traditional Symmetric-Key Ciphers: Substitution ciphers:
Monoalphabetic ciphers, Polyalphabetic ciphers, Transposition ciphers.
Stream Ciphers and Block Ciphers: Stream Ciphers, Block Ciphers.
Unit 1 CONTENTS
4. Divisors
● A non-zero Number b divides a if for some m have a=mb (a,b,m all integers)
i.e b divides into a with no remainder and is denoted as b | a and is said b is a
divisor of a.
● Ex: 1,2,3,4,6,8,12,24 divide 24
● 13 | 182, -5 | 30, 17 | 289, -3|33, 17 | 0
5. Properties of Divisibility
● If a | 1, then a= ± 1
● If a | b and b | a, then a= ±b
● Any b≠0 divides 0
● If a | b and b | c then a | c. Ex: 11 | 66 and 66 |198 = 11 | 198
● If b | g and b | h then b | (mg+nh) For arbitrary integers m and n, note that
• If b | g, then g is of the form g = b * g1 for some integer g1
• If b | h, then h is of the form h = b * h1 for some integer h1
So mg + nh = mbg1 + nbh1 = b * (mg1 + nh1)
● and therefore b divides mg + nh.
○ Ex: b=7; g=14; h=63; m=3; n=2
■ Hence 7|14 and 7| 63
6. The Division Algorithm
● Given any positive integer n and any nonnegative integer a, if we divide a by n,
we get an integer quotient q and an integer remainder r that obey the following
relationship:
a = qn + r 0<=r<n; q= floor(a/n) (4.1)
● Equation (4.1) is referred to as the division algorithm.
● Figure 4.1a demonstrates that, given a and positive n, it is always possible to
find q and r that satisfy the preceding relationship.
● Represent the integers on the number line; a will fall somewhere on that line
Starting at 0, proceed to n, 2n, up to qn, such that qn <= a and (q + 1)n > a.
● The distance from qn to a is r, and we have found the unique values of q and r.
The remainder r is often referred to as a residue.
8. The Euclidean Algorithm
● One of the basic techniques of number theory is the Euclidean algorithm, which is a simple procedure
for determining the GCD of two positive integers. 2 integers are relatively prime if their only common
positive integer factor is 1.
● Greatest Common Divisor
● Non zero b is defined to be a divisor of a if a = mb for some m, where a, b, and m are integers.
● The greatest common divisor of a and b is the largest integer that divides both a and b. Also gcd(0, 0)
= 0.
● More formally, the positive integer c is said to be the greatest common divisor of a and b if
1. c is a divisor of a and of b.
2. Any divisor of a and b is a divisor of c.
● An equivalent definition is the following:
● gcd(a, b) = max[k, such that k | a and k | b]
● Because we require that the greatest common divisor be positive, gcd(a, b) = gcd(a, -b) =
gcd(-a, b) = gcd(-a,-b). In general, gcd(a, b) = gcd( a , b ).
gcd(60, 24) = gcd(60, -24) = 12
9. ● Also, because all nonzero integers divide 0, we have gcd(a, 0) = a .
● It is stated that two integers a and b are relatively prime if their only common
positive integer factor is 1. This is equivalent to saying that a and b are relatively
prime if gcd(a, b) = 1.
● 8 and 15 are relatively prime because the positive divisors of 8 are 1, 2, 4, and
8, and the positive divisors of 15 are 1, 3, 5, and 15. So 1 is the only integer on
both lists.
10. Finding the Greatest Common Divisor
● Euclid for easily finding the greatest common divisor of two integers.
● Suppose we have integers a, b such that d = gcd(a, b).
● Because gcd( | a | , | b | ) = gcd(a, b), there is no harm in assuming a >= b > 0. Now dividing a by
b and applying the division algorithm, we can state:
a = q1b + r1 0 <=r1 < b (4.2)
● If it happens that r1 = 0, then b | a and d = gcd(a, b) = b. But if r1 != 0, we can state that d | r1.
This is due to the basic properties of divisibility: the relations d | a and d | b together imply that d
(a - q1b), which is the same as d | r1.
● Consider 4.2 and assume that r1!= 0. Because b > r1,
● we can divide b by r1and apply the division algorithm to obtain:
b = q2r1 + r2 0 <=r2 < r1
● As before, if r2 = 0, then d = r1 and if r2!=0, then d = gcd(r1, r2). The division
● process continues until some zero remainder appears, say, at the (n + 1)th stage where rn-1 is
divided by rn. The result is the following system of equations:
11. Finding the Greatest Common Divisor
● At each iteration, we have d = gcd(ri, ri+1) until finally d = gcd(rn, 0) = rn.
● Thus, GCD of two integers can be found by repetitive application of the division
algorithm. This scheme is known as the Euclidean algorithm.
12. Modular Arithmetic
● The Modulus : If a is an integer and n is a positive integer, a mod n is he
remainder. when a is divided by n. The integer n is called the modulus. Thus, for
any integer a, we can rewrite Equation (4.1) as a = qn + r 0<=r<n; q = floor (a/n );
● a = floor (a/n ) * n + (a mod n)
Ex: 11 mod 7 = 4; - 11 mod 7 = 3
● Two integers a and b are said to be congruent modulo n, if (a mod n) = (b mod n).
This is written as a ≡ b (mod n)
● 73 ≡ 4 (mod 23) 21 ≡ -9 (mod 10)
● Note that if a ≡ 0 (mod n), then n | a.
13. Properties of Congruences
● Congruences have the following properties:
1. a ≡ b (mod n) if n (a - b).
2. a ≡ b (mod n) implies b ≡ a (mod n).
3. a ≡ b (mod n) and b ≡ c (mod n) imply a ≡ c (mod n).
● To demonstrate the first point, if n (a - b), then (a - b) = kn for some k.
● So we can write a = b + kn. Therefore, (a mod n) = (remainder when b + kn is
divided by n) = (remainder when b is divided by n) = (b mod n).
● 23 ≡ 8 (mod 5) because 23 - 8 = 15 = 5 * 3
● -11 ≡ 5 (mod 8) because -11 - 5 = -16 = 8 * (-2)
● 81 ≡ 0 (mod 27) because 81 - 0 = 81 = 27 * 3
14. Modular Arithmetic Operations
● By definition, the (mod n) operator maps all integers into the set of integers {0, 1, c, (n -
1)}. arithmetic operations within the confines of this set? Yes ; this technique is known as
modular arithmetic.
● Modular arithmetic exhibits the following properties:
1. [(a mod n) + (b mod n)] mod n = (a + b) mod n
2. [(a mod n) - (b mod n)] mod n = (a - b) mod n
3. [(a mod n) * (b mod n)] mod n = (a * b) mod n
1. Define (a mod n) = ra and (b mod n) = rb.
● Then we can write a = ra + jn for some integer j and b = rb + kn for some integer k. Then
(a + b) mod n = (ra + jn + rb + kn) mod n = (ra + rb + (k + j)n) mod n = (ra + rb) mod n
● = [(a mod n) + (b mod n)] mod n
● The remaining properties are proven as easily.
15. Examples of the three properties:
● 11 mod 8 = 3; 15 mod 8 = 7
[(11 mod 8) + (15 mod 8)] mod 8 = 10 mod 8 = 2
(11 + 15) mod 8 = 26 mod 8 = 2
● [(11 mod 8) - (15 mod 8)] mod 8 = -4 mod 8 = 4
(11 - 15) mod 8 = -4 mod 8 = 4
● [(11 mod 8) * (15 mod 8)] mod 8 = 21 mod 8 = 5
(11 * 15) mod 8 = 165 mod 8 = 5
● Exponentiation is performed by repeated multiplication, as in ordinary arithmetic.
● To find 117 mod 13,
○ 112 = 121 ≡ 4 (mod 13)
○ 114 = (112)2 ≡ 42 ≡ 3 (mod 13)
○ 117 ≡ 11 * 4 * 3 ≡ 132 ≡ 2 (mod 13)
16. Modular addition and multiplication modulo 8
● Looking at addition, results are straightforward & there is a
regular pattern to the matrix. Both matrices are symmetric about
the main diagonal in conformance to the commutative property
of addition and multiplication. As in ordinary addition, there is an
additive inverse, or negative, to each integer in modular
arithmetic. In this case, the negative of an integer x is the integer
y such that (x + y) mod 8 = 0. To find the additive inverse of an
integer in the left-hand column, scan across the corresponding
row of the matrix to find the value 0; the integer at the top of that
column is the additive inverse; thus, (2 + 6) mod 8 = 0.
● Similarly, there is a multiplicative inverse, or reciprocal, to each
integer. In modular arithmetic mod 8, the multiplicative inverse of
x is the integer y such that (x * y) mod 8 = 1 mod 8. Now, to find
the multiplicative inverse of an integer from the multiplication
table, scan across the matrix in the row for that integer to find the
value 1; the integer at the top of that column is the multiplicative
inverse; thus, (3 * 3) mod 8 = 1. Note that not all integers mod 8
have a multiplicative inverse;
17. Properties of Modular Arithmetic
● Define the set Zn as the set of nonnegative integers less than n: Zn = {0, 1, c, (n - 1)}
● This is referred to as the set of residues, or residue classes (mod n).
● To be more precise, each integer in Zn represents a residue class. We can label the residue
classes (mod n) as [0], [1], [2],....., [n - 1], where [r] = {a: a is an integer, a ≡ r (mod n)}
● The residue classes (mod 4) are
[0] = {……, -16, -12, -8, -4, 0, 4, 8, 12, 16, ……}
[1] = {……, -15, -11, -7, -3, 1, 5, 9, 13, 17, ……}
[2] = {……, -14, -10, -6, -2, 2, 6, 10, 14, 18, ……}
[3] = {……, -13, -9, -5, -1, 3, 7, 11, 15, 19, ……}
● Of all the integers in a residue class, the smallest nonnegative integer is the one used to
represent the residue class. Finding the smallest nonnegative integer to which k is congruent
modulo n is called reducing k modulo n.
● If modular arithmetic is performed within Zn, the properties shown in Table 4.3 hold for integers
in Zn.
18. There is one peculiarity of modular arithmetic that sets it apart from ordinary arithmetic
First, (as in ordinary arithmetic) we can write, if (a + b) K (a + c) (mod n) then b K c (mod n) (4.4)
(5 + 23) ≡ (5 + 7) (mod 8); ≡ 7(mod 8)
Equation (4.4) is consistent with the existence of an additive inverse. Adding the additive inverse
of a to both sides of Equation (4.4),
((-a) + a + b) ≡ ((-a) + a + c) (mod n)
b ≡ c (mod n)
However, the following statement is true only with the attached condition:
if (a * b) ≡ (a * c)(mod n) then b ≡ c (mod n) if a is relatively prime to n (4.5)
Two integers are relatively prime if their only common positive integer factor is 1. Similar to the
case of Equation (4.4), it can be said that Equation (4.5) is consistent with the existence of a
multiplicative inverse.
Applying the multiplicative inverse of a to both sides of Equation (4.5),
((a-1
)ab) ≡((a-1)ac) (mod n)
b ≡ c (mod n)
21. Euclidean Algorithm
an efficient way to find the GCD(a,b)
uses theorem that:
GCD(a,b) = GCD(b, a mod b)
Euclidean Algorithm to compute GCD(a,b) is:
Euclid(a,b)
if (b=0) then return a;
else return Euclid(b, a mod b);
22. Extended Euclidean Algorithm
calculates not only GCD but x & y:
ax + by = d = gcd(a, b)
useful for later crypto computations
follow sequence of divisions for GCD but
assume at each step i, can find x &y:
r = ax + by
at end find GCD value and also x & y
if GCD(a,b)=1 these values are inverses
23. Finding Inverses
EXTENDED EUCLID(m, b)
1. (A1, A2, A3)=(1, 0, m);
(B1, B2, B3)=(0, 1, b)
2. if B3 = 0
return A3 = gcd(m, b); no inverse
3. if B3 = 1
return B3 = gcd(m, b); B2 = b–1
mod m
4. Q = A3 div B3
5. (T1, T2, T3)=(A1 – Q B1, A2 – Q B2, A3 – Q
B3)
6. (A1, A2, A3)=(B1, B2, B3)
7. (B1, B2, B3)=(T1, T2, T3)
8. goto 2
24. find the multiplicative inverse of 3 mod 5
using Extended Euclid’s Algorithm
Q a b r T1 T2 T
1 5 3 2 0 1 -1
1 3 2 1 1 -1 2
2 2 1 0 -1 2 -5
1 0 2 -5
T=T1-T2*Q
25. Prime Numbers
prime numbers only have divisors of 1 and self
they cannot be written as a product of other numbers
note: 1 is prime, but is generally not of interest
eg. 2,3,5,7 are prime, 4,6,8,9,10 are not
prime numbers are central to number theory
list of prime number less than 200 is:
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101
103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191
193 197 199
26. Prime Factorization
to factor a number n is to write it as a product
of other numbers: n=a x b x c
note that factoring a number is relatively hard
compared to multiplying the factors together to
generate the number
Fundamental theorem of arithmetic
the prime factorization of a number n is when
its written as a product of primes
eg. 91=7x13 ; 3600=24
x32
x52
27. Relatively Prime Numbers &
GCD
two numbers a, b are relatively prime if have no
common divisors apart from 1
eg. 8 & 15 are relatively prime since factors of 8 are 1,2,4,8
and of 15 are 1,3,5,15 and 1 is the only common factor
conversely can determine the greatest common divisor
by comparing their prime factorizations and using least
powers
eg. 300=21
x31
x52
18=21
x32
hence
GCD(18,300)=21
x31
x50
=6
28. Fermat's Theorem
ap-1
= 1 (mod p)
where p is prime and gcd(a,p)=1
also known as Fermat’s Little Theorem
also have: ap
= a (mod p)
useful in public key and primality testing
29. Euler Totient Function ø(n)
when doing arithmetic modulo n
complete set of residues is: 0..n-1
reduced set of residues is those numbers
(residues) which are relatively prime to n
eg for n=10,
complete set of residues is {0,1,2,3,4,5,6,7,8,9}
reduced set of residues is {1,3,7,9}
number of elements in reduced set of residues
is called the Euler Totient Function ø(n)
30. Euler Totient Function ø(n)
to compute ø(n) need to count number of
residues to be excluded
in general need prime factorization, but
for p (p prime) ø(p)=p-1
for p.q (p,q prime) ø(p.q)=(p-1)x(q-1)
eg.
ø(37) = 36
ø(21) = (3–1)x(7–1) = 2x6 = 12
31. Euler's Theorem
a generalisation of Fermat's Theorem
aø(n)
= 1 (mod n)
for any a,n where gcd(a,n)=1
eg.
a=3;n=10; ø(10)=4;
hence 34
= 81 = 1 mod 10
a=2;n=11; ø(11)=10;
hence 210
= 1024 = 1 mod 11
also have: aø(n)+1
= a (mod n)
32. Primality Testing
often need to find large prime numbers
traditionally sieve using trial division
ie. divide by all numbers (primes) in turn less than
the square root of the number
only works for small numbers
alternatively can use statistical primality tests
based on properties of primes
for which all primes numbers satisfy property
but some composite numbers, called pseudo-
primes, also satisfy the property
can use a slower deterministic primality test
33. Chinese Remainder Theorem
used to speed up modulo computations
if working modulo a product of numbers
e.g., mod M, where M = m1m2..mk
Chinese Remainder theorem lets us work
in each modulus mi separately
since computational cost is proportional
to size, this is faster than working in the
full modulus M
34. Chinese Remainder Theorem
can implement CRT in several ways
to compute A(mod M)
first compute all ai = A mod mi separately
determine constants ci below, where Mi = M/mi
then combine results to get answer using:
35. Primitive Roots
from Euler’s theorem have aø(n)
mod n=1
consider am
=1 (mod n), GCD(a,n)=1
must exist for m = ø(n) but may be smaller
once powers reach m, cycle will repeat
if smallest is m = ø(n) then a is called a
primitive root
if p is prime, then successive powers of a
"generate" the group mod p
these are useful but relatively hard to find
37. 3-1 INTRODUCTION
Figure 3.1 shows the general idea behind a symmetric-key cipher. The original message from Alice to Bob is called
plaintext; the message that is sent through the channel is called the ciphertext. To create the ciphertext from the
plaintext, Alice uses an encryption algorithm and a shared secret key. To create the plaintext from ciphertext, Bob
uses a decryption algorithm and the same secret key.
3.1.1 Kerckhoff’s Principle
3.1.2 Cryptanalysis
3.1.3 Categories of Traditional Ciphers
Topics discussed in this section:
41. 3.1.1 Kerckhoff’s Principle
Based on Kerckhoff’s principle, one should always assume that the adversary, Eve, knows the
encryption/decryption algorithm. The resistance of the cipher to attack must be based only on the secrecy of the
key.
42. Cryptanalysis
As cryptography is the science and art of creating secret codes, cryptanalysis is the science and art
of breaking those codes.
Figure 3.3 Cryptanalysis attacks
47. 3-2 SUBSTITUTION CIPHERS
A substitution cipher replaces one symbol with another. Substitution ciphers can be categorized as either
monoalphabetic ciphers or polyalphabetic ciphers.
3.2.1 Monoalphabetic Ciphres
3.2.2 Polyalphabetic Ciphers
Topics discussed in this section:
A substitution cipher replaces one symbol with another.
Note
48. Monoalphabetic Ciphers
In monoalphabetic substitution, the relationship between a symbol in
the plaintext to a symbol in the ciphertext is always one-to-one.
Note
49. The following shows a plaintext and its corresponding ciphertext. The cipher is probably monoalphabetic because
both l’s (els) are encrypted as O’s.
Example 3.1
The following shows a plaintext and its corresponding ciphertext. The cipher is not monoalphabetic because each
l (el) is encrypted by a different character.
Example 3.2
50. The simplest monoalphabetic cipher is the additive cipher. This cipher is sometimes called a shift cipher and
sometimes a Caesar cipher, but the term additive cipher better reveals its mathematical nature.
Additive Cipher
Figure 3.8 Plaintext and ciphertext in Z26
51. Figure 3.9 Additive cipher
When the cipher is additive, the plaintext, ciphertext, and key are
integers in Z26.
Note
52. Use the additive cipher with key = 15 to encrypt the message “hello”.
We apply the encryption algorithm to the plaintext, character by character:
Solution
53. Use the additive cipher with key = 15 to decrypt the message “WTAAD”.
Example 3.4
We apply the decryption algorithm to the plaintext character by character:
Solution
54. Historically, additive ciphers are called shift ciphers. Julius Caesar used an additive cipher to communicate with
his officers. For this reason, additive ciphers are sometimes referred to as the Caesar cipher. Caesar used a key of
3 for his communications.
Shift Cipher and Caesar Cipher
Additive ciphers are sometimes referred to as shift ciphers or Caesar
cipher.
Note
55. Eve has intercepted the ciphertext “UVACLYFZLJBYL”. Show how she can use a brute-force attack to break the
cipher.
Example 3.5
Eve tries keys from 1 to 7. With a key of 7, the plaintext is “not very secure”, which makes sense.
Solution
56. Table 3.1 Frequency of characters in English
Table 3.2 Frequency of diagrams and trigrams
57. Eve has intercepted the following ciphertext. Using a statistical attack, find the plaintext.
Example 3.6
When Eve tabulates the frequency of letters in this ciphertext, she gets: I =14, V =13, S =12, and so on. The most
common character is I with 14 occurrences. This means key = 4.
Solution
58. Multiplicative Ciphers
In a multiplicative cipher, the plaintext and ciphertext are integers in
Z26; the key is an integer in Z26*.
Note
Figure 3.10 Multiplicative cipher
59. What is the key domain for any multiplicative cipher?
Example 3.7
The key needs to be in Z26*. This set has only 12 members: 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25.
Solution
We use a multiplicative cipher to encrypt the message “hello” with a key of 7. The ciphertext is “XCZZU”.
Example 3.8
61. The affine cipher uses a pair of keys in which the first key is from Z26* and the second is from Z26. The size of
the key domain is
26 × 12 = 312.
Example 3.09
Use an affine cipher to encrypt the message “hello” with the key pair (7, 2).
Example 3.10
62. Use the affine cipher to decrypt the message “ZEBBW” with the key pair (7, 2) in modulus 26.
Example 3.11
Solution
The additive cipher is a special case of an affine cipher in which
k1 = 1. The multiplicative cipher is a special case of affine cipher in which k2 = 0.
Example 3.12
63. Because additive, multiplicative, and affine ciphers have small key domains, they are very vulnerable to brute-
force attack.
Monoalphabetic Substitution Cipher
A better solution is to create a mapping between each plaintext character and the corresponding ciphertext
character. Alice and Bob can agree on a table showing the mapping for each character.
Figure 3.12 An example key for monoalphabetic substitution cipher
64. We can use the key in Figure 3.12 to encrypt the message
Example 3.13
The ciphertext is
65. 3.2.2 Polyalphabetic Ciphers
In polyalphabetic substitution, each occurrence of a character may have a different substitute.
The relationship between a character in the plaintext to a character in the ciphertext is one-to-
many.
Autokey Cipher
66. Assume that Alice and Bob agreed to use an autokey cipher with initial key value k1 = 12. Now Alice wants to
send Bob the message “Attack is today”. Enciphering is done character by character.
Example 3.14
67. Playfair Cipher
Figure 3.13 An example of a secret key in the Playfair cipher
Let us encrypt the plaintext “hello” using the key in Figure 3.13.
Example 3.15
68. Vigenere Cipher
We can encrypt the message “She is listening” using the 6-character keyword “PASCAL”.
Example 3.16
69. Let us see how we can encrypt the message “She is listening” using the 6-character keyword “PASCAL”. The
initial key stream is (15, 0, 18, 2, 0, 11). The key stream is the repetition of this initial key stream (as many times
as needed).
Example 3.16
70. Vigenere cipher can be seen as combinations of m additive ciphers.
Example 3.17
Figure 3.14 A Vigenere cipher as a combination of m additive ciphers
71. Using Example 3.18, we can say that the additive cipher is a special case of Vigenere cipher in which m = 1.
Example 3.18
Table 3.3
A Vigenere Tableau
72. Vigenere Cipher (Crypanalysis)
Let us assume we have intercepted the following ciphertext:
Example 3.19
The Kasiski test for repetition of three-character segments yields the results shown in Table 3.4.
73. Let us assume we have intercepted the following ciphertext:
Example 3.19
The Kasiski test for repetition of three-character segments yields the results shown in Table 3.4.
74. The greatest common divisor of differences is 4, which means that the key length is multiple of 4. First try m = 4.
Example 3.19 (Continued)
In this case, the plaintext makes sense.
75. Hill Cipher
Figure 3.15 Key in the Hill cipher
The key matrix in the Hill cipher needs to have a multiplicative
inverse.
Note
76. For example, the plaintext “code is ready” can make a 3 × 4 matrix when adding extra bogus character “z” to the
last block and removing the spaces. The ciphertext is “OHKNIHGKLISS”.
Example 3.20
Figure 3.16 Example 3.20
77. Assume that Eve knows that m = 3. She has intercepted three plaintext/ciphertext pair blocks (not necessarily
from the same message) as shown in Figure 3.17.
Example 3.21
Figure 3.17 Example 3.21
78. She makes matrices P and C from these pairs. Because P is invertible, she inverts the P matrix and multiplies it by
C to get the K matrix as shown in Figure 3.18.
Example 3.21
Figure 3.18 Example 3.21
Now she has the key and can break any ciphertext encrypted with that key.
(Continued)
79. One of the goals of cryptography is perfect secrecy. A study by Shannon has shown that perfect
secrecy can be achieved if each plaintext symbol is encrypted with a key randomly chosen from a
key domain. This idea is used in a cipher called one-time pad, invented by Vernam.
One-Time Pad
82. 3-3 TRANSPOSITION CIPHERS
A transposition cipher does not substitute one symbol for another, instead it changes the location of the
symbols.
3.3.1 Keyless Transposition Ciphers
3.3.2 Keyed Transposition Ciphers
3.3.3 Combining Two Approaches
Topics discussed in this section:
A transposition cipher reorders symbols.
Note
83. Keyless Transposition Ciphers
Simple transposition ciphers, which were used in the past, are keyless.
A good example of a keyless cipher using the first method is the rail fence cipher. The ciphertext is created
reading the pattern row by row. For example, to send the message “Meet me at the park” to Bob, Alice writes
Example 3.22
She then creates the ciphertext “MEMATEAKETETHPR”.
84. Alice and Bob can agree on the number of columns and use the second method. Alice writes the same plaintext,
row by row, in a table of four columns.
Example 3.23
She then creates the ciphertext “MMTAEEHREAEKTTP”.
85. The cipher in Example 3.23 is actually a transposition cipher. The following shows the permutation of each
character in the plaintext into the ciphertext based on the positions.
Example 3.24
The second character in the plaintext has moved to the fifth position in the ciphertext; the third character has
moved to the ninth position; and so on. Although the characters are permuted,
there is a pattern in the permutation: (01, 05, 09, 13), (02, 06, 10, 13), (03, 07, 11, 15), and (08, 12). In each section,
the difference between the two adjacent numbers is 4.
86. 3.3.2 Keyed Transposition Ciphers
The keyless ciphers permute the characters by using writing plaintext in one way and reading it in
another way The permutation is done on the whole plaintext to create the whole ciphertext.
Another method is to divide the plaintext into groups of predetermined size, called blocks, and
then use a key to permute the characters in each block separately.
87. Alice needs to send the message “Enemy attacks tonight” to Bob..
Example 3.25
The key used for encryption and decryption is a permutation key, which shows how the character are permuted.
The permutation yields
89. Figure 3.22 Encryption/decryption keys in transpositional ciphers
Keys
In Example 3.27, a single key was used in two directions for the column exchange: downward for encryption,
upward for decryption. It is customary to create two keys.
91. Using Matrices
We can use matrices to show the encryption/decryption process for a transposition cipher.
Figure 3.24 Representation of the key as a matrix in the transposition cipher
Example 3.27
92. Figure 3.24 Representation of the key as a matrix in the transposition cipher
Figure 3.24 shows the encryption process. Multiplying the 4 × 5 plaintext matrix by the 5 × 5 encryption key gives
the 4 × 5 ciphertext matrix.
Example 3.27
94. STREAM AND BLOCK CIPHERS
The literature divides the symmetric ciphers into two broad categories: stream ciphers and block ciphers.
Although the definitions are normally applied to modern ciphers, this categorization also applies to
traditional ciphers.
3.4.1 Stream Ciphers
3.4.2 Block Ciphers
3.4.3 Combination
Topics discussed in this section:
95. Stream Ciphers
Call the plaintext stream P, the ciphertext stream C, and the key stream K.
Figure 3.26 Stream cipher
96. 3.4.1 Continued
Additive ciphers can be categorized as stream ciphers in which the key stream is the repeated value of the key. In
other words, the key stream is considered as a predetermined stream of keys or
K = (k, k, …, k). In this cipher, however, each character in the ciphertext depends only on the corresponding
character in the plaintext, because the key stream is generated independently.
Example 3.30
The monoalphabetic substitution ciphers discussed in this chapter are also stream ciphers. However, each value of
the key stream in this case is the mapping of the current plaintext character to the corresponding ciphertext
character in the mapping table.
Example 3.31
97. Vigenere ciphers are also stream ciphers according to the definition. In this case, the key stream is a repetition of
m values, where m is the size of the keyword. In other words,
Example 3.32
We can establish a criterion to divide stream ciphers based on their key streams. We can say that a stream cipher
is a monoalphabetic cipher if the value of ki does not depend on the position of the plaintext character in the
plaintext stream; otherwise, the cipher is polyalphabetic.
Example 3.33
98. Combination
In practice, blocks of plaintext are encrypted individually, but they use a stream of keys to encrypt
the whole message block by block. In other words, the cipher is a block cipher when looking at the
individual blocks, but it is a stream cipher when looking at the whole message considering each
block as a single unit.
#20:If we perform modular arithmetic within Zn, the properties shown in Table 4.3 hold for integers in Zn We show in the next section that this implies that Zn is a commutative ring with a multiplicative identity element. Note that unlike ordinary arithmetic, the following statement is true only with the attached condition:
if (a x b) = (a x c) (mod n) then b = c (mod n) if a is relatively prime to n
In general, an integer has a multiplicative inverse in Zn if that integer is relatively prime to n. Table 4.2 cin the text shows that the integers 1, 3, 5, and 7 have a multiplicative inverse in Z 8, but 2, 4, and 6 do not.
#21:We now describe an algorithm credited to Euclid for easily finding the greatest common divisor of two integers. This algorithm has significance subsequently in this chapter. The Euclidean algorithm is an efficient way to find the GCD(a,b), and is derived from the observation that if a & b have a common factor d (ie. a=m.d & b=n.d) then d is also a factor in any difference between them, vis: a-p.b = (m.d)-p.(n.d) = d.(m-p.n). See text for more detailed proof. Euclid's Algorithm keeps computing successive differences until it vanishes, at which point the greatest common divisor has been reached. Some pseudo-code from the text for this algorithm is shown.
#22:We now proceed to look at an extension to the Euclidean algorithm that will be important for later computations in the area of finite fields and in encryption algorithms such as RSA. For given integers a and b, the extended Euclidean algorithm not only calculate the greatest common divisor d but also two additional integers x and y that satisfy the following equation: ax + by = d = gcd(a, b). It should be clear that x and y will have opposite signs.
Can extend the Euclidean algorithm to determine x, y, d, given a and b. We again go through the sequence of divisions indicated in Equation Set (4.3) and we assume that at each step i, we can find integers x and y that satisfy r = ax + by. In each row, we calculate a new remainder r , based on the remainders of the previous two rows. We know from the original Euclidean algorithm that the process ends with a remainder of zero and that the greatest common divisor of a and b is d = gcd(a, b) = r n. But we also have determined that d = r n = axn + byn.
#23:An important problem is to find multiplicative inverses in such finite fields. Can show that such inverses always exist, & can extend the Euclidean algorithm to find them as shown. See text for discussion as to why this works.
#25:A central concern of number theory is the study of prime numbers. Indeed, whole books have been written on the subject. An integer p>1 is a prime number if and only if its only divisors are 1 and itself. Prime numbers play a critical role in number theory and in the techniques discussed in this chapter. Stallings Table 8.1 (excerpt above) shows the primes less than 2000. Note the way the primes are distributed. In particular note the number of primes in each range of 100 numbers.
#26:The idea of "factoring" a number is important - finding numbers which divide into it. Taking this as far as can go, by factorising all the factors, we can eventually write the number as a product of (powers of) primes - its prime factorisation. Note also that factoring a number is relatively hard compared to multiplying the factors together to generate the number.
#27:Have the concept of “relatively prime” if two number share no common factors other than 1.
Another common problem is to determine the "greatest common divisor” GCD(a,b) which is the largest number that divides into both a & b.
#28:Two theorems that play important roles in public-key cryptography are Fermat’s theorem and Euler’s theorem.
Fermat’s theorem (also known as Fermat’s Little Theorem) as listed above, states an important property of prime numbers. See Stallings section 8.2 for its proof.
#29:Now introduce the Euler’s totient function ø(n), defined as the number of positive integers less than n & relatively prime to n. Note the term “residue” refers to numbers less than some modulus, and the “reduced set of residues” to those numbers (residues) which are relatively prime to the modulus (n). Note by convention that ø(1) = 1. Stallings Table 8.2 lists the first 30 values of ø(n). The value ø(1) is without meaning but is defined to have the value 1.
#30:To compute ø(n) need to count the number of residues to be excluded. In general you need use a complex formula on the prime factorization of n, but have a couple of special cases as shown.
#31:Euler's Theorem is a generalization of Fermat's Theorem for any number n. See Stallings section 8.2 for its proof. As is the case for Fermat's theorem, an alternative form of the theorem is also useful. Again, similar to the case with Fermat's theorem, the first form of Euler's theorem requires that a be relatively prime to n, but this form does not.
#32:For many cryptographic functions it is necessary to select one or more very large prime numbers at random. Thus we are faced with the task of determining whether a given large number is prime. There is no simple yet efficient means of accomplishing this task.
Traditionally sieve for primes using trial division of all possible prime factors of some number, but this only works for small numbers.
Alternatively can use repeated statistical primality tests based on properties of primes, and then for certainty, use a slower deterministic primality test, such as the AKS test.
#33:One of the most useful results of number theory is the Chinese remainder theorem (CRT), so called because it is believed to have been discovered by the Chinese mathematician Sun-Tse in around 100 AD. In essence, the CRT says it is possible to reconstruct integers in a certain range from their residues modulo a set of pairwise relatively prime moduli. Thus it is very useful in speeding up some operations in the RSA public-key scheme, since it allows you to do perform calculations modulo factors of your modulus, and then combine the answers to get the actual result. Since the computational cost is proportional to size, this is faster than working in the full modulus sized modulus.
#34:One of the useful features of the Chinese remainder theorem is that it provides a way to manipulate (potentially very large) numbers mod M, in terms of tuples of smaller numbers. This can be useful when M is 150 digits or more. However note that it is necessary to know beforehand the factorization of M. See worked examples in Stallings section 8.4.
#35:Consider the powers of an integer modulo n. By Eulers theorem, for every relatively prime a, there is at least one power equal to 1 (being ø(n)), but there may be a smaller value. If the smallest value is m = ø(n) then a is called a primitive root. If n is prime, then the powers of a primitive root “generate” all residues mod n. Such generators are very useful, and are used in a number of public-key algorithms, but they are relatively hard to find.
#36:Stallings Table 8.3 shows all the powers of a, modulo 19 for all positive a < 19. The length of the sequence for each base value is indicated by shading. Note the following:
All sequences end in 1.
The length of a sequence divides %(19) = 18. That is, an integral number of sequences occur in each row of the table.
Some of the sequences are of length 18. In this case, it is said that the base integer a generates (via powers) the set of nonzero integers modulo 19. Each such integer is called a primitive root of the modulus 19.