DES算法的加解密原理(详细算法+样例Demo)

 

对称密码体制的原理

我们使用经典的爱丽丝与鲍伯假设来解释对称密码体制的原理:
(1)爱丽丝与鲍伯约定好一个密钥k,密钥k可以同时用于加密和解密;
(2)爱丽丝将明文m通过密钥k加密成密文c;
(3)爱丽丝将密文c发送给鲍伯;
(4)鲍伯用密钥k将密文c解密成明文m。

对称密码体制的原理示意图

1. 输入数据流的处理

DES算法利用64位的密钥K对64位的明文M进行加密,得到64位的密文C。如果明文数据流M的长度大于64位,则需要把明文切成一个个64位的数据块,用密钥K分批加密。如果密钥K的长度大于64位,则多余的部分将被忽略。

例如,有一个长为200位的明文数据流M,以及一个70位的密钥K。则密钥K的最后6位将被截断,得到一个64位的密钥,我们还记为K。则

M[200bits] = M1[64bits] + M2[64bits] + M3[64bits] + M4[8bits]
C[200bits] = K(M1) + K(M2) + K(M3) + K(M4)

最后的C就是我们加密得到的密文。如要解密,只要反向操作即可

C[200bits] = C1[64bits] + C2[64bits] + C3[64bits] + C4[8bits]
M[200bits] = K-1(C1) + K-1(C2) + K-1(C3) + K-1(C4)

最后的M就是我们解密得到的明文。

2. 密钥的生成

给定密钥K=“ABCDEFGH”,密钥K有8个字节也就是64位,写成二进制形式就是

Key[64bits] = 01000001 01000010 01000011 01000100 01000101 01000110 01000111 01001000

Key的第8, 16, 24, 32, 40, 48, 56, 64位(红色的位)共8位是奇偶校验位,不参与密钥的生成,所以要用到的Key其实一共是56位。给定PC-1置换表

<span style="color:#000000"><code class="language-cpp">PC<span style="color:#669900">-</span><span style="color:#98c379">1</span>_table<span style="color:#999999">[</span><span style="color:#98c379">56</span><span style="color:#999999">]</span> <span style="color:#669900">=</span> <span style="color:#98c379">57</span><span style="color:#999999">,</span> <span style="color:#98c379">49</span><span style="color:#999999">,</span> <span style="color:#98c379">41</span><span style="color:#999999">,</span> <span style="color:#98c379">33</span><span style="color:#999999">,</span> <span style="color:#98c379">25</span><span style="color:#999999">,</span> <span style="color:#98c379">17</span><span style="color:#999999">,</span>  <span style="color:#98c379">9</span><span style="color:#999999">,</span>  <span style="color:#98c379">1</span><span style="color:#999999">,</span> <span style="color:#98c379">58</span><span style="color:#999999">,</span> <span style="color:#98c379">50</span><span style="color:#999999">,</span> <span style="color:#98c379">42</span><span style="color:#999999">,</span> <span style="color:#98c379">34</span><span style="color:#999999">,</span> <span style="color:#98c379">26</span><span style="color:#999999">,</span> <span style="color:#98c379">18</span><span style="color:#999999">,</span>
                 <span style="color:#98c379">10</span><span style="color:#999999">,</span>  <span style="color:#98c379">2</span><span style="color:#999999">,</span> <span style="color:#98c379">59</span><span style="color:#999999">,</span> <span style="color:#98c379">51</span><span style="color:#999999">,</span> <span style="color:#98c379">43</span><span style="color:#999999">,</span> <span style="color:#98c379">35</span><span style="color:#999999">,</span> <span style="color:#98c379">27</span><span style="color:#999999">,</span> <span style="color:#98c379">19</span><span style="color:#999999">,</span> <span style="color:#98c379">11</span><span style="color:#999999">,</span>  <span style="color:#98c379">3</span><span style="color:#999999">,</span> <span style="color:#98c379">60</span><span style="color:#999999">,</span> <span style="color:#98c379">52</span><span style="color:#999999">,</span> <span style="color:#98c379">44</span><span style="color:#999999">,</span> <span style="color:#98c379">36</span><span style="color:#999999">,</span>
                 <span style="color:#98c379">63</span><span style="color:#999999">,</span> <span style="color:#98c379">55</span><span style="color:#999999">,</span> <span style="color:#98c379">47</span><span style="color:#999999">,</span> <span style="color:#98c379">39</span><span style="color:#999999">,</span> <span style="color:#98c379">31</span><span style="color:#999999">,</span> <span style="color:#98c379">23</span><span style="color:#999999">,</span> <span style="color:#98c379">15</span><span style="color:#999999">,</span>  <span style="color:#98c379">7</span><span style="color:#999999">,</span> <span style="color:#98c379">62</span><span style="color:#999999">,</span> <span style="color:#98c379">54</span><span style="color:#999999">,</span> <span style="color:#98c379">46</span><span style="color:#999999">,</span> <span style="color:#98c379">38</span><span style="color:#999999">,</span> <span style="color:#98c379">30</span><span style="color:#999999">,</span> <span style="color:#98c379">22</span><span style="color:#999999">,</span>
                 <span style="color:#98c379">14</span><span style="color:#999999">,</span>  <span style="color:#98c379">6</span><span style="color:#999999">,</span> <span style="color:#98c379">61</span><span style="color:#999999">,</span> <span style="color:#98c379">53</span><span style="color:#999999">,</span> <span style="color:#98c379">45</span><span style="color:#999999">,</span> <span style="color:#98c379">37</span><span style="color:#999999">,</span> <span style="color:#98c379">29</span><span style="color:#999999">,</span> <span style="color:#98c379">21</span><span style="color:#999999">,</span> <span style="color:#98c379">13</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span> <span style="color:#98c379">28</span><span style="color:#999999">,</span> <span style="color:#98c379">20</span><span style="color:#999999">,</span> <span style="color:#98c379">12</span><span style="color:#999999">,</span>  <span style="color:#98c379">4</span>
</code></span>
  • 1
  • 2
  • 3
  • 4

PC-1置换表的第一位57表示,置换后的第一位是Key的第57位“0”,即PC-1(Key)[0] = Key[57] = 0,以此类推。通过PC-1置换表,我们把Key的各位打乱顺序,并把值赋给C0和D0,即有

PC-1(key) = 0000000 0111111 1100000 0000000 0110011 0011110 0010000 0000000
C0[28bits] = 0000000 0111111 1100000 0000000
D0[28bits] = 0110011 0011110 0010000 0000000

给定循环左移表

<span style="color:#000000"><code class="language-cpp">LOOP_table<span style="color:#999999">[</span><span style="color:#98c379">16</span><span style="color:#999999">]</span> <span style="color:#669900">=</span> <span style="color:#98c379">1</span><span style="color:#999999">,</span> <span style="color:#98c379">1</span><span style="color:#999999">,</span> <span style="color:#98c379">2</span><span style="color:#999999">,</span> <span style="color:#98c379">2</span><span style="color:#999999">,</span> <span style="color:#98c379">2</span><span style="color:#999999">,</span> <span style="color:#98c379">2</span><span style="color:#999999">,</span> <span style="color:#98c379">2</span><span style="color:#999999">,</span> <span style="color:#98c379">2</span><span style="color:#999999">,</span> <span style="color:#98c379">1</span><span style="color:#999999">,</span> <span style="color:#98c379">2</span><span style="color:#999999">,</span> <span style="color:#98c379">2</span><span style="color:#999999">,</span> <span style="color:#98c379">2</span><span style="color:#999999">,</span> <span style="color:#98c379">2</span><span style="color:#999999">,</span> <span style="color:#98c379">2</span><span style="color:#999999">,</span> <span style="color:#98c379">2</span><span style="color:#999999">,</span> <span style="color:#98c379">1</span>
</code></span>
  • 1

循环左移表的第一位1表示C1是C0左移1位得到的,D1是D0左移1位得到的,C0左边溢出的一位放在C1最右边,D0左边溢出的一位放在D1最右边,C2, D2, ……, C16, D16的生成以此类推。于是有

C1[28bits] = 0000000 1111111 1000000 0000000
D1[28bits] = 1100110 0111100 0100000 0000000
C2[28bits] = 0000001 1111111 0000000 0000000
D2[28bits] = 1001100 1111000 1000000 0000001
………… ………… ………… ………… …………
C16[28bits] = 0000000 0111111 1100000 0000000
D16[28bits] = 0110011 0011110 0010000 0000000

给定PC-2置换表

