You are here

function encrypt_encryption_methods_basic in Encrypt 7.2

Same name and namespace in other branches
  1. 7.3 plugins/encryption_methods/default.inc \encrypt_encryption_methods_basic()

Callback for Encrypt implementation: default.

This method uses a simple encryption method of character replacement.

1 string reference to 'encrypt_encryption_methods_basic'
encrypt_default_encrypt_encryption_methods in plugins/encryption_methods/default.inc
Implements MODULE_FILENAME_encrypt_encryption_methods().

File

plugins/encryption_methods/default.inc, line 29

Code

function encrypt_encryption_methods_basic($op, $text, $key, $options = array()) {
  $processed_text = '';

  // Caching length operations to speed up for loops.
  $text_length = strlen($text);
  $key_length = strlen($key);

  // Loop through each character.
  for ($i = 0; $i < $text_length; $i++) {
    $char = substr($text, $i, 1);
    $keychar = substr($key, $i % $key_length - 1, 1);

    // Encrypt or decrypt the character.
    if ($op == 'decrypt') {
      $char = chr(ord($char) - ord($keychar));
    }
    else {
      $char = chr(ord($char) + ord($keychar));
    }
    $processed_text .= $char;
  }
  return $processed_text;
}