求一个可逆的加密算法

wtadminxjeri 2006-08-28 04:25:30
1 要求用java和javasrcipt两种语言同时实现(既两种语言版本的加密解密效果一致)
2 不要求特别复杂,也不要特别简单

我的邮箱 weitao6186@sina.com

得到答案即给分,谢谢
...全文
553 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
wtadminxjeri 2006-08-29
  • 打赏
  • 举报
回复
多谢

一些朋友有疑问说一样的没意义,我这不是关于数据库操作的所以不在乎
flydr 2006-08-29
  • 打赏
  • 举报
回复
板凳
lip009 2006-08-28
  • 打赏
  • 举报
回复
var s="abcd中";
//加密
var result="";
for(var i=0;i<s.length;i++){
result=result+String.fromCharCode(s.charCodeAt(i)^"t".charCodeAt(0));
}
//解密
var result1="";
for(var j=0;j<result.length;j++){
result1=result1+(String.fromCharCode(result.charCodeAt(j)^"t".charCodeAt(0)));
}
alert(result);
alert(result1);
chenggm 2006-08-28
  • 打赏
  • 举报
回复
呵呵,如果搞成JAVASCRIPT,这样的加密就形同虚设了
---------------------------------------------

你把把javascript写呵呵,如果搞成JAVASCRIPT,这样的加密就形同虚设了
---------------------------------------------

你把把javascript写在一个*.js的文件中把。然后<script src="*.js"></script>就行了把在一个*.js的文件中把。然后<script src="*.js"></script>就行了把
  • 打赏
  • 举报
回复
呵呵,如果搞成JAVASCRIPT,这样的加密就形同虚设了
Iknowurcode 2006-08-28
  • 打赏
  • 举报
回复
恩。。。那个随机产生认证码的代码不错
copying.......
puton 2006-08-28
  • 打赏
  • 举报
回复
楼上的楼上 好文啊
让我又学到了一个东西 厉害 敬仰

lip009(深蓝忧郁) 好样!
wtadminxjeri 2006-08-28
  • 打赏
  • 举报
回复
javasrcipt版本的呢?
lip009 2006-08-28
  • 打赏
  • 举报
回复
//加密
String s = new String("abcd中");
char[] a = s.toCharArray();
for (int i = 0; i < a.length; i++) {
a[i] = (char) (a[i] ^ 't');
}
String secret = new String(a);
System.out.println("密文:" + secret);
//=======================================
//解密
for (int i = 0; i < a.length; i++) {
a[i] = (char) (a[i] ^ 't');
}
String secret1 = new String(a);
System.out.println("密文:" + secret1);
wtadminxjeri 2006-08-28
  • 打赏
  • 举报
回复
只要可逆就行,大家帮忙啊
mater789 2006-08-28
  • 打赏
  • 举报
回复
des的可以吗
千里冰封820 2006-08-28
  • 打赏
  • 举报
回复
呵呵,别人要的是可逆的,你这样随机的肯定可逆不了啦
lip009 2006-08-28
  • 打赏
  • 举报
回复
我倒...发错列...汗自己一个...
lip009 2006-08-28
  • 打赏
  • 举报
回复
<%@ pagecontentType="image/jpeg" import="java.awt.*,java.awt.image.*,java.util.*,javax.imageio.*" %>
<%!
Color getRandColor(int fc,int bc){//给定范围获得随机颜色
Random random = new Random();
if(fc>255) fc=255;
if(bc>255) bc=255;
int r=fc+random.nextInt(bc-fc);
int g=fc+random.nextInt(bc-fc);
int b=fc+random.nextInt(bc-fc);
return new Color(r,g,b);
}
%>
<%
//设置页面不缓存
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);

// 在内存中创建图象
int width=60, height=20;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

// 获取图形上下文
Graphics g = image.getGraphics();

//生成随机类
Random random = new Random();

// 设定背景色
g.setColor(getRandColor(200,250));
g.fillRect(0, 0, width, height);

//设定字体
g.setFont(new Font("Comic Sans MS",Font.PLAIN,20));

//画边框
//g.setColor(new Color());
//g.drawRect(0,0,width-1,height-1);


// 随机产生155条干扰线,使图象中的认证码不易被其它程序探测到
g.setColor(getRandColor(160,200));
for (int i=0;i<155;i++)
{
int x = random.nextInt(width);
int y = random.nextInt(height);
int xl = random.nextInt(12);
int yl = random.nextInt(12);
g.drawLine(x,y,x+xl,y+yl);
}

// 取随机产生的认证码(4位数字)
String sRand="";
for (int i=0;i<4;i++){
String rand=String.valueOf(random.nextInt(10));
sRand+=rand;
// 将认证码显示到图象中
g.setColor(new Color(20+random.nextInt(110),20+random.nextInt(110),20+random.nextInt(110)));
//调用函数出来的颜色相同,可能是因为种子太接近,所以只能直接生成
g.drawString(rand,13*i+6,16);
}

// 将认证码存入SESSION
session.setAttribute("rand",sRand);

// 图象生效
g.dispose();

// 输出图象到页面
ImageIO.write(image, "JPEG", response.getOutputStream());
%>

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