๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐“ก๐“ธ๐“ธ๐“ถ5: ๐’ฆ๐‘œ๐“‡๐‘’๐’ถ ๐’ฐ๐“ƒ๐’พ๐“‹/Discrete mathematics

[์ด์‚ฐ์ˆ˜ํ•™] Chapter 5. Introduction to Number Theory

1. Divisors

  1)

  - d๊ฐ€ n์„ ๋‚˜๋ˆ„์–ด ๋–จ์–ด์ง€๊ฒŒ ํ•  ๋•Œ, ์ฆ‰ n=dq๋ฅผ ๋งŒ์กฑํ•˜๋Š” integer q๊ฐ€ ์กด์žฌํ•  ๋•Œ, d divides n์ด๋ผ๊ณ  ๋งํ•œ๋‹ค. 

  - ์ด ๋•Œ q๋ฅผ quotient, d๋ฅผ divisor ๋˜๋Š” n์˜ factor๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค.

  - d divides n์ผ ๋•Œ d|n์œผ๋กœ ์“ด๋‹ค.

 

  Theorem 5.1.3 

  m, n, d๋ฅผ ์ •์ˆ˜๋ผ๊ณ  ํ•˜์ž. ๋งŒ์•ฝ d|m์ด๊ณ  d|n์ด๋ฉด d|(m±n)์ด๋‹ค. ๋˜ํ•œ d|m์ด๋ฉด d|mn์ด๋‹ค. 

 

  proof : d|m์ด๊ณ  d|n์ด๋ฉด m=dq, n=dq' ๋ผ๊ณ  ์“ธ ์ˆ˜ ์žˆ๋‹ค. m+n = dq + dq' = d(q+q')์ด๋‹ค. 

 ๋”ฐ๋ผ์„œ d|(m+n) ์ด๋‹ค. 

 

 

2) Prime and Composite

 - Prime : ์†Œ์ˆ˜

 - Composite : ํ•ฉ์„ฑ์ˆ˜

   composition์€ 2์™€ ๋ฃจํŠธn ์‚ฌ์ด์˜ divisor d๋ฅผ ๊ฐ–๋Š”๋‹ค.

 

* ์†Œ์ˆ˜์™€ ํ•ฉ์„ฑ์ˆ˜๋ฅผ ๊ตฌ๋ถ„ํ•˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜

//input : n
// output : d

is_prime(n) {
  for d=2 to sqrt(n) {
    if(n % d ==0)
    	return d
  }
  return 0
}

๋งŒ์•ฝ ์†Œ์ˆ˜์ด๋ฉด 0์„ returnํ•˜๊ณ  ํ•ฉ์„ฑ์ˆ˜์ด๋ฉด ๋‚˜๋ˆ„์–ด ๋–จ์–ด์ง€๋Š” divisior ๊ฐ’์„ ๋ฆฌํ„ดํ•œ๋‹ค.

 

Theorem 5.1.11 

 1๋ณด๋‹ค ํฐ ์ •์ˆ˜๋Š” ์†Œ์ˆ˜๋“ค์˜ ๊ณฑ์œผ๋กœ ๋‚˜ํƒ€๋‚ผ ์ˆ˜ ์žˆ๋‹ค. ๋˜ํ•œ ์ด ์†Œ์ˆ˜๋“ค์ด ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์“ฐ์—ฌ์ง„๋‹ค๋ฉด, ์ด factorization์€ uniqueํ•˜๋‹ค. 

 

Theorem 5.1.12

 ์†Œ์ˆ˜์˜ ๊ฐœ์ˆ˜๋Š” ๋ฌดํ•œํ•˜๋‹ค. 

 

 proof : p๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ๋ชจ๋“  ์†Œ์ˆ˜๋“ค์„ p1, p2....pn ์ด๋ผ๊ณ  ํ•˜์ž. 

m = p1p2...pn + 1 ์ด๋ผ๊ณ  ํ•˜๊ณ , m์„ q๋กœ ๋‚˜๋ˆ„์–ด 1์ด ๋‚จ๋Š” ์ˆ˜, m = piq + 1์ด๋ผ๊ณ  ํ•˜๋ฉด ๋ชจ๋“  i=1 to n๊นŒ์ง€ pi๋Š” m์„ ๋‚˜๋ˆ„์–ด ๋–จ์–ด์ง€๊ฒŒ ๋งŒ๋“ค์ง€ ๋ชปํ•œ๋‹ค. ๋”ฐ๋ผ์„œ p'๋Š” m์˜ prime factor์ด๊ณ , p'๋Š” ์–ด๋–ค pi์™€๋„ ๊ฐ™์ง€ ์•Š๋‹ค. ๋”ฐ๋ผ์„œ p1, p2 ,..., pn์€ p๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์†Œ์ˆ˜๋“ค์˜ ๋ฆฌ์ŠคํŠธ์ด๋ฏ€๋กœ p'>p์ธ pi๋ฅผ ๋ฌด์กฐ๊ฑด ๊ฐ–๋Š”๋‹ค.

 

 

