You are here

public function UbercartEncryption::decrypt in Ubercart 7.3

Decrypts cyphertext.

Parameters

$key: String key used for encryption.

$source: Cyphertext. Text string containing encrypted $source.

Return value

Plaintext. Text string to be encrypted.

File

uc_store/classes/encrypt.inc, line 44
Utility class definition.

Class

UbercartEncryption
Handles encryption of credit-card information.

Code

public function decrypt($key, $source) {
  $this->errors = array();

  // Convert key into sequence of numbers
  $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(self::$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(self::$scramble1, $num1, 1);
    $target .= $char1;
  }
  return rtrim($target);
}