mjc 发表于 2007-4-27 11:31:42

***综合类***文本加密 可自定加密code和校验码

把下列代码加到网页的<body></body>标签之间 从google下载我的照片管理软件
要完成此效果需要两个步骤

第一步:把如下代码加入到<head>区域中

<script language="javascript">
<!-- begin
function dosecure() {
alert( 'javascript 1.2 or above required.' );
}
function dounsecure() {
alert( 'javascript 1.2 or above required.' );
}
// end -->
</script>
<script language="javascript1.2">
<!-- begin
function permutationgenerator(nnumelements) {
this.nnumelements   = nnumelements;
this.antranspositions = new array;
var k = 0;
for (i = 0; i < nnumelements - 1; i++)
for (j = i + 1; j < nnumelements; j++)
this.antranspositions[ k++ ] = ( i << 8 ) | j;
// keep two positions as lo and hi byte!
this.nnumtranspositions = k;
this.fromcycle = permutationgenerator_fromcycle;
}
function permutationgenerator_fromcycle(ancycle) {
var anpermutation = new array(this.nnumelements);
for (var i = 0; i < this.nnumelements; i++) anpermutation = i;
for (var i = 0; i < ancycle.length; i++) {
var nt = this.antranspositions];
var n1 = nt & 255;
var n2 = (nt >> 8) & 255;
nt = anpermutation;
anpermutation = anpermutation;
anpermutation = nt;
}
return anpermutation;
}
function password(strpasswd) {
this.strpasswd = strpasswd;
this.gethashvalue   = password_gethashvalue;
this.getpermutation = password_getpermutation;
}
function password_gethashvalue() {
var m = 907633409;
var a = 65599;
var h = 0;
for (var i = 0; i < this.strpasswd.length; i++)
h = (h % m) * a + this.strpasswd.charcodeat(i);
return h;
}
function password_getpermutation() {
var nnumelements = 13;
var ncyclelength = 21;
pg = new permutationgenerator(nnumelements);
var ancycle = new array(ncyclelength);
var npred   = this.gethashvalue();
for (var i = 0; i < ncyclelength; i++) {
npred = 314159269 * npred + 907633409;
ancycle = npred % pg.nnumtranspositions;
}
return pg.fromcycle(ancycle);
}
function securecontext(strtext, strsignature, bescape) {
this.strsignature = strsignature || '';
this.bescape      = bescape || false;
this.strtext = strtext;
this.escape      = securecontext_escape;
this.unescape      = securecontext_unescape;
this.transliterate = securecontext_transliterate;
this.encypher      = securecontext_encypher;
this.decypher      = securecontext_decypher;
this.sign          = securecontext_sign;
this.unsign      = securecontext_unsign;
this.secure   = securecontext_secure;
this.unsecure = securecontext_unsecure;
}
function securecontext_escape(strtoescape) {
var strescaped = '';
for (var i = 0; i < strtoescape.length; i++) {
var cht = strtoescape.charat( i );
switch(cht) {
case '\r': strescaped += '\\r'; break;
case '\n': strescaped += '\\n'; break;
case '\\': strescaped += '\\\\'; break;
default: strescaped += cht;
   }
}
return strescaped;
}
function securecontext_unescape(strtounescape) {
var strunescaped = '';
var i = 0;
while (i < strtounescape.length) {
var cht = strtounescape.charat(i++);
if ('\\' == cht) {
cht = strtounescape.charat( i++ );
switch( cht ) {
case 'r': strunescaped += '\r'; break;
case 'n': strunescaped += '\n'; break;
case '\\': strunescaped += '\\'; break;
default: // not possible
   }
}
else strunescaped += cht;
}
return strunescaped;
}
function securecontext_transliterate(btransliterate) {
var strdest = '';

var ntextiter= 0;
var ntexttrail = 0;

while (ntextiter < this.strtext.length) {
var strrun = '';
var cskipped   = 0;
while (cskipped < 7 && ntextiter < this.strtext.length) {
var cht = this.strtext.charat(ntextiter++);
if (-1 == strrun.indexof(cht)) {
strrun += cht;
cskipped = 0;
}
else cskipped++;
}
while (ntexttrail < ntextiter) {
var nrunidx = strrun.indexof(this.strtext.charat(ntexttrail++));
if (btransliterate) {
nrunidx++
if (nrunidx == strrun.length) nrunidx = 0;
}
else {
nrunidx--;
if (nrunidx == -1) nrunidx += strrun.length;
}
strdest += strrun.charat(nrunidx);
   }
}
this.strtext = strdest;
}
function securecontext_encypher(anperm) {
var strencyph = '';
var ncols   = anperm.length;
var nrows   = this.strtext.length / ncols;
for (var i = 0; i < ncols; i++) {
var k = anperm[ i ];
for (var j = 0; j < nrows; j++) {
strencyph += this.strtext.charat(k);
k         += ncols;
   }
}
this.strtext = strencyph;
}
function securecontext_decypher(anperm) {
var nrows    = anperm.length;
var ncols    = this.strtext.length / nrows;
var anrowofs = new array;
for (var i = 0 ; i < nrows; i++) anrowofs[ anperm[ i ] ] = i * ncols;
var strplain = '';
for (var i = 0; i < ncols; i++) {
for (var j = 0; j < nrows; j++)
strplain += this.strtext.charat(anrowofs[ j ] + i);
}
this.strtext = strplain;
}
function securecontext_sign(ncols) {
if (this.bescape) {
this.strtext      = this.escape(this.strtext);
this.strsignature = this.escape(this.strsignature);
}
var ntextlen   = this.strtext.length + this.strsignature.length;
var nmissingcols = ncols - (ntextlen % ncols);
var strpadding   = '';
if (nmissingcols < ncols)
for (var i = 0; i < nmissingcols; i++) strpadding += ' ';
var x = this.strtext.length;
this.strtext +=strpadding + this.strsignature;
}
function securecontext_unsign(ncols) {
if (this.bescape) {
this.strtext      = this.unescape(this.strtext);
this.strsignature = this.unescape(this.strsignature);
}
if ('' == this.strsignature) return true;
var ntextlen = this.strtext.lastindexof(this.strsignature);
if (-1 == ntextlen) return false;
this.strtext = this.strtext.substr(0, ntextlen);
return true;
}
function securecontext_secure(strpasswd) {
var passwd = new password(strpasswd);
var anperm   = passwd.getpermutation()
this.sign(anperm.length);
this.transliterate(true);

this.encypher(anperm);
}
function securecontext_unsecure(strpasswd) {
var passwd = new password(strpasswd);
var anperm = passwd.getpermutation()
this.decypher(anperm);
this.transliterate(false);
return this.unsign(anperm.length);
}
// end -->
</script>

