You are here

public function MarstonEncryption::decrypt in Ubercart 8.4

Decrypts cyphertext.

Parameters

string $key: Key used for encryption.

string $cyphertext: String containing text to be encrypted.

Return value

string Plaintext. Decrypted text.

Overrides EncryptionInterface::decrypt

File

uc_store/src/MarstonEncryption.php, line 85

Class

MarstonEncryption
Deprecated. Handles encryption of credit-card information.

Namespace

Drupal\uc_store

Code

public function decrypt($key, $cyphertext) {
  $this->errors = [];

  // Convert key into sequence of numbers.
  $fudgefactor = $this
    ->convertKey($key);
  if ($this->errors) {
    return;
  }
  if (empty($cyphertext)) {

    // Commented out to prevent errors getting logged for use cases that may
    // have variable encryption/decryption requirements.

    /* $this->errors[] = t('No value has been supplied for decryption'); */
    return;
  }
  $target = NULL;
  $factor2 = 0;
  for ($i = 0; $i < strlen($cyphertext); $i++) {
    $char2 = substr($cyphertext, $i, 1);
    $num2 = strpos(self::$scramble2, $char2);
    if ($num2 === FALSE) {
      $this->errors[] = t('Source string contains an invalid character (@char)', [
        '@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);
}