3) ๊ณต์•ฝ์ˆ˜์™€ ๊ณต๋ฐฐ์ˆ˜ 

  - Greatest Common Divisor : ์ตœ๋Œ€๊ณต์•ฝ์ˆ˜( gcd(m,n) )

   

  - Least Common Multiple : ์ตœ์†Œ๊ณต๋ฐฐ์ˆ˜ ( lcm(m,n) )

Theorem 5.1.25 

  gcd(m,n) * lcm (m,n) = mn

 

 

2. Representation of Integers and Integer Algorithms

  1) Number system 

    -Binary digits: 0, 1 (bits)

    -hexadecimal, octal ...

 

    -์ปดํ“จํ„ฐ๋Š” ์ด์ง„์ˆ˜๋กœ ๋Œ์•„๊ฐ. positive integer n์„ ํ‘œํ˜„ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋ช‡ bits๊ฐ€ ํ•„์š”ํ•จ.

   integer n์„ ํ‘œํ˜„ํ•˜๋Š”๋ฐ์—๋Š” k+1 bits๊ฐ€ ํ•„์š”ํ•˜๋‹ค. ์ด ๋•Œ k๋Š” log n ๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™๊ณ , log n ์€ k+1๋ณด๋‹ค ์ž‘๋‹ค. ๋”ฐ๋ผ์„œ 

 " k+1 <= 1+log n < k+2 " ์ด๋ฏ€๋กœ k+1 = 1+log n ์ด๋‹ค. ์ฆ‰, integer n์—์„œ ํ•„์š”ํ•œ ๋น„ํŠธ์ˆ˜๋Š” 1+log n์ด๋‹ค. 

 

์œ„์— ๋‚˜์˜จ ์†Œ์ˆ˜ ํ•ฉ์„ฑ์ˆ˜ ๊ตฌ๋ถ„ํ•˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ the worst case time์€ Θ(√n) 

C(√n) ≥ Cc^s ์ด๋ฏ€๋กœ Exponential time in the input size s ๋ผ๋Š”๋ฐ ๋ญ”์†Œ๋ฆฌ์ž„

 

 

 2) Binary to Decimal

 

*์ด์ง„์ˆ˜ c ๊ฐ’์„ b์ง„์ˆ˜๋กœ ๋ฐ”๊พธ๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜

//input : c, n, b
// output : dec_val

base_b_to_dec(c, n, b){
  dec_val = 0;
  power = 1;
  for (i=0; i<n; i++){
  	dec_val = dec_val + ci * power
    power = power*b
  }
  return dec_val
}

 

  3) Decimal to Binary

//input : m,b
// output : c,n

dec_to_base_b(m,b,c,n){
  n= -1;
  while(m>0){
    n = n+1;
    c_n = m mode b;
    m= m/b;
  }
}

 

  4) Hexadecimal number System

 

 

  5) addition

   - Binary addition

 * Binary addition table

 

  * ์•Œ๊ณ ๋ฆฌ์ฆ˜

//input : a, b, n
//output : s
 
 binary_addition(a, b, n, s){
   carry = 0;
   for (i=0;i<n;i++){
     s_i = (a_i + b_i + carry) % 2;
     carry = (a_i + b_i + carry) / 2
   }
   s_n+1 = carry
 }

  - Hexadecimal addition

 

 

 6) Exponentiation

 

 a^n์„ ๊ณ„์‚ฐํ•˜์ž!

 โ‘  ๋‹จ์ˆœ ๋ฐ˜๋ณต ( repeated multiplication ) 

  a^n = a*a*...*

 

 โ‘ก ์ œ๊ณฑ์„ ์ด์šฉ

 

 a^29 = a^1 * a^4 * a^8 * a^16

 

  - a^2 = a*a

  - a^4 = a^2*a^2

  - a^8 = a^4 * a^4

  - a^16 = a^8 * a^8

 

 -> 7๋ฒˆ์˜ ๊ณ„์‚ฐ

 

 

 

 * squring์„ ํ™œ์šฉํ•œ a^n์„ ๊ตฌํ•˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜

//input : a, n
//output : a^n

exp_via_repeated_squaring(a,n){
  result = 1;
  x = a;
  while (n>0){
  	if(n % 2 ==1)
    	result = result *  x;
    x = x*x;
    n=n/2;
  }
  return result;
}

 

 Theorem 5.2.17

 ๋งŒ์•ฝ a, b, z๊ฐ€ ์–‘์˜ ์ •์ˆ˜๋ผ๋ฉด, ab mod z = [(a mod z) (b mod z)] mod z

 