<span style="color:#000000"><code class="language-cpp">PC<span style="color:#669900">-</span><span style="color:#98c379">2</span>_table<span style="color:#999999">[</span><span style="color:#98c379">48</span><span style="color:#999999">]</span> <span style="color:#669900">=</span> <span style="color:#98c379">14</span><span style="color:#999999">,</span> <span style="color:#98c379">17</span><span style="color:#999999">,</span> <span style="color:#98c379">11</span><span style="color:#999999">,</span> <span style="color:#98c379">24</span><span style="color:#999999">,</span>  <span style="color:#98c379">1</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span>  <span style="color:#98c379">3</span><span style="color:#999999">,</span> <span style="color:#98c379">28</span><span style="color:#999999">,</span> <span style="color:#98c379">15</span><span style="color:#999999">,</span>  <span style="color:#98c379">6</span><span style="color:#999999">,</span> <span style="color:#98c379">21</span><span style="color:#999999">,</span> <span style="color:#98c379">10</span><span style="color:#999999">,</span>
                 <span style="color:#98c379">23</span><span style="color:#999999">,</span> <span style="color:#98c379">19</span><span style="color:#999999">,</span> <span style="color:#98c379">12</span><span style="color:#999999">,</span>  <span style="color:#98c379">4</span><span style="color:#999999">,</span> <span style="color:#98c379">26</span><span style="color:#999999">,</span>  <span style="color:#98c379">8</span><span style="color:#999999">,</span> <span style="color:#98c379">16</span><span style="color:#999999">,</span>  <span style="color:#98c379">7</span><span style="color:#999999">,</span> <span style="color:#98c379">27</span><span style="color:#999999">,</span> <span style="color:#98c379">20</span><span style="color:#999999">,</span> <span style="color:#98c379">13</span><span style="color:#999999">,</span>  <span style="color:#98c379">2</span><span style="color:#999999">,</span>
                 <span style="color:#98c379">41</span><span style="color:#999999">,</span> <span style="color:#98c379">52</span><span style="color:#999999">,</span> <span style="color:#98c379">31</span><span style="color:#999999">,</span> <span style="color:#98c379">37</span><span style="color:#999999">,</span> <span style="color:#98c379">47</span><span style="color:#999999">,</span> <span style="color:#98c379">55</span><span style="color:#999999">,</span> <span style="color:#98c379">30</span><span style="color:#999999">,</span> <span style="color:#98c379">40</span><span style="color:#999999">,</span> <span style="color:#98c379">51</span><span style="color:#999999">,</span> <span style="color:#98c379">45</span><span style="color:#999999">,</span> <span style="color:#98c379">33</span><span style="color:#999999">,</span> <span style="color:#98c379">48</span><span style="color:#999999">,</span>
                 <span style="color:#98c379">44</span><span style="color:#999999">,</span> <span style="color:#98c379">49</span><span style="color:#999999">,</span> <span style="color:#98c379">39</span><span style="color:#999999">,</span> <span style="color:#98c379">56</span><span style="color:#999999">,</span> <span style="color:#98c379">34</span><span style="color:#999999">,</span> <span style="color:#98c379">53</span><span style="color:#999999">,</span> <span style="color:#98c379">46</span><span style="color:#999999">,</span> <span style="color:#98c379">42</span><span style="color:#999999">,</span> <span style="color:#98c379">50</span><span style="color:#999999">,</span> <span style="color:#98c379">36</span><span style="color:#999999">,</span> <span style="color:#98c379">29</span><span style="color:#999999">,</span> <span style="color:#98c379">32</span>
</code></span>
  • 1
  • 2
  • 3
  • 4

将C1D1通过PC-2置换表变成K1。K2, K3, ……, K16的生成过程以此类推。于是有

K1[48bits] = PC-2(C1D1) = 101000 001001 001001 000010 000100 110010 101010 000010
K2[48bits] = PC-2(C2D2) = 101000 000001 001001 010010 000100 000010 001100 000111
………… ………… ………… ………… ………… ………… ………… ………… ………… …………
K16[48bits] = PC-2(C16D16) = 101000 001001 001000 100010 101000 110100 001010 000000

至此,我们生成了16个密钥K1, K2, ……, K16,每个密钥48位。
将密钥生成的过程总结一下就是

C0D0=PC−1(Key)Di=LOOP(Di−1)Ki=PC−2(CiDi)i=1,2,…,16C_{0}D_{0} = PC-1(Key)\\D_{i} = LOOP(D_{i-1})\quad K_{i} = PC-2(C_{i}D_{i})\quad i = 1, 2, …, 16C0​D0​=PC−1(Key)Di​=LOOP(Di−1​)Ki​=PC−2(CiDi​)i=1,2,…,16

其中Key[64bits],Ci[28bits],Di[28bits],Ki[48bits]。

3. 明文的加密

给定明文M=“12345678”,明文M有8个字节也就是64位,写成二进制形式就是

M[64bits] = 00110001 00110010 00110011 00110100 00110101 00110110 00110111 00111000

给定初始置换表

<span style="color:#000000"><code class="language-cpp">IP_table<span style="color:#999999">[</span><span style="color:#98c379">64</span><span style="color:#999999">]</span> <span style="color:#669900">=</span> <span style="color:#98c379">58</span><span style="color:#999999">,</span> <span style="color:#98c379">50</span><span style="color:#999999">,</span> <span style="color:#98c379">42</span><span style="color:#999999">,</span> <span style="color:#98c379">34</span><span style="color:#999999">,</span> <span style="color:#98c379">26</span><span style="color:#999999">,</span> <span style="color:#98c379">18</span><span style="color:#999999">,</span> <span style="color:#98c379">10</span><span style="color:#999999">,</span>  <span style="color:#98c379">2</span><span style="color:#999999">,</span> <span style="color:#98c379">60</span><span style="color:#999999">,</span> <span style="color:#98c379">52</span><span style="color:#999999">,</span> <span style="color:#98c379">44</span><span style="color:#999999">,</span> <span style="color:#98c379">36</span><span style="color:#999999">,</span> <span style="color:#98c379">28</span><span style="color:#999999">,</span> <span style="color:#98c379">20</span><span style="color:#999999">,</span> <span style="color:#98c379">12</span><span style="color:#999999">,</span>  <span style="color:#98c379">4</span><span style="color:#999999">,</span>
               <span style="color:#98c379">62</span><span style="color:#999999">,</span> <span style="color:#98c379">54</span><span style="color:#999999">,</span> <span style="color:#98c379">46</span><span style="color:#999999">,</span> <span style="color:#98c379">38</span><span style="color:#999999">,</span> <span style="color:#98c379">30</span><span style="color:#999999">,</span> <span style="color:#98c379">22</span><span style="color:#999999">,</span> <span style="color:#98c379">14</span><span style="color:#999999">,</span>  <span style="color:#98c379">6</span><span style="color:#999999">,</span> <span style="color:#98c379">64</span><span style="color:#999999">,</span> <span style="color:#98c379">56</span><span style="color:#999999">,</span> <span style="color:#98c379">48</span><span style="color:#999999">,</span> <span style="color:#98c379">40</span><span style="color:#999999">,</span> <span style="color:#98c379">32</span><span style="color:#999999">,</span> <span style="color:#98c379">24</span><span style="color:#999999">,</span> <span style="color:#98c379">16</span><span style="color:#999999">,</span>  <span style="color:#98c379">8</span><span style="color:#999999">,</span>
               <span style="color:#98c379">57</span><span style="color:#999999">,</span> <span style="color:#98c379">49</span><span style="color:#999999">,</span> <span style="color:#98c379">41</span><span style="color:#999999">,</span> <span style="color:#98c379">33</span><span style="color:#999999">,</span> <span style="color:#98c379">25</span><span style="color:#999999">,</span> <span style="color:#98c379">17</span><span style="color:#999999">,</span>  <span style="color:#98c379">9</span><span style="color:#999999">,</span>  <span style="color:#98c379">1</span><span style="color:#999999">,</span> <span style="color:#98c379">59</span><span style="color:#999999">,</span> <span style="color:#98c379">51</span><span style="color:#999999">,</span> <span style="color:#98c379">43</span><span style="color:#999999">,</span> <span style="color:#98c379">35</span><span style="color:#999999">,</span> <span style="color:#98c379">27</span><span style="color:#999999">,</span> <span style="color:#98c379">19</span><span style="color:#999999">,</span> <span style="color:#98c379">11</span><span style="color:#999999">,</span>  <span style="color:#98c379">3</span><span style="color:#999999">,</span>
               <span style="color:#98c379">61</span><span style="color:#999999">,</span> <span style="color:#98c379">53</span><span style="color:#999999">,</span> <span style="color:#98c379">45</span><span style="color:#999999">,</span> <span style="color:#98c379">37</span><span style="color:#999999">,</span> <span style="color:#98c379">29</span><span style="color:#999999">,</span> <span style="color:#98c379">21</span><span style="color:#999999">,</span> <span style="color:#98c379">13</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span> <span style="color:#98c379">63</span><span style="color:#999999">,</span> <span style="color:#98c379">55</span><span style="color:#999999">,</span> <span style="color:#98c379">47</span><span style="color:#999999">,</span> <span style="color:#98c379">39</span><span style="color:#999999">,</span> <span style="color:#98c379">31</span><span style="color:#999999">,</span> <span style="color:#98c379">23</span><span style="color:#999999">,</span> <span style="color:#98c379">15</span><span style="color:#999999">,</span>  <span style="color:#98c379">7</span>
