Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function NPHencode($strPlaintext)
- {
- $strPlaintextAlphaOnly = preg_replace("[\W]", "", $strPlaintext);
- $strCiphertextAlphaOnly = "";
- for ($i = 0; $i < strlen($strPlaintextAlphaOnly); $i += 2)
- {
- $strCiphertextAlphaOnly .= $strPlaintextAlphaOnly[$i];
- }
- $strCiphertextAlphaOnlyTail = "";
- for ($i = 1; $i < strlen($strPlaintextAlphaOnly); $i += 2)
- {
- $strCiphertextAlphaOnlyTail = $strPlaintextAlphaOnly[$i] . $strCiphertextAlphaOnlyTail;
- }
- $strCiphertextAlphaOnly .= $strCiphertextAlphaOnlyTail;
- $strCiphertext = "";
- $padcount = 0;
- for ($i = 0; $i < strlen($strPlaintext); $i++)
- {
- if (preg_match("[\W]", substr($strPlaintext, $i, 1)))
- {
- $strCiphertext .= substr($strPlaintext, $i, 1);
- $padcount++;
- }
- else
- {
- $strCiphertext .= substr($strCiphertextAlphaOnly, $i-$padcount, 1);
- }
- }
- return($strCiphertext);
- }
- function NPHdecode($strCiphertext)
- {
- $strCiphertextAlphaOnly = preg_replace("[\W]", "", $strCiphertext);
- $strPlaintextAlphaOnly = "";
- for ($i = 0; $i < strlen($strCiphertextAlphaOnly); $i++)
- {
- if (floor($i/2) == $i/2)
- {
- $strPlaintextAlphaOnly .= substr($strCiphertextAlphaOnly, $i/2, 1);
- }
- else
- {
- $strPlaintextAlphaOnly .= substr($strCiphertextAlphaOnly, floor($i/-2), 1);
- }
- }
- $strPlaintext = "";
- $padcount = 0;
- for ($i = 0; $i < strlen($strCiphertext); $i++)
- {
- if (preg_match("[\W]", substr($strCiphertext, $i, 1)))
- {
- $strPlaintext .= substr($strCiphertext, $i, 1);
- $padcount++;
- }
- else
- {
- $strPlaintext .= substr($strPlaintextAlphaOnly, $i-$padcount, 1);
- }
- }
- return($strPlaintext);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement