private var loader:URLLoader;
...
private function init():void
{
loader = new URLLoader;
req=URLRequest = new URLRequest("1.txt");
//req.dataFormat = URLLoaderDataFormat.BINARY;
loader.load(req);
loader.addEventListener(Event.COMPLETE,oncomlete);
}
private function save(bt:ByteArray):void
{
var fr:FileReference = new fileReference;
fr.save(bt,"2.txt");
}
private function oncomplete(e:Event):void
{
if(true)
{
var str:String=loader.data;
trace("src///////");
trace(str);
str=secret(str);
var bt:ByteArray = new ByteArray;
bt.writeUTFBytes(str);
bt.compress();
}
else
{
var bt:ByteArray=loader.data;
bt.uncompress();
str=bt.readUTFButes(bt.length);
str=unsecret(str);
trace("unsecret//////////////\n"+str)
}
}
private var add_key:Array=[800,650,400,525,100,250]//间距大于122(z的unicode值)
private var range:Array=[65,91,97,123]//65,70,75,91,97,100,123
private var xor_key:Array=[0xaa,0xbb]
private var pos_key:Array=[8,4]//
private function secret(src:String):String
{
var res:String="";
var i:int,len:int,unicode:int;
len=src.length
for(i=0;i<len;i++)
{
unicode=str.charCodeAt(i);
var idx=index(unicode);
res+=String.fromCharCode(xor(add_key[idx]+unicode+random(i)))
}
res=pos(res);
return res;
}
i
private function xor(v:int):int
{
var i:int,len:int;
len=xor_key.length
for(i=0;i<len;i++)
{
v^=xor_key[i];
}
return v;
}
private function random(i:int):int
{
swicth(i%4)
{
case 0:
if(i%9==0)
return((1-Math.sin(i))*(i%100)>>0);
else
return((1-Math.sin(i))*(i%200)>>0);
case 1:
return ((1-Math.cos(i))*(i%300)>>0);
case 2:
return ((1-Math.cos(i)*Math.sin(i))*(i%400)>>0);
case 3
if(i%3==0)
return((1-Math.sin(i)*Math.cos(i)*Math.cos(i))*(i%500)>>0);
else
return((1-Math.sin(i)*Math.cos(i)*Math.cos(i))*(i%600)>>0);
}
return 1;
}
private function index(u:int):int
{
if(u>64&&u<91||u>96&&u<123)
{
var i:int,len:int;
len=range.length-1;
for(i=0;i<len;i++)
{
if(u>=range[i]&&u<range[i+1])
break;
}
return i
}
else
return 5
}
private function index2(u:int):int
{
var i:int,len:int;
len=add_key.length-1;
for(i=0;i<len;i++)
{
if(u>=add_key[i]&&u<=add_key[i]+123)
break;
}
return u-add_key[i];
}
private function unsecret(src:String):String
{
src=unpos(src);
var res:String="";
var i:int,len:int;
var u:int;
len=src.length;
for(i=0;i<len;i++)
{
u=xor(src.charCodeAt(i)-random(i));
u=index2(u);
res+=String.formCharCode(u);
}
return res;
}
private function pos(src:String):String
{
var i,j,k,len,len1,n;
var res:String;
len = pos_key.length;
len1=src.length;
for(i,len)
{
src=res||src;
res="";
for(j,pos_key[i])
{
n=len1%pos_key[i];
if(n>0)
n=pos_key[i]-n;
while(n--)
src+='#';
len1=src.length;
k=j;
while(k<len1)
{
res+=src.charAt(k);
k+=pos_key[i]
}
}
}
return res;
}
private function unpos(src:String):String
{
var i,j,k,len,len1,n;
var res:String;
len = pos_key.length;
len1=src.length;
for(i,len)
{
dis=Math.ceil(len1/pos_key[i]);
src=res||src;
res="";
for(j,dis)
{
k=j;
while(k<len1)
{
res+=src.charAt(k)
k+=dis;
}
}
}
return res;
}