|
$ Ralphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 !,. :;?~ @ # $ % ^ & * () _ +-=] [} {/> <"'";
$ Alphabet = $ ralphabet. $ ralphabet;
Class Crypto {
Function encrypt ($ password, $ strtoencrypt ){
Global $ ralphabet;
Global $ alphabet;
For ($ I = 0; $ I <strlen ($ password); $ I ++)
{
$ Cur_ps tutorial wd_ltr = substr ($ password, $ I, 1 );
$ Pos_alpha_ary [] = substr (strstr ($ alphabet, $ cur_pswd_ltr), 0, strlen ($ ralphabet ));
}
$ I = 0;
$ N = 0;
$ Nn = strlen ($ password );
$ C = strlen ($ strtoencrypt );
While ($ I <$ c)
{
$ Encrypted_string. = substr ($ pos_alpha_ary [$ n], strpos ($ ralphabet, substr ($ strtoencrypt, $ I, 1), 1 );
$ N ++;
If ($ n = $ nn) $ n = 0;
$ I ++;
}
Return $ encrypted_string;
}
Function decrypt ($ password, $ strtodecrypt ){
Global $ ralphabet;
Global $ alphabet;
For ($ I = 0; $ I <strlen ($ password); $ I ++)
{
$ Cur_pswd_ltr = substr ($ password, $ I, 1 );
$ Pos_alpha_ary [] = substr (strstr ($ alphabet, $ cur_pswd_ltr), 0, strlen ($ ralphabet ));
}
$ I = 0;
$ N = 0;
$ Nn = strlen ($ password );
$ C = strlen ($ strtodecrypt );
While ($ I <$ c)
{
$ Decrypted_string. = substr ($ ralphabet, strpos ($ pos_alpha_ary [$ n], substr ($ strtodecrypt, $ I, 1), 1 );
$ N ++;
If ($ n = $ nn) $ n = 0;
$ I ++;
}
Return $ decrypted_string;
}
Function cryption_table ($ password ){
Global $ ralphabet;
Global $ alphabet;
For ($ I = 0; $ I <strlen ($ password); $ I ++)
{
$ Cur_pswd_ltr = substr ($ password, $ I, 1 );
$ Pos_alpha_ary [] = substr (strstr ($ alphabet, $ cur_pswd_ltr), 0, strlen ($ ralphabet ));
}
Print "<table border = 1 cellpadding =" 0 "cellspacing =" 0 "> n ";
Print "<tr> <td> </td> ";
For ($ j = 0; $ j <strlen ($ ralphabet); $ j ++)
{
Print "<td align =" center "> <font size =" 2 "face =" arial "> ". substr ($ ralphabet, $ j, 1 ). "</td> n ";
}
Print "</tr> ";
For ($ I = 0; $ I <count ($ pos_alpha_ary); $ I ++)
{
Print "<tr> <td align =" right "> <font size =" 2 "> <B> ". ($ I + 1 ). "| </B> </font> </td> ";
For ($ k = 0; $ k <strlen ($ pos_alpha_ary [$ I]); $ k ++)
{
Print "<td align =" center "> <font size =" 2 "face =" arial "> ". substr ($ pos_alpha_ary [$ I], $ k, 1 ). "</td> n ";
}
Print "</tr> ";
}
Print "</table> n ";
}
} // End class Crypto
// Example written by Macro Zeng
// The motto of the network technology supervisor: the trio must have our teacher. Http://www.111cn.net
$ Ct = new Crypto;
// $ Ct-> cryption_table ($ password );
Echo "<form action = $ PHP_SELF method = post> ";
If ($ mod = 2 ){
$ Strtodecrypt = $ ct-> encrypt ($ password, $ strtoencrypt );
Echo 'encryption String (Encrypted field ):';
Echo "<input type = text name = strtodecrypt size = 45 value = $ strtodecrypt>
";
Echo "password lock: <input type = text name = password size = 6 value = $ password> ";
Echo "<input type = submit value =" Decrypt (decryption) "> ";
}
Else {
$ Strtoencrypt = $ ct-> decrypt ($ password, $ strtodecrypt );
Echo 'string to Encrypt (the field to be encrypted ):';
Echo "<input type = text name = strtoencrypt size = 45 value = $ strtoencrypt>
";
Echo "password lock: <input type = text name = password size = 6 value = $ password> ";
Echo "<input type = submit value =" Encrypt (encrypted) "> ";
Echo "<input type = hidden name = mod value = 2> ";
}
Echo "</form> "; |