</code></span>
  • 1
  • 2
  • 3
  • 4

通过初始置换表,我们把M的各位打乱顺序,并把值赋给L0和R0,即有

IP(M) = 00000000 11111111 01111000 01010101 00000000 11111111 10000000 01100110
L0[32bits] = 00000000 11111111 01111000 01010101
R0[32bits] = 00000000 11111111 10000000 01100110

给定E盒置换表

<span style="color:#000000"><code class="language-cpp">E_table<span style="color:#999999">[</span><span style="color:#98c379">48</span><span style="color:#999999">]</span> <span style="color:#669900">=</span> <span style="color:#98c379">32</span><span style="color:#999999">,</span>  <span style="color:#98c379">1</span><span style="color:#999999">,</span>  <span style="color:#98c379">2</span><span style="color:#999999">,</span>  <span style="color:#98c379">3</span><span style="color:#999999">,</span>  <span style="color:#98c379">4</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span>  <span style="color:#98c379">4</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span>
               <span style="color:#98c379">6</span><span style="color:#999999">,</span>  <span style="color:#98c379">7</span><span style="color:#999999">,</span>  <span style="color:#98c379">8</span><span style="color:#999999">,</span>  <span style="color:#98c379">9</span><span style="color:#999999">,</span>  <span style="color:#98c379">8</span><span style="color:#999999">,</span>  <span style="color:#98c379">9</span><span style="color:#999999">,</span> <span style="color:#98c379">10</span><span style="color:#999999">,</span> <span style="color:#98c379">11</span><span style="color:#999999">,</span>
              <span style="color:#98c379">12</span><span style="color:#999999">,</span> <span style="color:#98c379">13</span><span style="color:#999999">,</span> <span style="color:#98c379">12</span><span style="color:#999999">,</span> <span style="color:#98c379">13</span><span style="color:#999999">,</span> <span style="color:#98c379">14</span><span style="color:#999999">,</span> <span style="color:#98c379">15</span><span style="color:#999999">,</span> <span style="color:#98c379">16</span><span style="color:#999999">,</span> <span style="color:#98c379">17</span><span style="color:#999999">,</span>
              <span style="color:#98c379">16</span><span style="color:#999999">,</span> <span style="color:#98c379">17</span><span style="color:#999999">,</span> <span style="color:#98c379">18</span><span style="color:#999999">,</span> <span style="color:#98c379">19</span><span style="color:#999999">,</span> <span style="color:#98c379">20</span><span style="color:#999999">,</span> <span style="color:#98c379">21</span><span style="color:#999999">,</span> <span style="color:#98c379">20</span><span style="color:#999999">,</span> <span style="color:#98c379">21</span><span style="color:#999999">,</span>
              <span style="color:#98c379">22</span><span style="color:#999999">,</span> <span style="color:#98c379">23</span><span style="color:#999999">,</span> <span style="color:#98c379">24</span><span style="color:#999999">,</span> <span style="color:#98c379">25</span><span style="color:#999999">,</span> <span style="color:#98c379">24</span><span style="color:#999999">,</span> <span style="color:#98c379">25</span><span style="color:#999999">,</span> <span style="color:#98c379">26</span><span style="color:#999999">,</span> <span style="color:#98c379">27</span><span style="color:#999999">,</span>
              <span style="color:#98c379">28</span><span style="color:#999999">,</span> <span style="color:#98c379">29</span><span style="color:#999999">,</span> <span style="color:#98c379">28</span><span style="color:#999999">,</span> <span style="color:#98c379">29</span><span style="color:#999999">,</span> <span style="color:#98c379">30</span><span style="color:#999999">,</span> <span style="color:#98c379">31</span><span style="color:#999999">,</span> <span style="color:#98c379">32</span><span style="color:#999999">,</span>  <span style="color:#98c379">1</span>
</code></span>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

将R0通过E盒置换得到

E(R0)[48bits] = 000000 000001 011111 111111 110000 000000 001100 001100

之前生成的K1为

K1[48bits] = 101000 001001 001001 000010 000100 110010 101010 000010

把E(R0)与K1按位异或运算得到

E(R0)⊕K1[48bits] = 101000 001000 010110 111101 110100 110010 100110 001110

给定S盒置换表

<span style="color:#000000"><code class="language-cpp">S_table<span style="color:#999999">[</span><span style="color:#98c379">1</span><span style="color:#999999">]</span> <span style="color:#669900">=</span> <span style="color:#98c379">14</span><span style="color:#999999">,</span>  <span style="color:#98c379">4</span><span style="color:#999999">,</span> <span style="color:#98c379">13</span><span style="color:#999999">,</span>  <span style="color:#98c379">1</span><span style="color:#999999">,</span>  <span style="color:#98c379">2</span><span style="color:#999999">,</span> <span style="color:#98c379">15</span><span style="color:#999999">,</span> <span style="color:#98c379">11</span><span style="color:#999999">,</span>  <span style="color:#98c379">8</span><span style="color:#999999">,</span>  <span style="color:#98c379">3</span><span style="color:#999999">,</span> <span style="color:#98c379">10</span><span style="color:#999999">,</span>  <span style="color:#98c379">6</span><span style="color:#999999">,</span> <span style="color:#98c379">12</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span>  <span style="color:#98c379">9</span><span style="color:#999999">,</span>  <span style="color:#98c379">0</span><span style="color:#999999">,</span>  <span style="color:#98c379">7</span><span style="color:#999999">,</span>
              <span style="color:#98c379">0</span><span style="color:#999999">,</span> <span style="color:#98c379">15</span><span style="color:#999999">,</span>  <span style="color:#98c379">7</span><span style="color:#999999">,</span>  <span style="color:#98c379">4</span><span style="color:#999999">,</span> <span style="color:#98c379">14</span><span style="color:#999999">,</span>  <span style="color:#98c379">2</span><span style="color:#999999">,</span> <span style="color:#98c379">13</span><span style="color:#999999">,</span>  <span style="color:#98c379">1</span><span style="color:#999999">,</span> <span style="color:#98c379">10</span><span style="color:#999999">,</span>  <span style="color:#98c379">6</span><span style="color:#999999">,</span> <span style="color:#98c379">12</span><span style="color:#999999">,</span> <span style="color:#98c379">11</span><span style="color:#999999">,</span>  <span style="color:#98c379">9</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span>  <span style="color:#98c379">3</span><span style="color:#999999">,</span>  <span style="color:#98c379">8</span><span style="color:#999999">,</span>
              <span style="color:#98c379">4</span><span style="color:#999999">,</span>  <span style="color:#98c379">1</span><span style="color:#999999">,</span> <span style="color:#98c379">14</span><span style="color:#999999">,</span>  <span style="color:#98c379">8</span><span style="color:#999999">,</span> <span style="color:#98c379">13</span><span style="color:#999999">,</span>  <span style="color:#98c379">6</span><span style="color:#999999">,</span>  <span style="color:#98c379">2</span><span style="color:#999999">,</span> <span style="color:#98c379">11</span><span style="color:#999999">,</span> <span style="color:#98c379">15</span><span style="color:#999999">,</span> <span style="color:#98c379">12</span><span style="color:#999999">,</span>  <span style="color:#98c379">9</span><span style="color:#999999">,</span>  <span style="color:#98c379">7</span><span style="color:#999999">,</span>  <span style="color:#98c379">3</span><span style="color:#999999">,</span> <span style="color:#98c379">10</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span>  <span style="color:#98c379">0</span><span style="color:#999999">,</span>
             <span style="color:#98c379">15</span><span style="color:#999999">,</span> <span style="color:#98c379">12</span><span style="color:#999999">,</span>  <span style="color:#98c379">8</span><span style="color:#999999">,</span>  <span style="color:#98c379">2</span><span style="color:#999999">,</span>  <span style="color:#98c379">4</span><span style="color:#999999">,</span>  <span style="color:#98c379">9</span><span style="color:#999999">,</span>  <span style="color:#98c379">1</span><span style="color:#999999">,</span>  <span style="color:#98c379">7</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span> <span style="color:#98c379">11</span><span style="color:#999999">,</span>  <span style="color:#98c379">3</span><span style="color:#999999">,</span> <span style="color:#98c379">14</span><span style="color:#999999">,</span> <span style="color:#98c379">10</span><span style="color:#999999">,</span>  <span style="color:#98c379">0</span><span style="color:#999999">,</span>  <span style="color:#98c379">6</span><span style="color:#999999">,</span> <span style="color:#98c379">13</span><span style="color:#999999">,</span>

