Advertisement
iljimae

encrypt and decrypt

Jun 21st, 2015
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.30 KB | None | 0 0
  1. <?php
  2. $data = $_GET['pass'];//get password
  3. $key = '1234567890123456';
  4. function encrypt($data, $key){
  5.     return base64_encode(
  6.     mcrypt_encrypt(
  7.         MCRYPT_RIJNDAEL_128,
  8.         $key,
  9.         $data,
  10.         MCRYPT_MODE_CBC,
  11.         "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  12.     )
  13. );
  14. }
  15. function decrypt($data, $key){
  16.     $decode = base64_decode($data);
  17.     return mcrypt_decrypt(
  18.                     MCRYPT_RIJNDAEL_128,
  19.                     $key,
  20.                     $decode,
  21.                     MCRYPT_MODE_CBC,
  22.                     "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  23.             );
  24.    
  25.    
  26. }
  27. echo $encrypted = encrypt($data, $key);
  28. echo $decrypted= decrypt($encrypted, $key);
  29.  
  30. //Encoding and decoding with str_rot13()
  31. function enrot13($enrot13){
  32.     return str_rot13($enrot13);
  33. }
  34.  
  35. function derot13($derot13){ //decode
  36.     return str_rot13(str_rot13($derot13));
  37. }
  38.  
  39.  
  40. //Encode and decode with base64_encode() & base64_decode()
  41. function enbase64($enstring){
  42.     return base64_encode($enstring);
  43. }
  44.  
  45. function debase64($destring){ //decode
  46.     return base64_decode((base64_encode($destring));
  47. }
  48.  
  49. //Deflate and inflate with gzdeflate() & gzinflate()
  50. function gzinflate($string){
  51.     return gzdeflate($string);
  52. }
  53.  
  54. function gzdeflate($string){ //decode
  55.     return gzinflate($string);
  56. }
  57.  
  58. //first two functions — str_rot13() and base64_encode()
  59. function gzinflateRot13($string){
  60.     return gzdeflate($string, 9);// compression level set to 9 = maximum
  61. }
  62.  
  63. function gzdeflateRot13($string){ //decode
  64.     return gzinflate(gzdeflate($string, 9), strlen($string));// length set to same as $string
  65. }
  66.  
  67. //Combined example: gzinflate(str_rot13(base64_decode()))
  68. function allthre($string){
  69.     return eval(gzinflate(str_rot13(base64_decode($string))));
  70. }
  71. //Php url encode and decode
  72. function enUrl($string){
  73.     return urlencode($string);
  74. }
  75.  
  76. function deUrl($string){ //decode
  77.     return urldecode($string);
  78. }
  79.  
  80. //PHP string to hex and hex to string functions
  81. function strToHex($string)
  82. {
  83.     $hex='';
  84.     for ($i=0; $i < strlen($string); $i++)
  85.     {
  86.         $hex .= dechex(ord($string[$i]));
  87.     }
  88.     return $hex;
  89. }
  90.  
  91. function hexToStr($hex) //decode
  92. {
  93.     $string='';
  94.     for ($i=0; $i < strlen($hex)-1; $i+=2)
  95.     {
  96.         $string .= chr(hexdec($hex[$i].$hex[$i+1]));
  97.     }
  98.     return $string;
  99. }
  100.  
  101. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement