PageRenderTime 62ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/site/helpers/encryption.php

https://github.com/hjoelr/com_simpledownload
PHP | 82 lines | 46 code | 9 blank | 27 comment | 20 complexity | e473a160d4c3632aeff38b4f94d53554 MD5 | raw file
  1. <?php
  2. /**
  3. * SimpleDownload default encryption functions. These are really only intended
  4. * for educational purposes and for areas where security is not highly important.
  5. *
  6. * @package Joomla.Joelrowley.Com
  7. * @subpackage Components
  8. * @link http://joomla.joelrowley.com/
  9. * @license GNU/GPL
  10. */
  11. // no direct access
  12. defined('_JEXEC') or die('Restricted access');
  13. function jcrypt($str, $offset=3) {
  14. $max = strlen($str);
  15. for($i = 0; $i < $max; $i++){
  16. //if the letter is upper case, keep it uppercase
  17. if(ord($str[$i]) >= 65 && ord($str[$i]) <= 90){
  18. if((ord($str[$i])+$offset) > 90) {
  19. $crypt .= chr(65+((ord($str[$i])+$offset)-91));
  20. } else if((ord($str[$i])+$offset) < 65) {
  21. $crypt .= chr(90+((ord($str[$i])+$offset)-64));
  22. } else {
  23. $crypt .= chr(ord($str[$i])+$offset);
  24. }
  25. }
  26. //if the letter is lower case, keep it lower case
  27. else if(ord($str[$i]) >= 97 && ord($str[$i]) <= 122){
  28. if((ord($str[$i])+$offset) > 122) {
  29. $crypt .= chr(97+((ord($str[$i])+$offset)-123));
  30. } else if((ord($str[$i])+$offset) < 97) {
  31. $crypt .= chr(122+((ord($str[$i])+$offset)-96));
  32. } else {
  33. $crypt .= chr(ord($str[$i])+$offset);
  34. }
  35. }
  36. else if(ord($str[$i]) >= 48 && ord($str[$i]) <= 57){
  37. if((ord($str[$i])+$offset) > 57) {
  38. $crypt .= chr(48+((ord($str[$i])+$offset)-58));
  39. } else {
  40. $crypt .= chr(ord($str[$i])+$offset);
  41. }
  42. }
  43. else {
  44. $crypt .= chr(ord($str[$i])+$offset);
  45. // in case of path separator
  46. /*if (ord($str[$i]) == 47) {
  47. $crypt .= '#';
  48. // in case of period
  49. } else if (ord($str[$i]) == 46) {
  50. $crypt .= '*';
  51. // in case of dash (-)
  52. } else if (ord($str[$i]) == 45) {
  53. $crypt .= '!';
  54. } else {
  55. echo "<- " . $i . " - " . ord($str[$i]) . " ->";
  56. }*/
  57. //die("You can only use letters.");
  58. //$crypt .= chr(ord($str[$i])+$offset);
  59. }
  60. }
  61. //$crypt = strtoupper($crypt);
  62. return $crypt;
  63. }
  64. function jdecrypt($str) {
  65. return jcrypt($str, -3);
  66. }
  67. function jcrypt64($str) {
  68. return base64_encode($str);
  69. }
  70. function jdecrypt64($str) {
  71. return base64_decode($str);
  72. }
  73. ?>