function uc_encryption_class::encrypt in Ubercart 5
Same name and namespace in other branches
- 6.2 uc_store/uc_store.module \uc_encryption_class::encrypt()
File
- uc_store/
uc_store.module, line 2715 - Contains global Ubercart functions and store administration functionality.
Class
- uc_encryption_class
- Trimmed down version of GPL class by Tony Marston. Details available at http://www.tonymarston.co.uk/php-mysql/encryption.html
Code
function encrypt($key, $source, $sourcelen = 0) {
$this->errors = array();
$fudgefactor = $this
->_convertKey($key);
if ($this->errors) {
return;
}
if (empty($source)) {
// Commented out to prevent errors getting logged for use cases that may
// have variable encryption/decryption requirements. -RS
// $this->errors[] = t('No value has been supplied for encryption');
return;
}
while (strlen($source) < $sourcelen) {
$source .= ' ';
}
$target = NULL;
$factor2 = 0;
for ($i = 0; $i < strlen($source); $i++) {
$char1 = substr($source, $i, 1);
$num1 = strpos($this->scramble1, $char1);
if ($num1 === FALSE) {
$this->errors[] = t('Source string contains an invalid character (!char)', array(
'!char' => $char1,
));
return;
}
$adj = $this
->_applyFudgeFactor($fudgefactor);
$factor1 = $factor2 + $adj;
$num2 = round($factor1) + $num1;
$num2 = $this
->_checkRange($num2);
$factor2 = $factor1 + $num2;
$char2 = substr($this->scramble2, $num2, 1);
$target .= $char2;
}
return $target;
}