加密程序

package com.cybookstore.struts.action;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.cybookstore.db.dao.User;
import com.cybookstore.db.dao.UserCart;
import com.cybookstore.db.dao.UserDAO1;
import com.cybookstore.db.dao.UserInfo;
import com.cybookstore.db.dao.UserLoginDAO;
import com.cybookstore.db.dao.UserManager;
import com.cybookstore.db.dao1.Userinfo;

/**
* MyEclipse Struts
* Creation date: 01-05-2008
*
* XDoclet definition:
* @struts.action validate="true"
* @struts.action-forward name="successfully" path="/suc.jsp"
* @struts.action-forward name="failure" path="/fail.jsp"
*/
public class LoginAction1 extends Action {
private static final Logger log = Logger.getLogger(LoginAction1.class);

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
String name=request.getParameter("textfield");
String password=request.getParameter("textfield2");
try {
String temp=new String(name.getBytes("ISO-8859-1"),"gb2312");
log.info("user: "+temp+" : "+password);
Userinfo user=new Userinfo(temp,"","","","","","");
Userinfo user2= UserDAO1.Login(user);

// UserLogin.Login(name,password);


UserInfo user1= UserManager.getUser(1);

// ArrayList ss=user1.getUserlist();
HttpSession session=request.getSession();
session.setAttribute("user", user1);


if(password!=null&&user2!=null&&!password.equals("")&&password.equals(user2.getPassword())){
UserCart c=new UserCart();
session.setAttribute("cart", c);
System.out.println(user);
return mapping.findForward("successful");
}else {
return mapping.findForward("failure");
}
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return mapping.findForward("failure");

}


}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
列置换加密是一种加密算法,它通过改变明文中的字母顺序来加密信息。下面是一个用C语言实现列置换加密程序的示例: ```c #include <stdio.h> #include <string.h> #define ROWS 4 // 列数 #define COLS 5 // 行数 void columnarTransposition(char plainText[], char key[]) { int keyLength = strlen(key); int textLength = strlen(plainText); int rows = textLength / keyLength; // 计算所需行数 // 创建一个二维数组作为加密矩阵 char matrix[ROWS][COLS]; // 将明文按照关键字进行列置换 int index = 0; for (int col = 0; col < keyLength; col++) { for (int row = 0; row < rows; row++) { matrix[row][col] = plainText[index++]; } } // 按关键字顺序输出加密矩阵 for (int i = 0; i < keyLength; i++) { int col = key[i] - '0' - 1; for (int j = 0; j < rows; j++) { printf("%c", matrix[j][col]); } } printf("\n"); } int main() { char plainText[] = "HELLOWORLD"; char key[] = "51324"; columnarTransposition(plainText, key); return 0; } ``` 在这个示例中,我们定义了一个名为columnarTransposition的函数来执行列置换加密。该函数接受两个参数:plainText表示要加密的明文,key表示列置换的关键字。 首先,我们计算所需的行数,然后创建一个二维数组作为加密矩阵。接下来,我们通过两个嵌套的循环将明文按照关键字进行列置换,并将结果存储在加密矩阵中。 最后,我们按照关键字顺序输出加密矩阵,即为加密后的密文。 在示例中,我们使用了明文"HELLOWORLD"和关键字"51324"进行加密。最终输出的密文是"EOHWDRLLLO".

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值