<script language="javascript1.2">
<!-- begin
function dosecure() {
var sc = new securecontext(document.frmsecurity.txtunsecure.value,
document.frmsecurity.txtsign.value, document.frmsecurity.chknewlines.checked);
sc.secure(document.frmsecurity.txtpassw.value);
document.frmsecurity.txtsecure.value = sc.strtext;
document.frmsecurity.txtunsecure.value = '';
}
function dounsecure() {
var sc = new securecontext(document.frmsecurity.txtsecure.value,
document.frmsecurity.txtsign.value, document.frmsecurity.chknewlines.checked);
if (!sc.unsecure(document.frmsecurity.txtpassw.value))
alert('invalid password used.');
document.frmsecurity.txtsecure.value = '';
document.frmsecurity.txtunsecure.value = sc.strtext;
}
//end -->
</script>


第二步:把如下代码加入到<body>区域中

<center>
<table border=1 width="571">
    <tr>
<td>
<form name=frmsecurity>
          <p>密码:
            <input type=text name=txtpassw size=20 value="typhoon">
            可选的加密签名:
            <input type=text name=txtsign size=20><br>
<input type=checkbox name=chknewlines value="1">
            新算法</p>
<table border=0>
<tr>
<td>
                <p align="center">待加密文本:</p>
            </td>
<td></td>
<td>
                <p align="center">加密后文本:</p>
            </td>
</tr>
<tr>
<td>
                <textarea rows=4 name=txtunsecure cols=20 wrap=virtual>typhoon start javascript fairyland


      










--------------------------------------

拥有三人行论坛管理系列软件,一个人就可以管理一个论坛的更新维护。还能使您的论坛有千人在线的真实火暴效果,让您不在为论坛因没有人气而留不住会员而烦恼,使您的论坛早日成为一流的论坛。详情请登陆网站:http://www.cnsrx.cn 三人行论坛管理软件,站长必备的专业好工具。(您使用的是免费版本,购买收费版本后,将不带广告。业务QQ:247216 44985227)
页: [1]
查看完整版本: ***综合类***文本加密 可自定加密code和校验码