You are here

function uc_encryption_class::decrypt in Ubercart 5

Same name and namespace in other branches
  1. 6.2 uc_store/uc_store.module \uc_encryption_class::decrypt()

File

uc_store/uc_store.module, line 2676
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 decrypt($key, $source) {
  $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 decryption');
    return;
  }
  $target = NULL;
  $factor2 = 0;
  for ($i = 0; $i < strlen($source); $i++) {
    $char2 = substr($source, $i, 1);
    $num2 = strpos($this->scramble2, $char2);
    if ($num2 === FALSE) {
      $this->errors[] = t('Source string contains an invalid character (!char)', array(
        '!char' => $char2,
      ));
      return;
    }
    $adj = $this
      ->_applyFudgeFactor($fudgefactor);
    $factor1 = $factor2 + $adj;
    $num1 = $num2 - round($factor1);
    $num1 = $this
      ->_checkRange($num1);
    $factor2 = $factor1 + $num2;
    $char1 = substr($this->scramble1, $num1, 1);
    $target .= $char1;
  }
  return rtrim($target);
}