Verzió: 1.0.3.3 0) $nChar2 = $nChar / $nEncKey; // Convert the value to the character. $cChar2 = chr($nChar2); $cDecryptedText .= $cChar2; $nCounter += $nCharSize; }while ($nCounter <= strlen($cText)); // Clear any unwanted spaces and show the decrypted text. return trim($cDecryptedText); } //------------------------------------------------------------------------------------ // Extract the Character Size from the middle of the exncrypted text. //------------------------------------------------------------------------------------ // Parámetros //------------------------------------------------------------------------------------ // &$cText: Cadena. // &$nCharSize: Tamańo de la cadena. //------------------------------------------------------------------------------------ function Extract_Char_Size(&$cText, &$nCharSize) {// Get the half left side of the text. $nLeft = intval(strlen($cText) / 2); $cLeft = strleft($cText, $nLeft); // Get the half right side of the text. $nRight = strlen($cText) - $nLeft; $cRight = strright($cText, $nRight); // Get the key from the text. $nKeyEnc = Val(strright($cLeft, 2)); $nKeySize = Val(strleft($cRight, 2)); if ($nKeyEnc >= 5) $nCharSize = $nKeySize + $nKeyEnc; else $nCharSize = $nKeySize - $nKeyEnc; $cText = strleft($cLeft, strlen($cLeft) - 2) . strright($cRight, strlen($cRight) - 2); } //------------------------------------------------------------------------------------ // Extract the Encryption Key from the middle of the encrypted text. //------------------------------------------------------------------------------------ // Parameters //------------------------------------------------------------------------------------ // &$cText: Chain. // $nCharSize: Length of the chain. // &$nEncKey: Length of the chain encrypt. //------------------------------------------------------------------------------------ function Extract_Enc_Key(&$cText, $nCharSize, &$nEncKey) {$cEncKey = ''; // Get the real size of the text (without the previously // stored character size). $nLenght = strlen($cText) - $nCharSize; // Get the half left and half right sides of the text. $nLeft = intval($nLenght / 2); $cLeft = strleft($cText, $nLeft); $nRight = $nLenght - $nLeft; $cRight = strright($cText, $nRight); // Get the key from the text. $cEncKey = Mid($cText, $nLeft + 1, $nCharSize); // Get the numeric value of the key. $nEncKey = Val(trim($cEncKey)); // Get the real text to decrypt (left side + right side). $cText = $cLeft . $cRight; } //------------------------------------------------------------------------------------ // Just to fool people....never show the real size in the string but we need to know // what we used in order to decrypt it so we will store the both in the string but // maked. //------------------------------------------------------------------------------------ // Parameters //------------------------------------------------------------------------------------ // $nKeySize: Length of the chain encrypt. //------------------------------------------------------------------------------------ function fEncryptedKeySize($nKeySize) {$nLowerBound = 0; $nKeyEnc = intval(($nKeySize - $nLowerBound + 1) * Rnd() + $nLowerBound); if ($nKeyEnc >= 5) $nKeySize = $nKeySize - $nKeyEnc; else $nKeySize = $nKeySize + $nKeyEnc; return NumToString($nKeyEnc, 2) . NumToString($nKeySize, 2); } //------------------------------------------------------------------------------------ // Convert a number to string using a fixed size using zeros in front of the real // number to match the desired size. //------------------------------------------------------------------------------------ // Parameters //------------------------------------------------------------------------------------ // $nNumber: Chain that n Numbers contains. // $nZeros: Quantity of zeros to add to the chain. //------------------------------------------------------------------------------------ function NumToString($nNumber, $nZeros) {// Check that the zeros to fill are not smaller than the actual size. $cNumber = trim(strval($nNumber)); $nLenght = strlen($cNumber); if ($nZeros < $nLenght) $nZeros = 0; $nUpperBound = 122; $nLowerBound = 65; for($nCounter = 1; $nCounter <= ($nZeros - $nLenght); $nCounter++) {// Add a zero in front of the string until we reach the desired size. $lCreated = false; do {$nNumber = intval(($nUpperBound - $nLowerBound + 1) * Rnd() + $nLowerBound); if (($nNumber > 90) && ($nNumber < 97)) $lCreated = false; else $lCreated = true; }while ($lCreated == false); $cChar = chr($nNumber); $cNumber = $cChar . $cNumber; } // Return the resulting string. return $cNumber; } //------------------------------------------------------------------------------------ // Insert a string in the middle of another. //------------------------------------------------------------------------------------ // Parameters //------------------------------------------------------------------------------------ // &$cSourceText: Chain. // $cTextToInsert: Chain to insert inside $cSourceText. //------------------------------------------------------------------------------------ function InsertInTheMiddle(&$cSourceText, $cTextToInsert) {// Get the half left and half right sides of the text. $nLeft = intval(strlen($cSourceText) / 2); $cLeft = strleft($cSourceText, $nLeft); $nRight = strlen($cSourceText) - $nLeft; $cRight = strright($cSourceText, $nRight); // Insert cTextToString in the middle of cSourceText. $cSourceText = $cLeft . $cTextToInsert . $cRight; } //------------------------------------------------------------------------------------ // //------------------------------------------------------------------------------------ function CreateDummy() {$nUpperBound = 122; $nLowerBound = 48; for($nCounter = 1; $nCounter <= 4; $nCounter++) {$lCreated = false; do {$nDummy = intval(($nUpperBound - $nLowerBound + 1) * Rnd() + $nLowerBound); if ((($nDummy > 57) && ($nDummy < 65)) || (($nDummy > 90) && ($nDummy < 97))) $lCreated = false; else $lCreated = true; }while ($lCreated == false); $cDummy .= chr($nDummy); } return $cDummy; } ///////////////////////////////////////////////////////////////////// // Function of chain handling. // ///////////////////////////////////////////////////////////////////// //------------------------------------------------------------------------------------ // Returns a specification number of characters of the left side of a chain. //------------------------------------------------------------------------------------ // Parameters //------------------------------------------------------------------------------------ // $tmp: Chain. // $nLeft: Number of left characters to right. //------------------------------------------------------------------------------------ function strleft($tmp, $nLeft) {$len = strlen($tmp); if ($nLeft == 0) $str = ''; else if ($nLeft < $len) $str = Mid($tmp, 1, $nLeft); return $str; } //------------------------------------------------------------------------------------ // Returns a specification number of characters of the right side of a chain. //------------------------------------------------------------------------------------ // Parameters //------------------------------------------------------------------------------------ // $tmp: Chain. // $nRight: Number of right characters to left. //------------------------------------------------------------------------------------ function strright($tmp, $nRight) {$len = strlen($tmp); if ($nRight == 0) $str = ''; else if ($nRight < $len) $str = Mid($tmp, $len - $nRight + 1, $len); return $str; } //------------------------------------------------------------------------------------ // Returns a specification number of characters of a chain. //------------------------------------------------------------------------------------ // Parameters //------------------------------------------------------------------------------------ // $tmp: Chain. // $start: Starting position in the chain. // $length: Quantity of left characters to right. //------------------------------------------------------------------------------------ function Mid($tmp, $start, $length) {$str = substr($tmp, $start - 1, $length); return $str; } ///////////////////////////////////////////////////////////////////// // Functions for handling of numbers. // ///////////////////////////////////////////////////////////////////// //------------------------------------------------------------------------------------ // Generates a Random number. //------------------------------------------------------------------------------------ function Rnd() {srand(); // Initialize random-number generator. do {$tmp = abs(tan(rand())); }while (($tmp > "1") || ($tmp < "0")); $tmp = Mid($tmp, 1, 8); return $tmp; } //------------------------------------------------------------------------------------ // Takes the numbers that it is in a chain. //------------------------------------------------------------------------------------ // Parameters //------------------------------------------------------------------------------------ // $tmp: Chain. //------------------------------------------------------------------------------------ function Val($tmp) {$length = strlen($tmp); $tmp2 = 0; for ($i = 1; $i <= $length; $i++) {$tmp1 = Mid($tmp, $i, 1); if (IsNumeric($tmp1) == 1) {$tmp2 .= $tmp1;} } return intval($tmp2); } //------------------------------------------------------------------------------------ // Returns if an expression you can evaluate as a number. //------------------------------------------------------------------------------------ // Parameters //------------------------------------------------------------------------------------ // $cChar: Chain. //------------------------------------------------------------------------------------ function IsNumeric($cChar) {$tmp = ord($cChar); if (($tmp < 48) || ($tmp > 57)) $tmp = false; else $tmp = true; return $tmp; } ?>