產生公鑰 | 範例 |
選擇一組數列\(w=\{\; w_1,w_2,\ldots,w_n \}\;\) | \(w=\{\;2,7,11,21,42,89,180,354 \}\;\) |
驗證是否為超遞增數列 \(\displaystyle w_i>\sum_{j=1}^{i-1}w_j \),\(i=2,3,\ldots,n\) | \(7>2\) \(11>7+2=9\) \(21>11+7+2=20\) \(42>21+11+7+2=41\) \(89>42+21+11+7+2=83\) \(354>89+42+21+11+7+2=172\) \(w\)的確是超遞增數列 |
選一個比全部\(w\)總和還大的數字\(q\) | \(q=881\),\(\displaystyle q>\sum_{i=1}^n w_i=706\) |
選一個和\(q\)互質的隨機整數\(r\) | \(r=588\),\(gcd(588,881)=1\) |
計算\(\beta_i=rw_i \pmod{q}\) | \((2 * 588)\pmod{881} = 295\) \((7 * 588)\pmod{881} = 592\) \((11 * 588)\pmod{881} = 301\) \((21 * 588)\pmod{881} = 14\) \((42 * 588)\pmod{881} = 28\) \((89 * 588)\pmod{881} = 353\) \((180 * 588)\pmod{881} = 120\) \((354 * 588)\pmod{881} = 236\) |
\(\beta=\{\;\beta_1,\beta_2,\ldots,\beta_n \}\;\)為公鑰 \( (w,q,r) \)為密鑰 | \(\beta=\{\;295, 592, 301, 14, 28, 353, 120, 236\}\;\)為公鑰 \((w,881,588)\)為密鑰 |
加密 | 範例 |
加密\(n\)位元長度的訊息 \(\alpha=(\alpha_1,\alpha_2,\ldots,\alpha_n)\),\(\alpha_i \in \{\;0,1 \}\;\) 其中\(\alpha_i\)是訊息的第\(i\)個位元 | 加密8位元長度的訊息"a" "a"的ASCII碼為97,轉成二進位01100001 \(\alpha=\{\;0,1,1,0,0,0,0,1 \}\;\) |
計算\( \displaystyle c=\sum_{i=1}^{n}\alpha_i \beta_i \) 得到密文\(c\) | 計算\(c=\) \(0 * 295\) \(+ 1 * 592\) \(+ 1 * 301\) \(+ 0 * 14\) \(+ 0 * 28\) \(+ 0 * 353\) \(+ 0 * 120\) \(+ 1 * 236\) \(= 1129\) 得到密文\(c=1129\) |
解密 | 範例 |
計算\(s\equiv r^{-1}\pmod{q}\) 因為\(r\)和\(q\)互質,\( sr\equiv 1\pmod{q} \) 存在整數\(k\)使得\( sr=kq+1 \),\(1=-kq+sr\) 利用輾轉相除法求出符合上式的\(s\)和\(k\) | 設\(q=881\),\(r=588\) 輾轉相除法 \(881=588\times 1+293\) \(293=881-588\) \(293=q-r\) \(588=293\times 2+2\) \(2=588-293\times 2\) \(2=r-(q-r)\cdot 2=-2q+3r\) \(293=2 \times 146+1\) \(1=293-2\times 146=(q-r)-(-2q+3r)\cdot 146=293q-439r\) \(1=-kq+sr=293q-439r\) \(s \equiv -439 \equiv 442 \pmod{881}\) |
計算\(c' \equiv cs \pmod{q}\) \(\displaystyle c'\equiv cs \equiv \sum_{i=1}^n \alpha_i \beta_i s\pmod{q}\) 因為\(rs\pmod{q}\equiv 1\)和\(\beta_i\equiv rw_i\pmod{q}\) 得到\(\beta_is \equiv w_i rs\equiv w_i \pmod{q}\) \(\displaystyle c'\equiv \sum_{i=1}^n \alpha_i w_i \pmod{q}\) | \(c'\equiv 1129*442 \equiv 372 \pmod{881}\) |
從\(w\)選出最大元素\(w_k\) 若\( w_k>c' \)則\(\alpha_k=0\) 若\( w_k \le c' \)則\( \alpha_k=1 \),將\(c'\)減掉\( w_k \times \alpha_k \) 重複相同步驟直到\(c'=0\)為止( | \(354 \le 372\),\(\alpha_8=1\),\(c'=372-354=18\) \(180>18\),\(\alpha_7=0\) \(89>18\),\(\alpha_6=0\) \(42>18\),\(\alpha_5=0\) \(21>18\),\(\alpha_4=0\) \(11\le 18\),\(\alpha_3=1\),\(c'=18-11=7\) \(7\le 7\),\(\alpha_2=1\),\(c'=7-7=0\) \(2>0\),\(\alpha_1=0\) \(\alpha=\{\;0,1,1,0,0,0,0,1 \}\;\),轉成十進位97,ASCII碼為"a" |
B: LLL(matrix([1,0,0,0,0,0,480], [0,1,0,0,0,0,1810], [0,0,1,0,0,0,2780], [0,0,0,1,0,0,3610], [0,0,0,0,1,0,5060], [0,0,0,0,0,1,6390], [0,0,0,0,0,0,11460])); \(\left[ \matrix{0&0&-1&-1&0&1&0 \cr -1&1&0&0&1&-1&0 \cr \color{red}{-1}& \color{red}{-1}& \color{red}{-1}& \color{red}{0}& \color{red}{0}& \color{red}{-1}& \color{red}{0} \cr -2&-1&1&0&1&1&0 \cr -3&4&-1&3&-4&1&0 \cr 0&0&0&0&-1&-1&10 \cr -2&0&3&-7&-4&-3&0}\right]\) B[3]; \( \left[\matrix{-1&-1&-1&0&0&-1&0} \right]\) | B: LLL(matrix([1,0,0,0,0,0,-480], [0,1,0,0,0,0,-1810], [0,0,1,0,0,0,-2780], [0,0,0,1,0,0,-3610], [0,0,0,0,1,0,-5060], [0,0,0,0,0,1,-6390], [0,0,0,0,0,0,-11460])); \(\left[ \matrix{0&0&-1&-1&0&1&0 \cr -1&1&0&0&1&-1&0 \cr \color{red}{1}&\color{red}{1}&\color{red}{1}&\color{red}{0}&\color{red}{0}&\color{red}{1}&\color{red}{0} \cr -2&-1&1&0&1&1&0 \cr -3&4&-1&3&-4&1&0 \cr 0&0&0&0&-1&-1&10 \cr -2&0&3&-7&-4&-3&0}\right]\) B[3]; \( \left[\matrix{1&1&1&0&0&1&0} \right]\) |
歡迎光臨 Math Pro 數學補給站 (https://math.pro/db/) | 論壇程式使用 Discuz! 6.1.0 |