S_table<span style="color:#999999">[</span><span style="color:#98c379">2</span><span style="color:#999999">]</span> <span style="color:#669900">=</span> <span style="color:#98c379">15</span><span style="color:#999999">,</span>  <span style="color:#98c379">1</span><span style="color:#999999">,</span>  <span style="color:#98c379">8</span><span style="color:#999999">,</span> <span style="color:#98c379">14</span><span style="color:#999999">,</span>  <span style="color:#98c379">6</span><span style="color:#999999">,</span> <span style="color:#98c379">11</span><span style="color:#999999">,</span>  <span style="color:#98c379">3</span><span style="color:#999999">,</span>  <span style="color:#98c379">4</span><span style="color:#999999">,</span>  <span style="color:#98c379">9</span><span style="color:#999999">,</span>  <span style="color:#98c379">7</span><span style="color:#999999">,</span>  <span style="color:#98c379">2</span><span style="color:#999999">,</span> <span style="color:#98c379">13</span><span style="color:#999999">,</span> <span style="color:#98c379">12</span><span style="color:#999999">,</span>  <span style="color:#98c379">0</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span> <span style="color:#98c379">10</span><span style="color:#999999">,</span>
              <span style="color:#98c379">3</span><span style="color:#999999">,</span> <span style="color:#98c379">13</span><span style="color:#999999">,</span>  <span style="color:#98c379">4</span><span style="color:#999999">,</span>  <span style="color:#98c379">7</span><span style="color:#999999">,</span> <span style="color:#98c379">15</span><span style="color:#999999">,</span>  <span style="color:#98c379">2</span><span style="color:#999999">,</span>  <span style="color:#98c379">8</span><span style="color:#999999">,</span> <span style="color:#98c379">14</span><span style="color:#999999">,</span> <span style="color:#98c379">12</span><span style="color:#999999">,</span>  <span style="color:#98c379">0</span><span style="color:#999999">,</span>  <span style="color:#98c379">1</span><span style="color:#999999">,</span> <span style="color:#98c379">10</span><span style="color:#999999">,</span>  <span style="color:#98c379">6</span><span style="color:#999999">,</span>  <span style="color:#98c379">9</span><span style="color:#999999">,</span> <span style="color:#98c379">11</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span>
              <span style="color:#98c379">0</span><span style="color:#999999">,</span> <span style="color:#98c379">14</span><span style="color:#999999">,</span>  <span style="color:#98c379">7</span><span style="color:#999999">,</span> <span style="color:#98c379">11</span><span style="color:#999999">,</span> <span style="color:#98c379">10</span><span style="color:#999999">,</span>  <span style="color:#98c379">4</span><span style="color:#999999">,</span> <span style="color:#98c379">13</span><span style="color:#999999">,</span>  <span style="color:#98c379">1</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span>  <span style="color:#98c379">8</span><span style="color:#999999">,</span> <span style="color:#98c379">12</span><span style="color:#999999">,</span>  <span style="color:#98c379">6</span><span style="color:#999999">,</span>  <span style="color:#98c379">9</span><span style="color:#999999">,</span>  <span style="color:#98c379">3</span><span style="color:#999999">,</span>  <span style="color:#98c379">2</span><span style="color:#999999">,</span> <span style="color:#98c379">15</span><span style="color:#999999">,</span>
             <span style="color:#98c379">13</span><span style="color:#999999">,</span>  <span style="color:#98c379">8</span><span style="color:#999999">,</span> <span style="color:#98c379">10</span><span style="color:#999999">,</span>  <span style="color:#98c379">1</span><span style="color:#999999">,</span>  <span style="color:#98c379">3</span><span style="color:#999999">,</span> <span style="color:#98c379">15</span><span style="color:#999999">,</span>  <span style="color:#98c379">4</span><span style="color:#999999">,</span>  <span style="color:#98c379">2</span><span style="color:#999999">,</span> <span style="color:#98c379">11</span><span style="color:#999999">,</span>  <span style="color:#98c379">6</span><span style="color:#999999">,</span>  <span style="color:#98c379">7</span><span style="color:#999999">,</span> <span style="color:#98c379">12</span><span style="color:#999999">,</span>  <span style="color:#98c379">0</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span> <span style="color:#98c379">14</span><span style="color:#999999">,</span>  <span style="color:#98c379">9</span><span style="color:#999999">,</span>

S_table<span style="color:#999999">[</span><span style="color:#98c379">3</span><span style="color:#999999">]</span> <span style="color:#669900">=</span> <span style="color:#98c379">10</span><span style="color:#999999">,</span>  <span style="color:#98c379">0</span><span style="color:#999999">,</span>  <span style="color:#98c379">9</span><span style="color:#999999">,</span> <span style="color:#98c379">14</span><span style="color:#999999">,</span>  <span style="color:#98c379">6</span><span style="color:#999999">,</span>  <span style="color:#98c379">3</span><span style="color:#999999">,</span> <span style="color:#98c379">15</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span>  <span style="color:#98c379">1</span><span style="color:#999999">,</span> <span style="color:#98c379">13</span><span style="color:#999999">,</span> <span style="color:#98c379">12</span><span style="color:#999999">,</span>  <span style="color:#98c379">7</span><span style="color:#999999">,</span> <span style="color:#98c379">11</span><span style="color:#999999">,</span>  <span style="color:#98c379">4</span><span style="color:#999999">,</span>  <span style="color:#98c379">2</span><span style="color:#999999">,</span>  <span style="color:#98c379">8</span><span style="color:#999999">,</span>
             <span style="color:#98c379">13</span><span style="color:#999999">,</span>  <span style="color:#98c379">7</span><span style="color:#999999">,</span>  <span style="color:#98c379">0</span><span style="color:#999999">,</span>  <span style="color:#98c379">9</span><span style="color:#999999">,</span>  <span style="color:#98c379">3</span><span style="color:#999999">,</span>  <span style="color:#98c379">4</span><span style="color:#999999">,</span>  <span style="color:#98c379">6</span><span style="color:#999999">,</span> <span style="color:#98c379">10</span><span style="color:#999999">,</span>  <span style="color:#98c379">2</span><span style="color:#999999">,</span>  <span style="color:#98c379">8</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span> <span style="color:#98c379">14</span><span style="color:#999999">,</span> <span style="color:#98c379">12</span><span style="color:#999999">,</span> <span style="color:#98c379">11</span><span style="color:#999999">,</span> <span style="color:#98c379">15</span><span style="color:#999999">,</span>  <span style="color:#98c379">1</span><span style="color:#999999">,</span>
             <span style="color:#98c379">13</span><span style="color:#999999">,</span>  <span style="color:#98c379">6</span><span style="color:#999999">,</span>  <span style="color:#98c379">4</span><span style="color:#999999">,</span>  <span style="color:#98c379">9</span><span style="color:#999999">,</span>  <span style="color:#98c379">8</span><span style="color:#999999">,</span> <span style="color:#98c379">15</span><span style="color:#999999">,</span>  <span style="color:#98c379">3</span><span style="color:#999999">,</span>  <span style="color:#98c379">0</span><span style="color:#999999">,</span> <span style="color:#98c379">11</span><span style="color:#999999">,</span>  <span style="color:#98c379">1</span><span style="color:#999999">,</span>  <span style="color:#98c379">2</span><span style="color:#999999">,</span> <span style="color:#98c379">12</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span> <span style="color:#98c379">10</span><span style="color:#999999">,</span> <span style="color:#98c379">14</span><span style="color:#999999">,</span>  <span style="color:#98c379">7</span><span style="color:#999999">,</span>
              <span style="color:#98c379">1</span><span style="color:#999999">,</span> <span style="color:#98c379">10</span><span style="color:#999999">,</span> <span style="color:#98c379">13</span><span style="color:#999999">,</span>  <span style="color:#98c379">0</span><span style="color:#999999">,</span>  <span style="color:#98c379">6</span><span style="color:#999999">,</span>  <span style="color:#98c379">9</span><span style="color:#999999">,</span>  <span style="color:#98c379">8</span><span style="color:#999999">,</span>  <span style="color:#98c379">7</span><span style="color:#999999">,</span>  <span style="color:#98c379">4</span><span style="color:#999999">,</span> <span style="color:#98c379">15</span><span style="color:#999999">,</span> <span style="color:#98c379">14</span><span style="color:#999999">,</span>  <span style="color:#98c379">3</span><span style="color:#999999">,</span> <span style="color:#98c379">11</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span>  <span style="color:#98c379">2</span><span style="color:#999999">,</span> <span style="color:#98c379">12</span><span style="color:#999999">,</span>

