下面代码是c#代码,哪位仁兄能帮忙转成flax代码(主要是解密代码的转化)。急求
//加密代码
public static string EncrypKey(string Src, string Key)
{
//int idx;
//Src = GB2312ToUTF8(Src);
if (Src == "")
{
return "";
}
int KeyLen;
int KeyPos;
int offset;
string Dest;
int SrcPos;
int SrcAsc;
int TmpSrcAsc;
//int Range;
KeyLen = Key.Length;
if (KeyLen == 0)
Key = "Think Space";
KeyPos = -1;
SrcPos = 0;
SrcAsc = 0;
//Range=256;
Random r = new Random(unchecked((int)DateTime.Now.Ticks));
offset = r.Next(0, 256);
Dest = offset.ToString("X02");
for (SrcPos = 0; SrcPos < Src.Length; SrcPos++)
{
SrcAsc = ((int)Src[SrcPos] + offset) % 255;
if (KeyPos < KeyLen - 1)
KeyPos = KeyPos + 1;
else
KeyPos = 0;
SrcAsc = SrcAsc ^ (int)Key[KeyPos];
Dest = Dest + SrcAsc.ToString("X02");
offset = SrcAsc;
}
return Dest;
}
//解密函数
public static string UncrypKey(string Src, string Key)
{
//int idx;
int KeyLen;
int KeyPos;
int offset;
string Dest = "";
int SrcPos;
int SrcAsc;
int TmpSrcAsc;
//int Range;
if (Src == "")
{
return "";
}
KeyLen = Key.Length;
if (KeyLen == 0) Key = "Think Space";
KeyPos = -1;
SrcPos = 0;
SrcAsc = 0;
//Range=256;
offset = Convert.ToInt32(Src.Substring(0, 2), 16);
SrcPos = 2;
do
{
SrcAsc = Convert.ToInt32(Src.Substring(SrcPos, 2), 16);
if (KeyPos < KeyLen - 1)
KeyPos = KeyPos + 1;
else
KeyPos = 0;
TmpSrcAsc = SrcAsc ^ (int)Key[KeyPos];
if (TmpSrcAsc <= offset)
TmpSrcAsc = 255 + TmpSrcAsc - offset;
else
TmpSrcAsc = TmpSrcAsc - offset;
Dest = Dest + (char)TmpSrcAsc;
offset = SrcAsc;
SrcPos = SrcPos + 2;
} while (SrcPos < Src.Length - 1);
return Dest;
}
[解决办法]
public static function UncrypKey(Src:String,Key:String):String
{
//int idx;
var KeyLen:int;
var KeyPos:int;
var offset:int;
var Dest:String = "";
var SrcPos:int;
var SrcAsc:int;
var TmpSrcAsc:int;
//int Range;
if (Src == "")
{
return "";
}
KeyLen = Key.length;
if (KeyLen == 0) Key = "Think Space";
KeyPos = -1;
SrcPos = 0;
//SrcAsc = 0;
//Range=256;
offset = parseInt(Src.substring(0,2),16);
SrcPos = 2;
do
{
SrcAsc = parseInt(Src.substring(SrcPos,SrcPos+2),16);
if (KeyPos < KeyLen - 1)
KeyPos = KeyPos + 1;
else
KeyPos = 0;
TmpSrcAsc = SrcAsc ^ (Key.charAt(KeyPos)).toString().charCodeAt(0);
if (TmpSrcAsc <= offset)
TmpSrcAsc = 255 + TmpSrcAsc - offset;
else
TmpSrcAsc = TmpSrcAsc - offset;
Dest = Dest + String.fromCharCode(TmpSrcAsc);
offset = SrcAsc;
SrcPos = SrcPos + 2;
} while (SrcPos < Src.length - 1);
return Dest;
}
楼主,这是转换好的,我试了可以用,你可以参考一下。