## Ý nghĩa của Prime Number và 1 số ưu điểm của PHP Cho hàm encrypt và decrypt như sau If you have problems understanding the code, you can take a look at http://www.php.net/[function_name]. ```php= //////////////////////////////////////////////////////////// // Encrypt // // * Param "key" is the key used to encrypt the plain text. // This key must be a number greater than 255 // // * Param "pt" is a string containing the plain text to be // encrypted // // * Return value : a number that is unique for this key and // this plain text // function Encrypt($key, $pt) { // Initialize the result to 0 $n = 0; // For each letter in the Plain Text... for ($c = 0; $c < strlen($pt); $c++) { // Add the Ascii value of the letter to the result $n = bcadd($n, ord($pt[$c])); // Multiply the result by the key $n = bcmul($n, $key); } // return the number return $n; } ``` ```php! //////////////////////////////////////////////////////////// // Decrypt // // * Param "key" is the key used to encrypt the plain text. // This key must be a number greater than 255 // // * Param "ct" is the cipher text (a number) // // * Return value : the plain text // function Decrypt($key, $ct) { // Initialize the result to empty string $res = ""; // Loop to operate while the cipher text is > 0 while($ct > 0) { // Divide the cipher text by the key $ct = bcdiv($ct, $key); // Calculate the remain of the ct divided again by the key $ch = bcmod($ct, $key); // ch is the ascii value of the ciphered letter. // As we are recovering letters starting by the end, // we have to put the letter before the accumulated result $res = chr($ch).$res; // Substract the ascii value of the letter to the cipher text $ct = bcsub($ct, $ch); } // return the text return $res; } ``` Bạn có thể tìm thấy văn bản đơn giản? Bạn không có chìa khóa, nhưng bạn biết số sau đây là kết quả của việc mã hóa văn bản thuần túy (nó là một số được chia thành bốn dòng): ``` 782586772212363902685959557860374042751869953584706056750206363299016452159315 650644107990187365869948326926898453591870593961657781932469747019998585538983 579152528018370328636323823450887383088115178235235071886526742687079246219330 073156360084235559437796081029473984222792462653421019622414706749725645350460 ``` Hint Bạn có thể giải thử thách này "bằng tay" (không cần lập trình) nếu bạn có BigNumber Calculator.