Let’s start with the actual PHP function:

1. function XOREncryption($InputString, $KeyPhrase){

2.   

3.     $KeyPhraseLength = strlen($KeyPhrase);

4.   

5.     // Loop trough input string

6.     for ($i = 0; $i //SALT

$salt = ‘my_special_phrase’;

//ENCRYPT

$crypted = base64_encode(XOREncryption(‘my string’, $salt));

echo “Encrypted: ” . $crypted . “
“;

 The variable ‘ $salt ‘ plays a crucial role here.  It is essentially the ‘key’ to your encrypted string. The salt value will always generate the same values when the same mathematics are applied to it.  It provides the constant needed to generate randomness.  This goes to say that if someone uses the salt that was used to generate the encryption and applies the same mathematics they can undo or reverse the encrypted string back into the original string text.

In order to decrypt an encrypted string that was generated by using this function use the invoccation code below:

//SALT

$salt = ‘my_special_phrase’;

//DECRYPT

$decrypted  = XOREncryption(base64_decode($crypted), $salt);

echo “Decrypted: ” . $decrypted;

As long as I use the same salt I can reverse an encrypted string that was encrypted with this function.


Source by Ryan Huff

Share Article:

Leave a Reply

Unlock the Power of SEO with the Top SEO Service Provider in Sri Lanka. Our experts deliver tailored strategies for businesses to soar higher in search rankings and dominate the online competition.

©2018 Shen e-Services (Pvt) Ltd. All Rights Reserved. SEO Services

Check The Feedback