Square and Multiply Introducing RSA Prof Hans Georg Schaathun Høgskolen i Ålesund Autumn 2013 – Crupto PK 4/4 Recorded: October 14, 2013 Prof Hans Georg Schaathun Square and Multiply Crypto PK 4/4 1/8 The RSA Cipher ee,n (x) = x e mod n Problem What is the algorithmic complexity of the encryption function? Prof Hans Georg Schaathun Square and Multiply Crypto PK 4/4 2/8 The Naïve Approach Two problems 1 Calculate x e = x · x · . . . · x 2 Reduce x e mod n Prof Hans Georg Schaathun Square and Multiply Crypto PK 4/4 3/8 Square and Multiply (x a )b = x ab , x a x b = x a+b . Prof Hans Georg Schaathun Square and Multiply Crypto PK 4/4 4/8 Reduction after every step xy mod n = (x mod n)(y mod n) mod n (1) To calculate x e mod n 1 Calculate y = x be/2c mod n 2 Square y and reduce mod n 3 If e is odd, then multiply y by x and reduce mod n 4 Return Prof Hans Georg Schaathun Square and Multiply Crypto PK 4/4 5/8 1 2 3 4 5 6 7 Recursive Pseudo-code Input positive integers x, e, n Return x e mod n A l g o r i t h m S q u a r e N m u l t i p l y (x, e, n) i f e = 1 , return x y := S q u a r e N m u l t i p l y (x, be/nc , n) y := y 2 mod n i f e mod 2 = 1 , y := y · x mod n return y Prof Hans Georg Schaathun Square and Multiply Crypto PK 4/4 6/8 Example 311 Prof Hans Georg Schaathun mod 13 Square and Multiply Crypto PK 4/4 7/8 Closure Exercise Write pseudo code for an iterative algorithm to calculate x a mod n using square and multiply. Prof Hans Georg Schaathun Square and Multiply Crypto PK 4/4 8/8
© Copyright 2026 Paperzz