表单:
<html> <head> <title>字符加密解密</title> </head> <body> <form method="post"> 请输入你要加密的内容(仅支持小写英文和空格!!): <input type="text" name="content"> <br/> 请输入你要解密的内容(Example:TTTJJJLTJJJTTLJTLJLTJ): <input type="text" name="content2"> <br /> <input type="submit" name="submit" value="加密或解密"> <br/> <br/> </form> 这是你加密的内容: <?php require("denc.php");?> <br/> <br/> 这是你解密的内容: <?php require("benc.php");?> </body> </html>
加密:
<?php function denc($text){ $len=strlen($text); for($i=0;$i<$len;$i++){ switch($text[$i]){ case "a": echo "JJJ"; break; case "b": echo "JJL"; break; case "c": echo "JJT"; break; case "d": echo "JLJ"; break; case "e": echo "JLL"; break; case "f": echo "JLT"; break; case "g": echo "JTJ"; break; case "h": echo "JTL"; break; case "i": echo "JTT"; break; case "j": echo "LJJ"; break; case "k": echo "LJL"; break; case "l": echo "LJT"; break; case "m": echo "LLJ"; break; case "n": echo "LLL"; break; case "o": echo "LLT"; break; case "p": echo "LTJ"; break; case "q": echo "LTL"; break; case "r": echo "LTT"; break; case "s": echo "TJJ"; break; case "t": echo "TJL"; break; case "u": echo "TJT"; break; case "v": echo "TLJ"; break; case "w": echo "TLL"; break; case "x": echo "TLT"; break; case "y": echo "TTJ"; break; case "z": echo "TTL"; break; case " ": echo "TTT"; break; } } } denc($_POST["content"]); ?>
解密:
<?php function benc($text){ $len=strlen($text); for($i=0;$i<$len;$i+=3){ if($text[$i]=="J"){ if($text[$i+1]=="J"){ if($text[$i+2]=="J") echo "a"; if($text[$i+2]=="L") echo "b"; if($text[$i+2]=="T") echo "c"; } if($text[$i+1]=="L"){ if($text[$i+2]=="J") echo "d"; if($text[$i+2]=="L") echo "e"; if($text[$i+2]=="T") echo "f"; } if($text[$i+1]=="T"){ if($text[$i+2]=="J") echo "g"; if($text[$i+2]=="L") echo "h"; if($text[$i+2]=="T") echo "i"; } } if($text[$i]=="L"){ if($text[$i+1]=="J"){ if($text[$i+2]=="J") echo "j"; if($text[$i+2]=="L") echo "k"; if($text[$i+2]=="T") echo "l"; } if($text[$i+1]=="L"){ if($text[$i+2]=="J") echo "m"; if($text[$i+2]=="L") echo "n"; if($text[$i+2]=="T") echo "o"; } if($text[$i+1]=="T"){ if($text[$i+2]=="J") echo "p"; if($text[$i+2]=="L") echo "q"; if($text[$i+2]=="T") echo "r"; } } if($text[$i]=="T"){ if($text[$i+1]=="J"){ if($text[$i+2]=="J") echo "s"; if($text[$i+2]=="L") echo "t"; if($text[$i+2]=="T") echo "u"; } if($text[$i+1]=="L"){ if($text[$i+2]=="J") echo "v"; if($text[$i+2]=="L") echo "w"; if($text[$i+2]=="T") echo "x"; } if($text[$i+1]=="T"){ if($text[$i+2]=="J") echo "y"; if($text[$i+2]=="L") echo "z"; if($text[$i+2]=="T") echo " "; } } } } benc($_POST["content2"]); ?>