Note that there are some explanatory texts on larger screens.

plurals
  1. POHow secure is my encrypt method?
    text
    copied!<p>So today I was doing what I sometimes do which is just program stuff for fun, and I decided to make my own encryption method. I think it's a basic stream cipher. The thing is I know next to nothing about cryptography, so I don't know how secure it is.</p> <p>Here is the method <strong>(implemented in PHP)</strong></p> <pre><code>public function encrypt($data) { $keylen = sizeof($this-&gt;key); $i=0; $current = 0; //Current offset for the cipher $ascii = utf8_decode($data); $output = ""; for ($i=0;$i&lt;strlen($ascii);$i++) { //Moves the cipher offset based on the key and the value of what is being //encrypted $current += ord($ascii[$i]) + $this-&gt;key[$i % $keylen]; $current = $current % 256; $output .= chr($this-&gt;cipher[$current]); //Moves the cipher offset to the value of the subsequent cipher key $current = $this-&gt;cipher[($current+1)%256]; } return $output; } </code></pre> <p><strong>Explanations</strong></p> <p><code>$this-&gt;cipher</code> a preshuffled array of all integer values from 0-255, each only showing once. (Effectively a one to one function, without any kind of pattern)</p> <p><code>$this-&gt;key</code> a 512 byte random key (Unlike the cipher array may contain repeated values)</p> <p>The cipher and key used for decryption must be the same as the one used for encryption obviously to retrieve the plaintext.</p> <p><strong>Decrypt method</strong></p> <pre><code>public function decrypt($data) { $keylen = sizeof($this-&gt;key); $i=0; $offset = 0; $output = ""; for ($i=0;$i&lt;strlen($data);$i++) { $current = $this-&gt;r_cipher[ord($data[$i])]; //Calculates the offset for the next iteration $next = $this-&gt;cipher[($current+1)%256]; //Subtracts the calculated offset and key value $current -= $offset + $this-&gt;key[$i % $keylen]; //Makes sure value is between 0 and 255 $current = ($current+512)%256; $output .= chr($current); $offset = $next; } return utf8_encode($output); } </code></pre> <p><code>r_cipher</code> is just the inverse function to the cipher function</p> <p><a href="http://pastebin.com/KbvHZnD1" rel="nofollow">http://pastebin.com/KbvHZnD1</a> Examples of the algorithm in use, gives the sample key and cipher as well as several examples</p>
 

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