public class Encrypt {
static char[] ec=new char[10];
static Object[] sk=new Object[10];
public Encrypt(){
}
public static Object[] Decrypt(char enc[],String scrK){
for(int i=0;i<enc.length;i++)
{
sk[i]= enc[i]-(char)(scrK.charAt(i%scrK.length()));
}
return sk;
}
public static char[] Encrypt(String enc,String scrK){
for(int i=0;i<enc.length();i++)
{
ec[i]=(char)(enc.charAt(i)+scrK.charAt(i%scrK.length()));
}
return ec;
}
public static void main(String[] args) throws Exception {
char[]ep=null;
//Encrypt ep;
Object[]cp=null;
// String mw=null;
System.out.print("请输入明文:");
String m=MyInput.readString();
System.out.print("请输入密钥:");
String k=MyInput.readString();
//for(int i=0;i<m.length();i++)
ep=Encrypt(m,k);
System.out.println(ep);
cp=Decrypt(ep,k);
System.out.print("解密密文为:"+cp);
}
|