function encrypt_encrypt_basic in Encrypt 6
Same name and namespace in other branches
- 7 includes/encrypt.encrypt.inc \encrypt_encrypt_basic()
Call back for Encrypt implementation: default
This method uses a simple encryption method of character replacement. Note that we are not using the drupal_ equivalent for strlen and substr because of issues.
1 string reference to 'encrypt_encrypt_basic'
- encrypt_encrypt_method_info in includes/
encrypt.encrypt.inc - Implementation of encrypt_method_info().
File
- includes/
encrypt.encrypt.inc, line 63 - This file holds the hook implementation for the encrypt modules
Code
function encrypt_encrypt_basic($op = 'encrypt', $text = '', $key = ENCRYPT_DEFAULT_KEY_NONE, $options = array()) {
$processed_text = '';
// Check op
if ($op == 'decrypt') {
// Decrypt
for ($i = 0; $i < strlen($text); $i++) {
$char = substr($text, $i, 1);
$keychar = substr($key, $i % strlen($key) - 1, 1);
$char = chr(ord($char) - ord($keychar));
$processed_text .= $char;
}
}
else {
// Encrypt
for ($i = 0; $i < strlen($text); $i++) {
$char = substr($text, $i, 1);
$keychar = substr($key, $i % strlen($key) - 1, 1);
$char = chr(ord($char) + ord($keychar));
$processed_text .= $char;
}
}
return $processed_text;
}