PageRenderTime 38ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/system/library/encryption.php

https://bitbucket.org/jjasko/opencart_serbian
PHP | 47 lines | 35 code | 12 blank | 0 comment | 4 complexity | b69920de29322296604622ce582d7a2b MD5 | raw file
  1. <?php
  2. final class Encryption {
  3. private $key;
  4. function __construct($key) {
  5. $this->key = $key;
  6. }
  7. function encrypt($value) {
  8. if (!$this->key) {
  9. return $value;
  10. }
  11. $output = '';
  12. for ($i = 0; $i < strlen($value); $i++) {
  13. $char = substr($value, $i, 1);
  14. $keychar = substr($this->key, ($i % strlen($this->key)) - 1, 1);
  15. $char = chr(ord($char) + ord($keychar));
  16. $output .= $char;
  17. }
  18. return base64_encode($output);
  19. }
  20. function decrypt($value) {
  21. if (!$this->key) {
  22. return $value;
  23. }
  24. $output = '';
  25. $value = base64_decode($value);
  26. for ($i = 0; $i < strlen($value); $i++) {
  27. $char = substr($value, $i, 1);
  28. $keychar = substr($this->key, ($i % strlen($this->key)) - 1, 1);
  29. $char = chr(ord($char) - ord($keychar));
  30. $output .= $char;
  31. }
  32. return $output;
  33. }
  34. }
  35. ?>