S_table<span style="color:#999999">[</span><span style="color:#98c379">4</span><span style="color:#999999">]</span> <span style="color:#669900">=</span>  <span style="color:#98c379">7</span><span style="color:#999999">,</span> <span style="color:#98c379">13</span><span style="color:#999999">,</span> <span style="color:#98c379">14</span><span style="color:#999999">,</span>  <span style="color:#98c379">3</span><span style="color:#999999">,</span>  <span style="color:#98c379">0</span><span style="color:#999999">,</span>  <span style="color:#98c379">6</span><span style="color:#999999">,</span>  <span style="color:#98c379">9</span><span style="color:#999999">,</span> <span style="color:#98c379">10</span><span style="color:#999999">,</span>  <span style="color:#98c379">1</span><span style="color:#999999">,</span>  <span style="color:#98c379">2</span><span style="color:#999999">,</span>  <span style="color:#98c379">8</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span> <span style="color:#98c379">11</span><span style="color:#999999">,</span> <span style="color:#98c379">12</span><span style="color:#999999">,</span>  <span style="color:#98c379">4</span><span style="color:#999999">,</span> <span style="color:#98c379">15</span><span style="color:#999999">,</span>
             <span style="color:#98c379">13</span><span style="color:#999999">,</span>  <span style="color:#98c379">8</span><span style="color:#999999">,</span> <span style="color:#98c379">11</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span>  <span style="color:#98c379">6</span><span style="color:#999999">,</span> <span style="color:#98c379">15</span><span style="color:#999999">,</span>  <span style="color:#98c379">0</span><span style="color:#999999">,</span>  <span style="color:#98c379">3</span><span style="color:#999999">,</span>  <span style="color:#98c379">4</span><span style="color:#999999">,</span>  <span style="color:#98c379">7</span><span style="color:#999999">,</span>  <span style="color:#98c379">2</span><span style="color:#999999">,</span> <span style="color:#98c379">12</span><span style="color:#999999">,</span>  <span style="color:#98c379">1</span><span style="color:#999999">,</span> <span style="color:#98c379">10</span><span style="color:#999999">,</span> <span style="color:#98c379">14</span><span style="color:#999999">,</span> <span style="color:#98c379">19</span><span style="color:#999999">,</span>
             <span style="color:#98c379">10</span><span style="color:#999999">,</span>  <span style="color:#98c379">6</span><span style="color:#999999">,</span>  <span style="color:#98c379">9</span><span style="color:#999999">,</span>  <span style="color:#98c379">0</span><span style="color:#999999">,</span> <span style="color:#98c379">12</span><span style="color:#999999">,</span> <span style="color:#98c379">11</span><span style="color:#999999">,</span>  <span style="color:#98c379">7</span><span style="color:#999999">,</span> <span style="color:#98c379">13</span><span style="color:#999999">,</span> <span style="color:#98c379">15</span><span style="color:#999999">,</span>  <span style="color:#98c379">1</span><span style="color:#999999">,</span>  <span style="color:#98c379">3</span><span style="color:#999999">,</span> <span style="color:#98c379">14</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span>  <span style="color:#98c379">2</span><span style="color:#999999">,</span>  <span style="color:#98c379">8</span><span style="color:#999999">,</span>  <span style="color:#98c379">4</span><span style="color:#999999">,</span>
              <span style="color:#98c379">3</span><span style="color:#999999">,</span> <span style="color:#98c379">15</span><span style="color:#999999">,</span>  <span style="color:#98c379">0</span><span style="color:#999999">,</span>  <span style="color:#98c379">6</span><span style="color:#999999">,</span> <span style="color:#98c379">10</span><span style="color:#999999">,</span>  <span style="color:#98c379">1</span><span style="color:#999999">,</span> <span style="color:#98c379">13</span><span style="color:#999999">,</span>  <span style="color:#98c379">8</span><span style="color:#999999">,</span>  <span style="color:#98c379">9</span><span style="color:#999999">,</span>  <span style="color:#98c379">4</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span> <span style="color:#98c379">11</span><span style="color:#999999">,</span> <span style="color:#98c379">12</span><span style="color:#999999">,</span>  <span style="color:#98c379">7</span><span style="color:#999999">,</span>  <span style="color:#98c379">2</span><span style="color:#999999">,</span> <span style="color:#98c379">14</span><span style="color:#999999">,</span>

S_table<span style="color:#999999">[</span><span style="color:#98c379">5</span><span style="color:#999999">]</span> <span style="color:#669900">=</span>  <span style="color:#98c379">2</span><span style="color:#999999">,</span> <span style="color:#98c379">12</span><span style="color:#999999">,</span>  <span style="color:#98c379">4</span><span style="color:#999999">,</span>  <span style="color:#98c379">1</span><span style="color:#999999">,</span>  <span style="color:#98c379">7</span><span style="color:#999999">,</span> <span style="color:#98c379">10</span><span style="color:#999999">,</span> <span style="color:#98c379">11</span><span style="color:#999999">,</span>  <span style="color:#98c379">6</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span>  <span style="color:#98c379">8</span><span style="color:#999999">,</span>  <span style="color:#98c379">3</span><span style="color:#999999">,</span> <span style="color:#98c379">15</span><span style="color:#999999">,</span> <span style="color:#98c379">13</span><span style="color:#999999">,</span>  <span style="color:#98c379">0</span><span style="color:#999999">,</span> <span style="color:#98c379">14</span><span style="color:#999999">,</span>  <span style="color:#98c379">9</span><span style="color:#999999">,</span>
             <span style="color:#98c379">14</span><span style="color:#999999">,</span> <span style="color:#98c379">11</span><span style="color:#999999">,</span>  <span style="color:#98c379">2</span><span style="color:#999999">,</span> <span style="color:#98c379">12</span><span style="color:#999999">,</span>  <span style="color:#98c379">4</span><span style="color:#999999">,</span>  <span style="color:#98c379">7</span><span style="color:#999999">,</span> <span style="color:#98c379">13</span><span style="color:#999999">,</span>  <span style="color:#98c379">1</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span>  <span style="color:#98c379">0</span><span style="color:#999999">,</span> <span style="color:#98c379">15</span><span style="color:#999999">,</span> <span style="color:#98c379">13</span><span style="color:#999999">,</span>  <span style="color:#98c379">3</span><span style="color:#999999">,</span>  <span style="color:#98c379">9</span><span style="color:#999999">,</span>  <span style="color:#98c379">8</span><span style="color:#999999">,</span>  <span style="color:#98c379">6</span><span style="color:#999999">,</span>
              <span style="color:#98c379">4</span><span style="color:#999999">,</span>  <span style="color:#98c379">2</span><span style="color:#999999">,</span>  <span style="color:#98c379">1</span><span style="color:#999999">,</span> <span style="color:#98c379">11</span><span style="color:#999999">,</span> <span style="color:#98c379">10</span><span style="color:#999999">,</span> <span style="color:#98c379">13</span><span style="color:#999999">,</span>  <span style="color:#98c379">7</span><span style="color:#999999">,</span>  <span style="color:#98c379">8</span><span style="color:#999999">,</span> <span style="color:#98c379">15</span><span style="color:#999999">,</span>  <span style="color:#98c379">9</span><span style="color:#999999">,</span> <span style="color:#98c379">12</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span>  <span style="color:#98c379">6</span><span style="color:#999999">,</span>  <span style="color:#98c379">3</span><span style="color:#999999">,</span>  <span style="color:#98c379">0</span><span style="color:#999999">,</span> <span style="color:#98c379">14</span><span style="color:#999999">,</span>
             <span style="color:#98c379">11</span><span style="color:#999999">,</span>  <span style="color:#98c379">8</span><span style="color:#999999">,</span> <span style="color:#98c379">12</span><span style="color:#999999">,</span>  <span style="color:#98c379">7</span><span style="color:#999999">,</span>  <span style="color:#98c379">1</span><span style="color:#999999">,</span> <span style="color:#98c379">14</span><span style="color:#999999">,</span>  <span style="color:#98c379">2</span><span style="color:#999999">,</span> <span style="color:#98c379">13</span><span style="color:#999999">,</span>  <span style="color:#98c379">6</span><span style="color:#999999">,</span> <span style="color:#98c379">15</span><span style="color:#999999">,</span>  <span style="color:#98c379">0</span><span style="color:#999999">,</span>  <span style="color:#98c379">9</span><span style="color:#999999">,</span> <span style="color:#98c379">10</span><span style="color:#999999">,</span>  <span style="color:#98c379">4</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span>  <span style="color:#98c379">3</span><span style="color:#999999">,</span>

