---
# System prepended metadata

title: '##Crypto'

---

### Crypto

Cho hàm mã hóa sau
```
Function Encrypt ($text, $len)
{
      $diff = 10 ;
      $ct="";
      for ($x=0 ; $x < $len; $x++)
        {
        if ($x+$diff < $len-1)
                {
                $ct.=$text[$x] ^ $text[$x+$diff];
                }
        Else
                {
                $ct.=$text[$x] ^ $text[$diff];
                }
        if ((ord($ct[$x]) % 2) == 0)
                {
                $diff++;
                }
        else
                {
                $diff--;
                }
        }
return $ct;
}
```

Cho vài ví dụ như bên dưới và đề bài là tìm cách viết hàm Decrypt hoặc đọc được nội dung thông điệp

Text #1:
  The orbits of the planets are ellipses, with the Sun at one focus of the ellipse.
Encrypted Text #1:
```
  ·--------------------------------------------------·--------------------·
  | 74 0e 11 54 0a 02 03 08 11 16 53 1c 07 41 15 09  |  t..T......S..A..  |
  | 04 45 15 09 04 0b 00 18 03 50 04 5e 12 54 45 4c  |  .E.......P.^.TEL  |
  | 04 49 50 06 45 53 0c 54 18 0c 12 0b 43 17 0b 06  |  .IP.ES.T....C...  |
  | 53 20 1a 4e 48 41 54 4c 06 1d 16 4e 03 01 02 1b  |  S .NHATL...N....  |
  | 12 4e 0a 12 53 00 1b 11 45 0b 0d 00 08 1e 16 11  |  .N..S...E.......  |
  | 4b                                               |  K                 |
  ·--------------------------------------------------·--------------------·
  ```
Decrypted Text #1:
```
  ·--------------------------------------------------·--------------------·
  | 54 68 65 20 6f 72 62 69 74 73 20 6f 66 20 74 68  |  The orbits of th  |
  | 65 20 70 6c 61 6e 65 74 73 20 61 72 65 20 65 6c  |  e planets are el  |
  | 6c 69 70 73 65 73 2c 20 77 69 74 68 20 74 68 65  |  lipses, with the  |
  | 20 53 75 6e 20 61 74 20 6f 6e 65 20 66 6f 63 75  |   Sun at one focu  |
  | 73 20 6f 66 20 74 68 65 20 65 6c 6c 69 70 73 65  |  s of the ellipse  |
  | 2e                                               |  .                 |
  ·--------------------------------------------------·--------------------·
  ```
Text #2:
  The line joining the planet to the Sun sweeps out equal areas in equal times as the planet travels around the ellipse.
Encrypted Text #2:
```
  ·--------------------------------------------------·--------------------·
  | 3b 07 0a 4e 02 49 4e 0d 48 4a 03 05 02 07 00 13  |  ;..N.IN.HJ......  |
  | 54 00 48 0d 48 50 19 14 4e 12 11 45 11 0a 53 07  |  T.H.HP..N..E..S.  |
  | 1b 16 4f 3c 01 1a 45 16 02 09 09 1c 12 45 0a 06  |  ..O<..E......E..  |
  | 1d 49 0c 51 55 41 4c 51 10 13 04 41 53 00 00 0b  |  .I.QUALQ...AS...  |
  | 45 00 51 55 41 4c 53 07 1a 19 11 07 54 04 03 50  |  E.QUALS.....T..P  |
  | 15 09 04 45 15 09 04 4e 17 06 56 18 52 13 04 10  |  ...E...N..V.R...  |
  | 08 07 54 04 17 0a 19 02 14 45 11 0d 00 4a 0a 05  |  ..T......E...J..  |
  | 03 03 50 19 45 4b                                |  ..P.EK            |
  ·--------------------------------------------------·--------------------·
  ```
Decrypted Text #2:
```
  ·--------------------------------------------------·--------------------·
  | 54 68 65 20 6c 69 6e 65 20 6a 6f 69 6e 69 6e 67  |  The line joining  |
  | 20 74 68 65 20 70 6c 61 6e 65 74 20 74 6f 20 74  |   the planet to t  |
  | 68 65 20 53 75 6e 20 73 77 65 65 70 73 20 6f 75  |  he Sun sweeps ou  |
  | 74 20 65 71 75 61 6c 20 61 72 65 61 73 20 69 6e  |  t equal areas in  |
  | 20 65 71 75 61 6c 20 74 69 6d 65 73 20 61 73 20  |   equal times as   |
  | 74 68 65 20 70 6c 61 6e 65 74 20 74 72 61 76 65  |  the planet trave  |
  | 6c 73 20 61 72 6f 75 6e 64 20 74 68 65 20 65 6c  |  ls around the el  |
  | 6c 69 70 73 65 2e                                |  lipse.            |
  ·--------------------------------------------------·--------------------·
  ```