//input : a, n, z
//output : a^n mod z

exp_mod_via_repeated_squaring(a,n,z){
  result = 1;
  x = a mod z;
  while (n>0){
  	if(n % 2 ==1)
    	result = (result *  x) mod z;
    x = (x*x) mod z;
    n=n/2;
  }
  return result;
}

 

 

3. The Euclidean algorithm

 - Euclid algorithm

 : gcd(a, b) = gcd(b, a mod b)

 

Theorem 5.3.2 

  a๊ฐ€ ์Œ์ˆ˜๊ฐ€ ์•„๋‹Œ ์ •์ˆ˜์ด๊ณ , b๊ฐ€ ์–‘์˜ ์ •์ˆ˜์ด๊ณ , r=a mod b์ด๋ผ๋ฉด, gcd(a, b) = gcd(b, r) ์ด๋‹ค. 

 

//input : a, b
//output : greatest common divisor of a and b

gcd(a, b){
  //make a largest
  if(a<b)
    swap(a,b);
  while ( b != 0 ){
    r=a mod b;
    a = b;
    b = r;
  }
  return a;
}

 * a special result 

 Theorem 5.3.7.

    a์™€ b๊ฐ€ ์Œ์ด ์•„๋‹Œ ์ •์ˆ˜์ผ ๋•Œ(๋‹จ, ๋‘˜ ๋‹ค 0์ด๋ฉด ์•ˆ๋จ), gcd(a, b) = sa + tb๋ฅผ ๋งŒ์กฑํ•˜๋Š” ์ •์ˆ˜ s์™€ t๊ฐ€ ์กด์žฌํ•œ๋‹ค.

 

ex) gcd(273, 110) = s*273 + t*110

 1) gcd(273, 110) ์ฐพ๊ธฐ (=1)

 2) ๋‹ค์‹œ ๋Œ์•„๊ฐ€์„œ ๋งˆ์ง€๋ง‰ ๋ฐฉ์ •์‹ ํ’€๊ธฐ 

 

 a= 273, b=110, 273 mod 110 = 53  -> 53 = 273 - 110*2

                      110 mod 53   = 4   -> 4 = 110 - 53*2

                       53 mod 4     = 1   -> 1 = 53 - 4*13

 

 ์ฆ‰, 1= 53 - (110 - 53*2)*13

       = 27*53 - 13*110

       = 27*(273 - 110*2) - 13*110

       = 27*273 - 67*110 

 

๋”ฐ๋ผ์„œ s=27, t=-67 ์ž„

 

 

 

 - Modulo convention 

      "0 (mod 5) vs "0 (mod 4)"

       N(mod 5)์—์„œ N์—๋Š” 0๋ถ€ํ„ฐ 4๊นŒ์ง€์˜ ์ˆซ์ž๊ฐ€ ๋“ค์–ด๊ฐˆ ์ˆ˜ ์žˆ์Œ

 

 - Inverse Modulo of b (mod m)  

     bb^(-1) = 1 (mod m)

     m์œผ๋กœ ๋‚˜๋ˆŒ ๋•Œ ๊ธฐ์กด ์ˆ˜์— ์–ด๋–ค ์ˆ˜๋ฅผ ๊ณฑํ•ด์„œ ๋‚˜๋จธ์ง€๊ฐ€ 1์ด ๋‚˜์˜จ๋‹ค๋ฉด, ๊ทธ ์ˆ˜๊ฐ€ mod m number์ด๋‹ค. 

 

    ex) inverses for (mod 5) number

         0 -> 0*0^(-1) mod 5 = 1? ์กด์žฌํ•˜์ง€ ์•Š์Œ

         1 -> 1*1^(-1) mod 5 = 1?  1(mod 5)

         2 -> 2*2^(-1) mod 5 = 1?  3(mod 5)

         3 -> 3*3^(-1) mod 5 = 1?  2(mod 5)

         4 -> 4*4^(-1) mod 5 = 1?  4(mod 5)

   

์ฆ‰ ์–ด๋–ค ์ˆ˜์— ๊ณฑํ•ด์„œ ๋‚˜๋จธ์ง€๊ฐ€ 1์ด ๋‚˜์˜ค๊ฒŒ ๋งŒ๋“œ๋Š” ์ˆ˜๊ฐ€ ๋ฐ”๋กœ inverse modulo of b (mod m)

2์—๋Š” 3์„ ๊ณฑํ•ด์•ผ 5๋กœ ๋‚˜๋ˆ„์—ˆ์„ ๋•Œ ๋‚˜๋จธ์ง€๊ฐ€ 1 (์ด ๋•Œ modulo์—๋Š” 0~4๊ฐ€ ๊ฐ€๋Šฅํ•จ)

 