S_table<span style="color:#999999">[</span><span style="color:#98c379">6</span><span style="color:#999999">]</span> <span style="color:#669900">=</span> <span style="color:#98c379">12</span><span style="color:#999999">,</span>  <span style="color:#98c379">1</span><span style="color:#999999">,</span> <span style="color:#98c379">10</span><span style="color:#999999">,</span> <span style="color:#98c379">15</span><span style="color:#999999">,</span>  <span style="color:#98c379">9</span><span style="color:#999999">,</span>  <span style="color:#98c379">2</span><span style="color:#999999">,</span>  <span style="color:#98c379">6</span><span style="color:#999999">,</span>  <span style="color:#98c379">8</span><span style="color:#999999">,</span>  <span style="color:#98c379">0</span><span style="color:#999999">,</span> <span style="color:#98c379">13</span><span style="color:#999999">,</span>  <span style="color:#98c379">3</span><span style="color:#999999">,</span>  <span style="color:#98c379">4</span><span style="color:#999999">,</span> <span style="color:#98c379">14</span><span style="color:#999999">,</span>  <span style="color:#98c379">7</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span> <span style="color:#98c379">11</span><span style="color:#999999">,</span>
             <span style="color:#98c379">10</span><span style="color:#999999">,</span> <span style="color:#98c379">15</span><span style="color:#999999">,</span>  <span style="color:#98c379">4</span><span style="color:#999999">,</span>  <span style="color:#98c379">2</span><span style="color:#999999">,</span>  <span style="color:#98c379">7</span><span style="color:#999999">,</span> <span style="color:#98c379">12</span><span style="color:#999999">,</span>  <span style="color:#98c379">9</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span>  <span style="color:#98c379">6</span><span style="color:#999999">,</span>  <span style="color:#98c379">1</span><span style="color:#999999">,</span> <span style="color:#98c379">13</span><span style="color:#999999">,</span> <span style="color:#98c379">14</span><span style="color:#999999">,</span>  <span style="color:#98c379">0</span><span style="color:#999999">,</span> <span style="color:#98c379">11</span><span style="color:#999999">,</span>  <span style="color:#98c379">3</span><span style="color:#999999">,</span>  <span style="color:#98c379">8</span><span style="color:#999999">,</span>
              <span style="color:#98c379">9</span><span style="color:#999999">,</span> <span style="color:#98c379">14</span><span style="color:#999999">,</span> <span style="color:#98c379">15</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span>  <span style="color:#98c379">2</span><span style="color:#999999">,</span>  <span style="color:#98c379">8</span><span style="color:#999999">,</span> <span style="color:#98c379">12</span><span style="color:#999999">,</span>  <span style="color:#98c379">3</span><span style="color:#999999">,</span>  <span style="color:#98c379">7</span><span style="color:#999999">,</span>  <span style="color:#98c379">0</span><span style="color:#999999">,</span>  <span style="color:#98c379">4</span><span style="color:#999999">,</span> <span style="color:#98c379">10</span><span style="color:#999999">,</span>  <span style="color:#98c379">1</span><span style="color:#999999">,</span> <span style="color:#98c379">13</span><span style="color:#999999">,</span> <span style="color:#98c379">11</span><span style="color:#999999">,</span>  <span style="color:#98c379">6</span><span style="color:#999999">,</span>
              <span style="color:#98c379">4</span><span style="color:#999999">,</span>  <span style="color:#98c379">3</span><span style="color:#999999">,</span>  <span style="color:#98c379">2</span><span style="color:#999999">,</span> <span style="color:#98c379">12</span><span style="color:#999999">,</span>  <span style="color:#98c379">9</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span> <span style="color:#98c379">15</span><span style="color:#999999">,</span> <span style="color:#98c379">10</span><span style="color:#999999">,</span> <span style="color:#98c379">11</span><span style="color:#999999">,</span> <span style="color:#98c379">14</span><span style="color:#999999">,</span>  <span style="color:#98c379">1</span><span style="color:#999999">,</span>  <span style="color:#98c379">7</span><span style="color:#999999">,</span>  <span style="color:#98c379">6</span><span style="color:#999999">,</span>  <span style="color:#98c379">0</span><span style="color:#999999">,</span>  <span style="color:#98c379">8</span><span style="color:#999999">,</span> <span style="color:#98c379">13</span><span style="color:#999999">,</span>

S_table<span style="color:#999999">[</span><span style="color:#98c379">7</span><span style="color:#999999">]</span> <span style="color:#669900">=</span> <span style="color:#98c379">4</span><span style="color:#999999">,</span> <span style="color:#98c379">11</span><span style="color:#999999">,</span>  <span style="color:#98c379">2</span><span style="color:#999999">,</span> <span style="color:#98c379">14</span><span style="color:#999999">,</span> <span style="color:#98c379">15</span><span style="color:#999999">,</span>  <span style="color:#98c379">0</span><span style="color:#999999">,</span>  <span style="color:#98c379">8</span><span style="color:#999999">,</span> <span style="color:#98c379">13</span><span style="color:#999999">,</span>  <span style="color:#98c379">3</span><span style="color:#999999">,</span> <span style="color:#98c379">12</span><span style="color:#999999">,</span>  <span style="color:#98c379">9</span><span style="color:#999999">,</span>  <span style="color:#98c379">7</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span> <span style="color:#98c379">10</span><span style="color:#999999">,</span>  <span style="color:#98c379">6</span><span style="color:#999999">,</span>  <span style="color:#98c379">1</span><span style="color:#999999">,</span>
            <span style="color:#98c379">13</span><span style="color:#999999">,</span>  <span style="color:#98c379">0</span><span style="color:#999999">,</span> <span style="color:#98c379">11</span><span style="color:#999999">,</span>  <span style="color:#98c379">7</span><span style="color:#999999">,</span>  <span style="color:#98c379">4</span><span style="color:#999999">,</span>  <span style="color:#98c379">9</span><span style="color:#999999">,</span>  <span style="color:#98c379">1</span><span style="color:#999999">,</span> <span style="color:#98c379">10</span><span style="color:#999999">,</span> <span style="color:#98c379">14</span><span style="color:#999999">,</span>  <span style="color:#98c379">3</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span> <span style="color:#98c379">12</span><span style="color:#999999">,</span>  <span style="color:#98c379">2</span><span style="color:#999999">,</span> <span style="color:#98c379">15</span><span style="color:#999999">,</span>  <span style="color:#98c379">8</span><span style="color:#999999">,</span>  <span style="color:#98c379">6</span><span style="color:#999999">,</span>
             <span style="color:#98c379">1</span><span style="color:#999999">,</span>  <span style="color:#98c379">4</span><span style="color:#999999">,</span> <span style="color:#98c379">11</span><span style="color:#999999">,</span> <span style="color:#98c379">13</span><span style="color:#999999">,</span> <span style="color:#98c379">12</span><span style="color:#999999">,</span>  <span style="color:#98c379">3</span><span style="color:#999999">,</span>  <span style="color:#98c379">7</span><span style="color:#999999">,</span> <span style="color:#98c379">14</span><span style="color:#999999">,</span> <span style="color:#98c379">10</span><span style="color:#999999">,</span> <span style="color:#98c379">15</span><span style="color:#999999">,</span>  <span style="color:#98c379">6</span><span style="color:#999999">,</span>  <span style="color:#98c379">8</span><span style="color:#999999">,</span>  <span style="color:#98c379">0</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span>  <span style="color:#98c379">9</span><span style="color:#999999">,</span>  <span style="color:#98c379">2</span><span style="color:#999999">,</span>
             <span style="color:#98c379">6</span><span style="color:#999999">,</span> <span style="color:#98c379">11</span><span style="color:#999999">,</span> <span style="color:#98c379">13</span><span style="color:#999999">,</span>  <span style="color:#98c379">8</span><span style="color:#999999">,</span>  <span style="color:#98c379">1</span><span style="color:#999999">,</span>  <span style="color:#98c379">4</span><span style="color:#999999">,</span> <span style="color:#98c379">10</span><span style="color:#999999">,</span>  <span style="color:#98c379">7</span><span style="color:#999999">,</span>  <span style="color:#98c379">9</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span>  <span style="color:#98c379">0</span><span style="color:#999999">,</span> <span style="color:#98c379">15</span><span style="color:#999999">,</span> <span style="color:#98c379">14</span><span style="color:#999999">,</span>  <span style="color:#98c379">2</span><span style="color:#999999">,</span>  <span style="color:#98c379">3</span><span style="color:#999999">,</span> <span style="color:#98c379">12</span><span style="color:#999999">,</span>

