Advertisement
Guest User

Untitled

a guest
May 31st, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. <?php
  2. function String2Hex($string){
  3. $hex='';
  4. for ($i=0; $i < strlen($string); $i++){
  5. $hex .= dechex(ord($string[$i]));
  6. }
  7. return $hex;
  8.  
  9. function Hex2String($hex){
  10. $string='';
  11. for ($i=0; $i < strlen($hex)-1; $i+=2){
  12. $string .= chr(hexdec($hex[$i].$hex[$i+1]));
  13. }
  14. return $string;
  15. }
  16.  
  17. function PKCS5AddPadding($input) {
  18. $pad = strlen($input) % 16;
  19. for ($i = $pad; $i < 16; $i++) {
  20. $input .= chr(16 - $pad);
  21. }
  22. return $input;
  23. }
  24. function PKCS5RemovePadding($input) {
  25. return rtrim($input, substr($input, strlen($input) - 1, 1));
  26. }
  27.  
  28. function kn_dec($ciph,$key) {
  29. $cipherText = base64_decode($ciph);
  30. $plainText = PKCS5RemovePadding(mcrypt_decrypt(MCRYPT_RIJNDAEL_128,$key, $cipherText, MCRYPT_MODE_CBC));
  31. return $plainText;
  32. }
  33.  
  34. function kn_enc($plai,$key) {
  35. $plainText = $plai;
  36. $cipherText = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, PKCS5AddPadding($plainText), MCRYPT_MODE_CBC);
  37. $cipherText = base64_encode($cipherText);
  38.  
  39. return $cipherText;
  40. }
  41.  
  42.  
  43.  
  44.  
  45. if (isset($_POST['te'])) {
  46.  
  47. die(String2Hex(kn_enc($_POST['te'],'!(*@&#^$%!&%^&*@')));
  48.  
  49. } else if (isset($_POST['td'])) {
  50. die(kn_dec(Hex2String($_POST['td']),'!(*@&#^$%!&%^&*@'));
  51. }
  52.  
  53.  
  54.  
  55. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement