login  Naam:   Wachtwoord: 
Registreer je!
 Scripts:

Scripts > PHP > Beveiliging > Rot13 Extended

Rot13 Extended

Auteur: Button - 08 juli 2010 - 14:16 - Gekeurd door: Koen - Hits: 4109 - Aantal punten: 4.50 (1 stem)




Rot13 encryptie extended op cijfers en leestekens (je kan zelf leestekens toevoegen).
http://nl.wikipedia.org/wiki/Rot13

Code:
  1. <?php
  2. /**
  3. *@description: ROT13 algorithm to encrypt/decrypt strings with one single function
  4. */
  5.  
  6.  
  7. function rot13Modified ($str) {
  8.  
  9.  
  10. $MNLTTRASCII = 97;
  11. // min letter ascii
  12. $MXLTTRASCII = 122;
  13. // max letter ascii
  14. $MNCLTTRASCII = 65;
  15. // min capital letter ascii
  16. $MXCLTTRASCII = 90;
  17. // max capital letter ascii
  18. $MNNRASCII = 48;
  19. // min number ascii
  20. $MXNRASCII = 57;
  21. // max number ascii
  22.  
  23. $special = array();
  24. $special['@'] = "_";
  25. $special['.'] = "-";
  26. $special[' '] = "$";
  27. $special['/'] = '\\';
  28.  
  29. $new = "";
  30.  
  31. for ($i = 0; $i < strlen($str); $i++) {
  32. if (($MNNRASCII <= ord($str[$i])) && (ord($str[$i]) <= $MXNRASCII)) {
  33. // numeric
  34. $nr = ord($str[$i]) + (($MXNRASCII - $MNNRASCII + 1) / 2);
  35. // (($MXNRASCII - $MNNRASCII + 1) / 2) = half of total numbers
  36. if ($nr > $MXNRASCII) {
  37. $diff = $nr % $MXNRASCII;
  38. $nr = $MNNRASCII - 1 + $diff;
  39. }
  40. } else if (($MNLTTRASCII <= ord($str[$i])) && (ord($str[$i]) <= $MXLTTRASCII)) {
  41. // lowercase letter
  42. $nr = ord($str[$i]) + (($MXLTTRASCII - $MNLTTRASCII + 1) / 2);;
  43. if ($nr > $MXLTTRASCII) {
  44. $diff = $nr % $MXLTTRASCII;
  45. $nr = $MNLTTRASCII - 1 + $diff;
  46. }
  47. } else if (($MNCLTTRASCII <= ord($str[$i])) && (ord($str[$i]) <= $MXCLTTRASCII)) {
  48. // capital letter
  49. $nr = ord($str[$i]) + (($MXCLTTRASCII - $MNCLTTRASCII + 1) / 2);;
  50. if ($nr > $MXCLTTRASCII) {
  51. $diff = $nr % $MXCLTTRASCII;
  52. $nr = $MNCLTTRASCII - 1 + $diff;
  53. }
  54. } else if (array_key_exists($str[$i], $special)) {
  55. // maybe it exists as key in the special token array
  56. $nr = ord($special[$str[$i]]);
  57. // set the value of the key as number (ascii)
  58. } else if (in_array($str[$i], $special)) {
  59. // maybe it exists as value in the special token array - opposite of the previous else if
  60. $tmp = array_flip($special);
  61. $nr = ord($tmp[$str[$i]]);
  62. }
  63. $new .= chr($nr);
  64. }
  65.  
  66. $new = strrev($new);
  67. // reverse the string - not necessary, but this will blow their (hacking) socks off...
  68.  
  69. return $new;
  70. }
  71.  
  72.  
  73. ?>
Download code! Download code (.txt)

 Stemmen
Niet ingelogd.

 Reacties
Post een reactie
Lees de reacties (2)
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.053s