๋งŒ์•ฝ gcd(e, Φ) = 1 ์ด๋ผ๊ณ  ํ•ด๋ณด์ž

1 = ed + Φy

ed = -Φy + 1

d๋Š” e์˜ inverse modulo (์ฆ‰ mod Φ)

๋˜ํ•œ e์™€ Φ๋Š” ์„œ๋กœ์†Œ์ž„ (mutually prime)

 

 

 

๋ชจ๋ฅด๊ฒ ์œผ๋‹ˆ ์˜ˆ์‹œ๋กœ ํ’€์–ด๋ณด์ž

 

e=110, Φ= 273

 

gcd(e, Φ) = 1, -67e + 27Φ=1์ด๋‹ค.

ed mod Φ = 110(-67) mod 273 = 1

d = -67 (๊ทผ๋ฐ ์ด๊ฑฐ๋Š” 0๊ณผ 273 ์‚ฌ์ด๊ฐ€ ์•„๋‹˜)

 

s=d mod Φ = -67 mod 273 = 206

110 modulo 273์˜ inverse๋Š” 206์ž„!

(-67 = 273*(-1) + 206)

 

 

 

4. The RSA public-key cryptosystem

 1) Cryptosystems : ๋ณด์•ˆ ํ†ต์‹ ์„ ์œ„ํ•œ ์‹œ์Šคํ…œ ? ์ •๋ถ€, ์‚ฐ์—…, ํšŒ์‚ฌ ๋“ฑ๋“ฑ์—์„œ ์”€

    sender๊ฐ€ ์•”ํ˜ธํ™”(encryps)ํ•ด์„œ ๋ณด๋‚ด๋ฉด receiver๊ฐ€ ๋ณตํ˜ธํ™”(decrypts)ํ•ด์„œ ๋ฉ”์‹œ์ง€๋ฅผ ์ฝ์Œ

 

    RSA ( Rivest, Shamir, Adleman) System 

    : ๋ฉ”์„ธ์ง€๋Š” ์ˆซ์ž๋กœ ํ‘œํ˜„๋จ

    ์•„์ฃผ ํฐ ์‹ญ์ง„์ˆ˜ ์ •์ˆ˜๋ฅผ ์ธ์ˆ˜๋ถ„ํ•ดํ•˜๋Š”๋ฐ ๋‹คํ•ญ์‹์˜ ์‹œ๊ฐ„ ์•ˆ์— ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋Š” ํšจ์œจ์ ์ธ ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ์—†๋‹ค๋Š” ์‚ฌ์‹ค์— ๊ธฐ๋ฐ˜ํ•จ.

 

   ์˜ˆ์ „์—” ๊ทธ๋ƒฅ ๋‹จ์ˆœํ•˜๊ฒŒ ์–ด๋–ค ๋ฌธ์ž๋ฅผ ๋‹ค๋ฅธ ๋ฌธ์ž๋กœ replaceํ–ˆ๋Š”๋ฐ, ์ด๊ฑด ์‰ฝ๊ฒŒ ๋šซ๋ฆผ

 

 2) RSA

   - ๋ฉ”์‹œ์ง€๋Š” ์ˆซ์ž๋กœ ํ‘œํ˜„๋œ๋‹ค. 

       A, B, C ,... => 1, 2, 3...

   - SEND MONEY => 20, 5, 15, 1, 14, 16, 15, 5, 26 => 200515011416150526

   

    โ‘  ๋‘ ๊ฐœ์˜ ์†Œ์ˆ˜ p, q ๋ฅผ ๊ณจ๋ผ์„œ n=pq๋ฅผ ๊ณ„์‚ฐํ•œ๋‹ค.

    โ‘ก Φ = (p-1)(q-1) ์„ ๊ณ„์‚ฐํ•œ๋‹ค.

    โ‘ข gcd(e, Φ)=1 ์ธ ์•„๋ฌด e๋ฅผ ๊ณ ๋ฅธ๋‹ค.

    โ‘ฃ ed mod Φ = 1์ธ d๋ฅผ ๊ณ„์‚ฐํ•œ๋‹ค. (0<d<Φ)

    โ‘ค n, e๋Š” ์•”ํ˜ธํ™” ํ‚ค(encryption key, prime) : public

        p, q, d๋Š” ๋ณตํ˜ธํ™” ํ‚ค(decryption key) : secret

    โ‘ฅ ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด๋‚ผ ๋•Œ, m์„ c=m^e mod n ์œผ๋กœ ์•”ํ˜ธํ™”ํ•œ๋‹ค.

    โ‘ฆ c๋Š” m=c^d mod n์œผ๋กœ ๋ณตํ˜ธํ™”ํ•œ๋‹ค.