Text #3:
  The ratio of the squares of the revolutionary periods for two planets is equal to the ratio of the cubes of their semimajor axes.
Encrypted Text #3:
```
  ·--------------------------------------------------·--------------------·
  | 3b 07 0a 00 1a 41 54 18 0e 45 0a 46 46 00 0d 00  |  ;....AT..E.FF...  |
  | 52 05 07 03 17 04 09 1f 4c 1b 12 4f 1b 07 0a 41  |  R.......L..O...A  |
  | 13 04 0f 16 1c 07 06 06 1c 08 13 00 0d 54 1f 0a  |  .............T..  |
  | 02 08 0a 17 00 49 0f 06 52 51 05 06 0e 00 1f 03  |  .....I..RQ......  |
  | 0e 1a 00 06 07 54 06 1c 00 0d 19 1d 09 04 00 01  |  .....T..........  |
  | 1a 45 11 0d 00 00 14 15 00 0c 1d 52 1c 0b 4d 19  |  .E.........R..M.  |
  | 05 08 4d 0e 1f 08 17 01 52 0e 03 45 11 0d 00 1a  |  ..M.....R..E....  |
  | 03 53 53 00 4d 0c 4d 04 4a 1c 03 53 41 1d 0d 07  |  .SS.M.M.J..SA...  |
  | 0e                                               |  .                 |
  ·--------------------------------------------------·--------------------·
  ```
Decrypted Text #3:
```
  ·--------------------------------------------------·--------------------·
  | 54 68 65 20 72 61 74 69 6f 20 6f 66 20 74 68 65  |  The ratio of the  |
  | 20 73 71 75 61 72 65 73 20 6f 66 20 74 68 65 20  |   squares of the   |
  | 72 65 76 6f 6c 75 74 69 6f 6e 61 72 79 20 70 65  |  revolutionary pe  |
  | 72 69 6f 64 73 20 66 6f 72 20 74 77 6f 20 70 6c  |  riods for two pl  |
  | 61 6e 65 74 73 20 69 73 20 65 71 75 61 6c 20 74  |  anets is equal t  |
  | 6f 20 74 68 65 20 72 61 74 69 6f 20 6f 66 20 74  |  o the ratio of t  |
  | 68 65 20 63 75 62 65 73 20 6f 66 20 74 68 65 69  |  he cubes of thei  |
  | 72 20 73 65 6d 69 6d 61 6a 6f 72 20 61 78 65 73  |  r semimajor axes  |
  | 2e                                               |  .                 |
  ·--------------------------------------------------·--------------------·
```

Thông điệp chính:
```
  ·--------------------------------------------------·--------------------·
  | 32 1a 12 18 00 0f 15 46 4e 48 21 64 5a 0b 1d 1b  |  2......FNH!dZ...  |
  | 02 5c 4f 00 02 04 56 44 54 35 3c 6e 75 34 4e 54  |  .\O...VDT5<nu4NT  |
  | 5a 00 1f 02 05 49 45 11 0d 00 07 00 11 00 0c 45  |  Z....IE........E  |
  | 6a 19 74 03 0a 04 0e 45 58 0b 47 4b 1f 03 0e 0d  |  j.t....EX.GK....  |
  | 0a 50 09 14 1d 32 45 29 5d 54 52 7b 75 75 75 7b  |  .P...2E)]TR{uuu{  |
  | 71 7b 34 06 08 46 00 1c 05 08 1d 1a 0c 4c 49 45  |  q{4..F.......LIE  |
  | 6a 5a 54 52 48 36 27 61 6d 39 25 28 36 1b 01 10  |  jZTRH6'am9%(6...  |
  | 27 2b 76 4b 57 3b 4f 4f 46 4e 4c 4b 47 22 32 30  |  '+vKW;OOFNLKG"20  |
  | 20 16 33 1f 19 01 33 03 0a 36 15 18 14 7f 43 48  |   .3...3..6...CH  |
  | 41 52 1f 33 05 02 31 1e 1c 00 07 00 11 00 0c 5d  |  AR.3..1........]  |
  | 09 03 09 0d 45 4c 1d 3a 03 09 13 49 0b 1c 00 58  |  ....EL.:...I...X  |
  | 06 4c 5a 5c                                      |  .LZ\              |
  ·--------------------------------------------------·--------------------·
  ```