0
点赞
收藏
分享

微信扫一扫

网络:密码原理

DT_M 2022-03-12 阅读 75
java网络

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);
    }

}

举报

相关推荐

0 条评论