Home > Code Snippets > String encryption with password

String encryption with password

While searching for some thing, I found a string encryption code sample for Visual Basic, and I just wanted the same in php, and did a port. Just like what F. Balena has done over there, this function is also used for both, encrypt as well as decrypt.

function stringEncrypt($str$pass){
$strlen strlen($str);
$passIndex 0;
$passLen strlen($pass);
// null passwords wont encode
if(strlen($pass) == 0
    for (
$i 0$i $strlen$i++){
// get the next char in the password
$passChr ord($pass[($i $passLen)]);
// encrypt one character in the string
$str[$i] = chr(ord($str[$i]) ^ $passChr);
// modify the character in the password (avoid overflow)
$pass[($i $passLen)] = chr(($passChr 17) & 255);

Categories: Code Snippets Tags:
  1. No comments yet.
  1. No trackbacks yet.

nine + one =