复制代码代码如下:
<! Doctype html public "- // w3c // dtd xhtml 1.0 transitional // en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<adal>
<meta http-equiv = "content-type" content = "text / html; charset = gb2312" />
<Title> 字符串加密 </TITAL>
</ head>
<body>
<Script linguisse = "javascript">
<! - commencer
fonction crypt (str, pwd) {
if (pwd == null || pwd.length <= 0) {
alert ("Veuillez saisir un mot de passe avec lequel crypter le message.");
retourner null;
}
var prand = "";
pour (var i = 0; i <pwd.length; i ++) {
prand + = pwd.charcodeat (i) .toString ();
}
var spos = math.floor (prand.length / 5);
var mul = paSeInt (prand.charat (spos) + prand.charat (spos * 2) + prand.charat (SPOS * 3) + prand.charat (spos * 4) + prand.charat (spos * 5));
var incr = math.ceil (pwd.length / 2);
var modu = math.pow (2, 31) - 1;
if (mul <2) {
alert ("L'algorithme ne peut pas trouver de hachage approprié. Veuillez choisir un mot de passe différent. / NPOSSIBLE Les considérations sont de choisir un mot de passe plus complexe ou plus long.");
retourner null;
}
var sel = math.round (math.random () * 1000000000)% 100000000;
prand + = sel;
while (prand.length> 10) {
Prand = (parseInt (prand.substring (0, 10)) + paSeInt (prand.substring (10, prand.length))). toString ();
}
Prand = (Mult * prand + infr)% modu;
var enc_chr = "";
var enc_str = "";
pour (var i = 0; i <str.length; i ++) {
ENC_CHR = PARSEIINT (Str.CharCodeat (i) ^ Math.Floor ((Prand / Modu) * 255));
if (enc_chr <16) {
ENC_STR + = "0" + ENC_CHR.TOSTRING (16);
} else enc_str + = enc_chr.ToString (16);
Prand = (Mult * prand + infr)% modu;
}
sel = sel.tostring (16);
tandis que (sali.lengle <8) sel = "0" + sel;
ENC_STR + = SALT;
return enc_str;
}
Fonction Decrypt (str, pwd) {
if (str == null || str.length <8) {
alerte ("Une valeur de sel n'a pas pu être extraite du message crypté car sa longueur est trop courte. Le message ne peut pas être décrypté.");
retour;
}
if (pwd == null || pwd.length <= 0) {
alert ("Veuillez saisir un mot de passe avec lequel décrypter le message.");
retour;
}
var prand = "";
pour (var i = 0; i <pwd.length; i ++) {
prand + = pwd.charcodeat (i) .toString ();
}
var spos = math.floor (prand.length / 5);
var mul = paSeInt (prand.charat (spos) + prand.charat (spos * 2) + prand.charat (SPOS * 3) + prand.charat (spos * 4) + prand.charat (spos * 5));
var incr = math.round (pwd.length / 2);
var modu = math.pow (2, 31) - 1;
Var Salt = ParseInt (Str.Substring (str.length - 8, str.length), 16);
str = str.substring (0, str.length - 8);
prand + = sel;
while (prand.length> 10) {
Prand = (parseInt (prand.substring (0, 10)) + parseInt (prand.substring (10, prand.length))). toString ();
}
Prand = (Mult * prand + infr)% modu;
var enc_chr = "";
var enc_str = "";
pour (var i = 0; i <str.length; i + = 2) {
ENC_CHR = PARSEIINT (PARSEINT (Str.Substring (I, I + 2), 16) ^ Math.floor ((Prand / Modu) * 255));
ENC_STR + = String.FromCharcode (ENC_CHR);
Prand = (Mult * prand + infr)% modu;
}
return enc_str;
}
// fin ->
</cript>
<form n name = "box"> <centre>
<Table CellPadding = 0 CellSpacing = 0 Border = 0> <Tr> <td Colspan = 3>
<TextArea Cols = 40 Rows = 5 Wrap = Virtual Name = IPT> Bienvenue sur baidu.com </ textarea>
</td> </tr>
<tr height = 50> <td valign = "top">
<input type = "bouton" onclick = "document.box.opt.value = encrypt (document.box.ipt.value, document.box.pwd.value);" valeur = "加密">
</td> <td align = "Center" valign = "Center">
<input type = "text" name = "pwd" value = "mot de passe">
</td> <td align = "droit" valign = "inférieur">
<entrée type = "bouton" onclick = "document.box.ipt.value = decrypt (document.box.opt.value, document.box.pwd.value);" valeur = "解密">
</td> </tr>
<tr> <td colspan = 3>
<TextArea Cols = 40 Rows = 5 Wrap = Virtual Name = Opt> </ TextArea>
</td> </tr> </ table>
</ Center>
</ form>
</docy>
</html>
代码 Copier 之后直接打开即可