S_table<span style="color:#999999">[</span><span style="color:#98c379">8</span><span style="color:#999999">]</span> <span style="color:#669900">=</span> <span style="color:#98c379">13</span><span style="color:#999999">,</span>  <span style="color:#98c379">2</span><span style="color:#999999">,</span>  <span style="color:#98c379">8</span><span style="color:#999999">,</span>  <span style="color:#98c379">4</span><span style="color:#999999">,</span>  <span style="color:#98c379">6</span><span style="color:#999999">,</span> <span style="color:#98c379">15</span><span style="color:#999999">,</span> <span style="color:#98c379">11</span><span style="color:#999999">,</span>  <span style="color:#98c379">1</span><span style="color:#999999">,</span> <span style="color:#98c379">10</span><span style="color:#999999">,</span>  <span style="color:#98c379">9</span><span style="color:#999999">,</span>  <span style="color:#98c379">3</span><span style="color:#999999">,</span> <span style="color:#98c379">14</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span>  <span style="color:#98c379">0</span><span style="color:#999999">,</span> <span style="color:#98c379">12</span><span style="color:#999999">,</span>  <span style="color:#98c379">7</span><span style="color:#999999">,</span>
              <span style="color:#98c379">1</span><span style="color:#999999">,</span> <span style="color:#98c379">15</span><span style="color:#999999">,</span> <span style="color:#98c379">13</span><span style="color:#999999">,</span>  <span style="color:#98c379">8</span><span style="color:#999999">,</span> <span style="color:#98c379">10</span><span style="color:#999999">,</span>  <span style="color:#98c379">3</span><span style="color:#999999">,</span>  <span style="color:#98c379">7</span><span style="color:#999999">,</span>  <span style="color:#98c379">4</span><span style="color:#999999">,</span> <span style="color:#98c379">12</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span>  <span style="color:#98c379">6</span><span style="color:#999999">,</span> <span style="color:#98c379">11</span><span style="color:#999999">,</span>  <span style="color:#98c379">0</span><span style="color:#999999">,</span> <span style="color:#98c379">14</span><span style="color:#999999">,</span>  <span style="color:#98c379">9</span><span style="color:#999999">,</span>  <span style="color:#98c379">2</span><span style="color:#999999">,</span>
              <span style="color:#98c379">7</span><span style="color:#999999">,</span> <span style="color:#98c379">11</span><span style="color:#999999">,</span>  <span style="color:#98c379">4</span><span style="color:#999999">,</span>  <span style="color:#98c379">1</span><span style="color:#999999">,</span>  <span style="color:#98c379">9</span><span style="color:#999999">,</span> <span style="color:#98c379">12</span><span style="color:#999999">,</span> <span style="color:#98c379">14</span><span style="color:#999999">,</span>  <span style="color:#98c379">2</span><span style="color:#999999">,</span>  <span style="color:#98c379">0</span><span style="color:#999999">,</span>  <span style="color:#98c379">6</span><span style="color:#999999">,</span> <span style="color:#98c379">10</span><span style="color:#999999">,</span> <span style="color:#98c379">13</span><span style="color:#999999">,</span> <span style="color:#98c379">15</span><span style="color:#999999">,</span>  <span style="color:#98c379">3</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span>  <span style="color:#98c379">8</span><span style="color:#999999">,</span>
              <span style="color:#98c379">2</span><span style="color:#999999">,</span>  <span style="color:#98c379">1</span><span style="color:#999999">,</span> <span style="color:#98c379">14</span><span style="color:#999999">,</span>  <span style="color:#98c379">7</span><span style="color:#999999">,</span>  <span style="color:#98c379">4</span><span style="color:#999999">,</span> <span style="color:#98c379">10</span><span style="color:#999999">,</span>  <span style="color:#98c379">8</span><span style="color:#999999">,</span> <span style="color:#98c379">13</span><span style="color:#999999">,</span> <span style="color:#98c379">15</span><span style="color:#999999">,</span> <span style="color:#98c379">12</span><span style="color:#999999">,</span>  <span style="color:#98c379">9</span><span style="color:#999999">,</span>  <span style="color:#98c379">0</span><span style="color:#999999">,</span>  <span style="color:#98c379">3</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span>  <span style="color:#98c379">6</span><span style="color:#999999">,</span> <span style="color:#98c379">11</span><span style="color:#999999">,</span>
</code></span>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39

我们把E(R0)⊕K1分成8块,每块6位,每块正好对应一个S盒置换表。例如,第一块是101000,第二块是001000,……,第八块是001110。所谓S盒置换,就是把每块6位数据的第一位和第六位组成一个二进制数,作为行号索引,第二、三、四、五位组成一个二进制数,作为列号索引。我们以第一块为例,第一块是101000,则行号为二进制数10也就是十进制的2,列号为0100也就是十进制的4。特别注意S盒置换表的行号和列号是从0开始的,故最后取值为S_table[1][2][4] = 13,换算成二进制就是1101,S盒的输出为4位。其余的数据块以此类推有(标红的数为二进制数)

区块编号区块数据S盒中的位置(二进制)S盒中的位置(十进制)S盒中的值(十进制)S盒中的值(二进制)
第一块101000S_table[1][10][0100]S_table[1][2][4]131101
第二块001000S_table[2][00][0100]S_table[2][0][4]60110
第三块010110S_table[3][00][1011]S_table[3][0][11]70111
第四块111101S_table[4][11][1110]S_table[4][3][14]20010
第五块110100S_table[5][10][1010]S_table[5][2][10]121100
第六块110010S_table[6][10][1001]S_table[6][2][9]00000
第七块100110S_table[7][10][0011]S_table[7][2][3]131101
第八块001110S_table[8][00][0111]S_table[8][0][7]10001

数据经过S盒从48位变成32位,其值为

S(E(R0)⊕K1)[32bits] = 11010110 01110010 11000000 11010001

给定P盒置换表

<span style="color:#000000"><code class="language-cpp">P_table<span style="color:#999999">[</span><span style="color:#98c379">32</span><span style="color:#999999">]</span> <span style="color:#669900">=</span> <span style="color:#98c379">16</span><span style="color:#999999">,</span>  <span style="color:#98c379">7</span><span style="color:#999999">,</span> <span style="color:#98c379">20</span><span style="color:#999999">,</span> <span style="color:#98c379">21</span><span style="color:#999999">,</span> <span style="color:#98c379">29</span><span style="color:#999999">,</span> <span style="color:#98c379">12</span><span style="color:#999999">,</span> <span style="color:#98c379">28</span><span style="color:#999999">,</span> <span style="color:#98c379">17</span><span style="color:#999999">,</span>
               <span style="color:#98c379">1</span><span style="color:#999999">,</span> <span style="color:#98c379">15</span><span style="color:#999999">,</span> <span style="color:#98c379">23</span><span style="color:#999999">,</span> <span style="color:#98c379">26</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span> <span style="color:#98c379">18</span><span style="color:#999999">,</span> <span style="color:#98c379">31</span><span style="color:#999999">,</span> <span style="color:#98c379">10</span><span style="color:#999999">,</span>
               <span style="color:#98c379">2</span><span style="color:#999999">,</span>  <span style="color:#98c379">8</span><span style="color:#999999">,</span> <span style="color:#98c379">24</span><span style="color:#999999">,</span> <span style="color:#98c379">14</span><span style="color:#999999">,</span> <span style="color:#98c379">32</span><span style="color:#999999">,</span> <span style="color:#98c379">27</span><span style="color:#999999">,</span>  <span style="color:#98c379">3</span><span style="color:#999999">,</span>  <span style="color:#98c379">9</span><span style="color:#999999">,</span>
              <span style="color:#98c379">19</span><span style="color:#999999">,</span> <span style="color:#98c379">13</span><span style="color:#999999">,</span> <span style="color:#98c379">30</span><span style="color:#999999">,</span>  <span style="color:#98c379">6</span><span style="color:#999999">,</span> <span style="color:#98c379">22</span><span style="color:#999999">,</span> <span style="color:#98c379">11</span><span style="color:#999999">,</span>  <span style="color:#98c379">4</span><span style="color:#999999">,</span> <span style="color:#98c379">25</span>
