Note that there are some explanatory texts on larger screens.

plurals
  1. PORandom results in custom encryption / decryption function
    primarykey
    data
    text
    <p>Im trying to encrypt data through a custom function i created... (based on base64) The code works but to a degree... it gives random results (sometimes work and sometimes doesn't).</p> <pre><code>&lt;?php set_time_limit(0); class encryptor{ function encrypt($data){ $all = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!?@,.&amp;*()$; "; $chars = str_split($all, 1); // Split $all to array of single characters $text_chars = str_split($data, 1); // Split $data to array of single characters // Create array of unique results based on the characters from $all foreach($chars as $char){ $array[$char] = md5(uniqid(rand(), true)); } // Replace the input text with the results from $array foreach($text_chars as $text_char){ $data = str_replace($text_char,$array[$text_char], $data); } // Encode and compress $array as $solution $solution = gzcompress(base64_encode(json_encode($array)),9); // Return the encoded solution + Breaker + encoded and compressed input text return $solution."BREAKHERE".gzcompress(base64_encode($data),9); } function decrypt($data){ // Break the encrypted code to two parts $exploded = explode('BREAKHERE', $data); // Decoding the contents $contents = base64_decode(gzuncompress($exploded[1])); // Decoding solution ($array) $solves = json_decode(base64_decode(gzuncompress($exploded[0])),true); $fliped = array_flip($solves); // Replace the encrypted data with the solution foreach($solves as $solve){ $contents = str_replace($solve,$fliped[$solve], $contents); } return($contents); // Return decoded data } } $text = "11 1"; $enc = new encryptor(); $encrypted = $enc-&gt;encrypt($text); $decrypted = $enc-&gt;decrypt($encrypted); echo $decrypted; ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload