ÖVNING 6. KRYPTOGRAFINS MATEMATISKA GRUNDER
Del A. Estimate the computational complexity of the following algorithms
a) Search in an unsorted array
The complexity of a sorting algorithm, which repeatedly copies into a new sorted array
the smallest still not copied element from an unsorted array of n elements, is O(n), since
on average n/2 element must be checked to find the next element to copy and this check
must be repeated n-1 times. Insertion sort's advantage is that it only scans as many
elements as needed to determine the correct location of the element.
b) Binary search in a sorted array
Binary insertion sort employs a binary search to determine the correct location to insert
new elements. It’s called subpolynomial COMPLEXITY O(f(n)), where 1<f(n)<n when
n, for example binary search in a sorted array of size n has logarithmic complexity
O(log2n). If the cost of comparisons exceeds the cost of swaps, as is the case for example
with string keys stored by reference or with human interaction, then maby binary search
is a good way.
c) Bubble sort of an unsorted array
Bubble sort works by repeatedly stepping through the list to be sorted, comparing each
pair of adjacent items and swapping them if they are in the wrong order.
Bubble sort is more efficient in practice than most other simple quadratic (i.e. O(n2))
algorithms. The average running time is n2/4, and the running time is linear in the best
case.
Del B. Show all calculation steps in an optimal calculation of
a) 6 mod 26 (start with 62 mod 26, 64 mod 26 and 68 mod 26)
6²mod26=10
6⁴ mod26=(10*10)mod26=22
6⁸ mod26=(22*22)mod26=16 (22*22/26-----0.61*26)
6¹⁵ mod26=6*6²*6⁴ *6⁸ mod26 = 6*10*22*16mod26=8
15
b) 5047 mod 47 (use Fermat's Theorem)
50⁴ ⁶ mod47=1
50⁴ ⁷ mod47 = 50⁴ ⁶ mod47*50mod47=3
Del C.
a) How many relative primes to 21 and smaller than 21 can be found? (use Euler's
Totient Function)
7*3 (relativ primtal * relativa primtal) = 21
6*2 (så här får man mängden relativa primtal (p-1) * (q-1)) =12
b) Which are these relative primes to 21?
21{1,2,4,5,8,10,11,13,16,17,19,20}
Del D.
a) Why is 288 mod 15 = 1? (apply Euler's Theorem)
3*5=15
2*4=8 (Eulers function av 15)
28 och 15 är relativa primtal för att det går att tillämpa Eulers Totient Function. Då det
här stämmer blir svaret alltid 1.
b) Show by calculation that 288 mod 15 is really 1
28mod15=13
13⁸ mod15=
13²mod15=4
13⁴ mod15=(4*4)mod15=1
13⁸ mod15=(1*1)mod15=1
Del E. Which discrete inverses exist/do not exist and why?
a) 17-1 mod 26
17 and 26 do not have common factors (so they are relative primes).
17⁻ ¹mod26 exists
b) 13-1 mod 26
13⁻ ¹mod26 do have an common factor that is 13, they are not relative primes.
13⁻ ¹mod26 does not exist.
Del F. Show that (n-1)-1 mod n = n-1 for any integer n>1
n and n-1 are always relative primes
(n-1)*(n-1)modn=
(n²-2n+1)mod n = n²mod n – 2n*mod n + 1*mod n = 0 - 0 + 1 = 1
The product of an integer and an inverse integer should be 1.
Del G. Modular inverse and division
a) Determine a-1 mod 200 for 3 values a, which are relative primes to 200. Use the
Extended Euclidean Algorithm. How many iterations are required? The calculation of 9-1
mod 26 in the example on the Course Portal requires 2 iteration steps until the answer 3
is obtained. Notice that the modulo should be applied to a possible negative answer. For
example, -17 mod 200 = (-17 + 200) = 183
7 and 143 are each others inverses with the help of three iterations
3 and 67 are each others inverses with the help of two iterations
133 and 197 are each others inverses with the help of three iterations
b) Calculate (9/13) mod 53
(9*(13⁻ ¹mod53))mod53
p=53=1*53+0*13
q=13=0*53+1*13
gcd(p,q)=gcd(q,r)
d=pdivq=53div13=4, r=p mod q 53mod13=1
9*1mod53 = 9
r=1=n1*53+n2*13 => n2=13^-1mod53 =>
r=p-d*q=53-(53div13)*13=1
since r=1 => n2=13^-1mod53 = ramod53=(1*13)mod53=3 (a = 13)
(3*9)mod53)=1 => OK
n1 = 1
n2 = -53div13 = -4
gcd(n,a) = n1*n + n2*a = 1
1*53+(-4)*13= 1
( n2*a mod n = 1 => -4*13mod53 = -52mod53=(53-52)mod53=1
((-4)*9))mod53=(-36)mod53 =(53-36)mod53=>17mod53=17
Del H. Discrete logarithm. Find the discrete logarithm of 10 in the basis 2 for modulo 11
(find x when 2x mod 11 = 10)
2¹ mod11 = 2
2² mod11 = 4
2³ mod11 = 8
2⁴ mod11 = 5
2⁵ mod11 = 10
Result: x is 5.
Del I. Integer vectorization.
a) Find x mod 165 when x mod 3 = 2, x mod 5 = 4, and x mod 11 = 7 (use Chinese
Remainder Theorem)
(m1,m2,m3) = (3, 5, 11), M1=165/3=55, M2=165/5=33, M3=165/11=15
c1=55*(55⁻ ¹mod3)=55*1 since (55*1)mod3=1
c2=33*(33⁻ ¹mod5)=33*2=66 since (33*2)mod5=1
c3=15*(15⁻ ¹mod11)=15*3=45 since (15*3)mod11=1
xmod165=(2*55+4*66+7*45)mod165=689mod165=29
Control: 29mod3=2, 29mod5=4, 29mod11=7
x = 29
b) Show that (x*x) mod 165 can also be obtained by modular vector multiplication.
(29*29)mod165 = 841mod165 = 16
16mod3 = 1, 16mod5 = 1, 16mod11 = 5
vektor representation of (29*29) is calculated to be (1,1,5)
vektor representation of 29 is (2,4,7)
modular vektor multiplication
((2*2)mod3, (4*4)mod5, (7*7)mod11) = (1,1,5))
Same vector from both approaches => OK
SAMULI KETOLA, MT4 12.11.2009