关于Digital Signature的一个演示?
用Jscript写成,虽然写的时候与原来有点出入吧,但是意思应该表达出来了。
var content = "Hello world.";
var Mykeys = {
"Tom" : 4,
"John" : 8
}
var Tomskey = 22;
var Johnskey = 18;
var Transmiting = "";
var Receive = "";
document.write("<br>The content is '" + content + "'. <br><br><br>");
Transmiting = enc(Mykeys["Tom"], content);
document.write("<br>I send tom a '" + Transmiting + "'.");
Receive = dec(Tomskey, Transmiting);
document.write("<br>Tom read a '" + Receive + "'.<br>");
Transmiting = enc(Mykeys["John"], content);
document.write("<br>I send John a '" + Transmiting + "'.");
Receive = dec(Johnskey, Transmiting);
document.write("<br>John read a '" + Receive + "'.<br>");
Transmiting = enc(Tomskey, content);
document.write("<br>Tom send me a '" + Transmiting + "'.");
Receive = dec(Mykeys["Tom"], Transmiting);
document.write("<br>I read a '" + Receive + "'.<br>");
Transmiting = enc(Johnskey, content);
document.write("<br>John send me a '" + Transmiting + "'.");
Receive = dec(Mykeys["John"], Transmiting);
document.write("<br>I read a '" + Receive + "'.<br>");
function enc(key, content)
{
var theChars = content.split("");
for (var i=0;i<theChars.length;i++)
theChars[i] = String.fromCharCode(content.charCodeAt(i) + key);
return theChars.join("");
}
function dec(key, content)
{
var theChars = content.split("");
for (var i=0;i<theChars.length;i++)
theChars[i] = String.fromCharCode(content.charCodeAt(i) + key - 26);
return theChars.join("");
}