Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.67 KB | None | 0 0
  1. <?php
  2.  
  3.     function NPHencode($strPlaintext)
  4.     {
  5.         $strPlaintextAlphaOnly = preg_replace("[\W]", "", $strPlaintext);
  6.         $strCiphertextAlphaOnly = "";
  7.         for ($i = 0; $i < strlen($strPlaintextAlphaOnly); $i += 2)
  8.         {
  9.             $strCiphertextAlphaOnly .= $strPlaintextAlphaOnly[$i];
  10.         }
  11.         $strCiphertextAlphaOnlyTail = "";
  12.         for ($i = 1; $i < strlen($strPlaintextAlphaOnly); $i += 2)
  13.         {
  14.             $strCiphertextAlphaOnlyTail = $strPlaintextAlphaOnly[$i] . $strCiphertextAlphaOnlyTail;
  15.         }
  16.         $strCiphertextAlphaOnly .= $strCiphertextAlphaOnlyTail;
  17.         $strCiphertext = "";
  18.         $padcount = 0;
  19.         for ($i = 0; $i < strlen($strPlaintext); $i++)
  20.         {
  21.             if (preg_match("[\W]", substr($strPlaintext, $i, 1)))
  22.             {
  23.                 $strCiphertext .= substr($strPlaintext, $i, 1);
  24.                 $padcount++;
  25.             }
  26.             else
  27.             {
  28.                 $strCiphertext .= substr($strCiphertextAlphaOnly, $i-$padcount, 1);
  29.             }
  30.         }
  31.         return($strCiphertext);
  32.     }
  33.    
  34.     function NPHdecode($strCiphertext)
  35.     {
  36.         $strCiphertextAlphaOnly = preg_replace("[\W]", "", $strCiphertext);
  37.         $strPlaintextAlphaOnly = "";
  38.         for ($i = 0; $i < strlen($strCiphertextAlphaOnly); $i++)
  39.         {
  40.             if (floor($i/2) == $i/2)
  41.             {
  42.                 $strPlaintextAlphaOnly .= substr($strCiphertextAlphaOnly, $i/2, 1);
  43.             }
  44.             else
  45.             {
  46.                 $strPlaintextAlphaOnly .= substr($strCiphertextAlphaOnly, floor($i/-2), 1);
  47.             }
  48.         }
  49.         $strPlaintext = "";
  50.         $padcount = 0;
  51.         for ($i = 0; $i < strlen($strCiphertext); $i++)
  52.         {
  53.             if (preg_match("[\W]", substr($strCiphertext, $i, 1)))
  54.             {
  55.                 $strPlaintext .= substr($strCiphertext, $i, 1);
  56.                 $padcount++;
  57.             }
  58.             else
  59.             {
  60.                 $strPlaintext .= substr($strPlaintextAlphaOnly, $i-$padcount, 1);
  61.             }
  62.         }
  63.         return($strPlaintext);
  64.     }
  65.  
  66. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement