一个不错的javascript加密解密算法源码
作者:aasvvv 来源:51js 时间:2010-03-28 13:12:00
来炫耀一下,谁看得懂我写的加密算法
写了一整天了,这个代码用于ajax提交,要求就是加密后内容不能变得过长,加密解密需要效率高,至于安全性,被抓取的数据无法被破解就可以了,下面的f23.ts可以算是密钥。现在有点不如意的地方就是英文内容加密后,数据长度增加一倍,中文加密不会增加数据长度,对于ajax提交,其实中文字符长度是大大减少了。
对应的服务器端c#版本,15000字加密再解密不用1毫秒。
//网站提交数据专用
public static string s52s = "8ABC7DLO5MN6Z9EFGdeJfghijkHIVrstuvwWSTUXYabclmnopqKPQRxyz01234";
static bool s52t = true;
static int N, N2;
static int[] s52r = new int[128];
static void s52f()
{
N = s52s.Length;
N2 = N * N;
for (var x = 0; x < s52s.Length; x++)
{
s52r[(int)s52s[x]] = x;
}
s52t = false;
}
public static string s52e(string n)
{
if (s52t) s52f();
int l = n.Length, a, x = 0;
List<char> t = new List<char>(l * 3);
for (; x < l; x++)
{
a = (int)n[x];
if (a < N2)
{
t.Add(s52s[a / N]);
t.Add(s52s[a % N]);
}
else
{
t.Add(s52s[a / N2 + 5]);
t.Add(s52s[(a / N) % N]);
t.Add(s52s[a % N]);
}
}
string s = new string(t.ToArray());
return s.Length.ToString().Length + s.Length.ToString() + s;
}
public static string s52d(string n)
{
if (s52t) s52f();
int c;
if (!int.TryParse(n[0].ToString(), out c)) return "";
if (!int.TryParse(n.Substring(1, c), out c)) return "";
int x = c.ToString().Length + 1;
if (n.Length != c + x) return "";
int nl = n.Length, a;
List<char> t = new List<char>(nl * 3);
for (; x < nl; x++)
{
a = s52r[(int)n[x]];
x++;
if (a < 5)
{
c = a * N + s52r[(int)n[x]];
}
else
{
c = (a - 5) * N2 + s52r[(int)n[x]] * N;
x++;
c += s52r[(int)n[x]];
}
t.Add((char)c);
}
return new string(t.ToArray());
}
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
详解Windows下PyCharm安装Numpy包及无法安装问题解决方案
![](https://img.aspxhome.com/file/2023/3/99183_0s.png)
Python 生成VOC格式的标签实例
浅析Python 中整型对象存储的位置
VSCode如何巧用正则表达式快速处理字符段
![](https://img.aspxhome.com/file/2023/3/132413_0s.jpg)
基于python的BP神经网络及异或实现过程解析
![](https://img.aspxhome.com/file/2023/8/72778_0s.jpg)
php注册和登录界面的实现案例(推荐)
python单向循环链表实例详解
python MNIST手写识别数据调用API的方法
![](https://img.aspxhome.com/file/2023/2/95592_0s.png)
TIOBE编程语言排行榜前20的语言入门书籍推荐
![](https://img.aspxhome.com/file/2023/0/131860_0s.jpg)
select * from sp_who的解决方案
face_recognition库在python的安装
一文带你吃透Golang中的类型转换
利用PyQt5模拟实现网页鼠标移动特效
![](https://img.aspxhome.com/file/2023/9/92009_0s.png)
基于Python编写一个ISBN查询工具
![](https://img.aspxhome.com/file/2023/3/83773_0s.png)
Flask response响应的具体使用
![](https://img.aspxhome.com/file/2023/0/107530_0s.png)
go install和go get的区别实例详解
(X)HTML的文档结构
![](https://img.aspxhome.com/file/UploadPic/20086/30/200863012361172s.png)