</code></span>
  • 1
  • 2
  • 3
  • 4

将S(E(R0)⊕K1)通过P盒置换得

P(S(E(R0)⊕K1))[32bits] = 01000111 11010101 10001000 00010111

之前生成的L0为

L0[32bits] = 00000000 11111111 01111000 01010101

把P(S(E(R0)⊕K1))与L0按位异或运算得到R1

R1[32bits] = L0⊕P(S(E(R0)⊕K1)) = 01000111 00101010 11110000 01000010

把上面的明文加密过程总结一下,并写成通项公式的形式有

Li=Ri−1i=1,2,…,16Ri=Li−1⊕P(S(E(Ri−1)⊕Ki))i=1,2,…,16L_{i} = R_{i-1} \quad i = 1, 2, …, 16\\R_{i} = L_{i-1}⊕P(S(E(R_{i-1})⊕K_{i})) \quad i = 1, 2, …, 16Li​=Ri−1​i=1,2,…,16Ri​=Li−1​⊕P(S(E(Ri−1​)⊕Ki​))i=1,2,…,16

其中Li[32bits],Ri[32bits],Ki[48bits]。

根据公式我们可以计算出L1, L2, …, L16和R1, R2, …, R16,即有

L0[32bits] = 00000000 11111111 01111000 01010101
R0[32bits] = 00000000 11111111 10000000 01100110
L1[32bits] = 00000000 11111111 10000000 01100110
R1[32bits] = 01000111 00101010 11110000 01000010
L2[32bits] = 01000111 00101010 11110000 01000010
R2[32bits] = 11011100 11010101 00011100 01011010
………… ………… ………… ………… ………… …………
L16[32bits] = 11001010 00001010 10010001 11010010
R16[32bits] = 01000000 00001111 00011010 10001011

给定IP-1置换表

<span style="color:#000000"><code class="language-cpp">IP1_table<span style="color:#999999">[</span><span style="color:#98c379">64</span><span style="color:#999999">]</span> <span style="color:#669900">=</span> <span style="color:#98c379">40</span><span style="color:#999999">,</span>  <span style="color:#98c379">8</span><span style="color:#999999">,</span> <span style="color:#98c379">48</span><span style="color:#999999">,</span> <span style="color:#98c379">16</span><span style="color:#999999">,</span> <span style="color:#98c379">56</span><span style="color:#999999">,</span> <span style="color:#98c379">24</span><span style="color:#999999">,</span> <span style="color:#98c379">64</span><span style="color:#999999">,</span> <span style="color:#98c379">32</span><span style="color:#999999">,</span>
                <span style="color:#98c379">39</span><span style="color:#999999">,</span>  <span style="color:#98c379">7</span><span style="color:#999999">,</span> <span style="color:#98c379">47</span><span style="color:#999999">,</span> <span style="color:#98c379">15</span><span style="color:#999999">,</span> <span style="color:#98c379">55</span><span style="color:#999999">,</span> <span style="color:#98c379">23</span><span style="color:#999999">,</span> <span style="color:#98c379">63</span><span style="color:#999999">,</span> <span style="color:#98c379">31</span><span style="color:#999999">,</span>
                <span style="color:#98c379">38</span><span style="color:#999999">,</span>  <span style="color:#98c379">6</span><span style="color:#999999">,</span> <span style="color:#98c379">46</span><span style="color:#999999">,</span> <span style="color:#98c379">14</span><span style="color:#999999">,</span> <span style="color:#98c379">54</span><span style="color:#999999">,</span> <span style="color:#98c379">22</span><span style="color:#999999">,</span> <span style="color:#98c379">62</span><span style="color:#999999">,</span> <span style="color:#98c379">30</span><span style="color:#999999">,</span>
                <span style="color:#98c379">37</span><span style="color:#999999">,</span>  <span style="color:#98c379">5</span><span style="color:#999999">,</span> <span style="color:#98c379">45</span><span style="color:#999999">,</span> <span style="color:#98c379">13</span><span style="color:#999999">,</span> <span style="color:#98c379">53</span><span style="color:#999999">,</span> <span style="color:#98c379">21</span><span style="color:#999999">,</span> <span style="color:#98c379">61</span><span style="color:#999999">,</span> <span style="color:#98c379">29</span><span style="color:#999999">,</span>
                <span style="color:#98c379">36</span><span style="color:#999999">,</span>  <span style="color:#98c379">4</span><span style="color:#999999">,</span> <span style="color:#98c379">44</span><span style="color:#999999">,</span> <span style="color:#98c379">12</span><span style="color:#999999">,</span> <span style="color:#98c379">52</span><span style="color:#999999">,</span> <span style="color:#98c379">20</span><span style="color:#999999">,</span> <span style="color:#98c379">60</span><span style="color:#999999">,</span> <span style="color:#98c379">28</span><span style="color:#999999">,</span>
                <span style="color:#98c379">35</span><span style="color:#999999">,</span>  <span style="color:#98c379">3</span><span style="color:#999999">,</span> <span style="color:#98c379">43</span><span style="color:#999999">,</span> <span style="color:#98c379">11</span><span style="color:#999999">,</span> <span style="color:#98c379">51</span><span style="color:#999999">,</span> <span style="color:#98c379">19</span><span style="color:#999999">,</span> <span style="color:#98c379">59</span><span style="color:#999999">,</span> <span style="color:#98c379">27</span><span style="color:#999999">,</span>
                <span style="color:#98c379">34</span><span style="color:#999999">,</span>  <span style="color:#98c379">2</span><span style="color:#999999">,</span> <span style="color:#98c379">42</span><span style="color:#999999">,</span> <span style="color:#98c379">10</span><span style="color:#999999">,</span> <span style="color:#98c379">50</span><span style="color:#999999">,</span> <span style="color:#98c379">18</span><span style="color:#999999">,</span> <span style="color:#98c379">58</span><span style="color:#999999">,</span> <span style="color:#98c379">26</span><span style="color:#999999">,</span>
                <span style="color:#98c379">33</span><span style="color:#999999">,</span>  <span style="color:#98c379">1</span><span style="color:#999999">,</span> <span style="color:#98c379">41</span><span style="color:#999999">,</span>  <span style="color:#98c379">9</span><span style="color:#999999">,</span> <span style="color:#98c379">49</span><span style="color:#999999">,</span> <span style="color:#98c379">17</span><span style="color:#999999">,</span> <span style="color:#98c379">57</span><span style="color:#999999">,</span> <span style="color:#98c379">25</span>
</code></span>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

将R16L16通过IP-1置换表得到最终的密文C

C[64bits] = IP-1(R16L16) = 00011001 10110111 00010000 10110101 00001110 00000000 11000010 10001011

4. 密文的解密

根据密钥的生成算法,我们仍然可以生成16个密钥K1, K2, ……, K16。现已知密文C,通过IP-1置换表我们可以反向置换出L16和R16

R16L16=IP−1−1(C)R_{16}L_{16} = IP-1^{-1}(C)R16​L16​=IP−1−1(C)

再由加密过程的通项公式,可以得到解密过程的通项公式为

Ri=Li+1i=0,1,…,15Li=Ri+1⊕P(S(E(Ri)⊕Ki+1))i=0,1,…,15R_{i} = L_{i+1} \quad i = 0, 1, …, 15\\L_{i} = R_{i+1}⊕P(S(E(R_{i})⊕K_{i+1})) \quad i = 0, 1, …, 15Ri​=Li+1​i=0,1,…,15Li​=Ri+1​⊕P(S(E(Ri​)⊕Ki+1​))i=0,1,…,15

最后得到L0和R0,通过初始置换表,我们可以反向置换出明文M

M=IP−1(L0R0)M = IP^{-1}(L_{0}R_{0})M=IP−1(L0​R0​)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值