secret password whatyoucansee是低级密码的3个元素
用Java实现如下:
import java.sql.SQLOutput;
import java.util.*;
public class Example8_1{
public static void main(String[] args) {
String secret;
String password;
String whatyoucansee;
EncryptAndDecrypt persion = new EncryptAndDecrypt();
Scanner read = new Scanner(System.in);
System.out.println("输入secret");
secret=read.nextLine();
System.out.println("输入密码");
password = read.nextLine();
whatyoucansee=persion.encrypt(secret,password);//加密
System.out.println(whatyoucansee);
System.out.println("输入密码");
password = read.nextLine();
secret=persion.decrypt(whatyoucansee,password);
System.out.println(secret);
}
}
class EncryptAndDecrypt{
String encrypt(String secret,String password){
char[] c=secret.toCharArray();
char[] d=password.toCharArray();
for(int i=0;i<c.length;i++){
int mima=c[i]+d[i];
c[i]=(char)mima;
}
return new String(c);
}
String decrypt(String secret,String password){
char[] c=secret.toCharArray();
char[] d=password.toCharArray();
for(int i=0;i<c.length;i++){
int mima=c[i]-d[i];
c[i]=(char)mima;
}
return new String(c);
}
}