Java仿射密码源码

仿射密码Java源码
/*
仿射密码
 */
import java.util.Scanner;

public class AffineCipher1 {
    //定义全局变量
    public static int x;  //k1的逆元
    public static int y;

    //目标:设计仿射密码,进行加解密(2023/5/23)
    public static void main(String[] args) {
        char[] data={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T',
        'U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9'};
        int mod=36;
        Scanner s=new Scanner(System.in);
        System.out.println("请输入将要加密的明文");
        String plainText=s.next();
        plainText=plainText.toUpperCase(); //输入的明文转为大写
        //判断K1是否与36互素,不互素则重新输入k1
        int k1;
        while(true){
            System.out.println("请输入k1:");
            k1=s.nextInt();
            String answer=judge(k1,mod);
            if(answer.equals("yes"))
                break;
            else
                System.out.println("k1与mod不互素,请重新输入");
        }
        System.out.println("请输入K2");
        int k2=s.nextInt();
        k2=Math.floorMod(k2,mod);
        //加密
        System.out.println("加密后:");
        char[] cipherText=encryption(plainText,k1,k2,data,mod);
        for (int i = 0; i mod  ? k1:mod;
        for(int i=1;i<=smallNumber;i++){
            if(bigNumber%smallNumber==0)
                return "no";
        }
        return "yes";
    }

    //加密
    public static char[] encryption(String plainText,int k1,int k2,char[] data,int mod){
        //plainNum用于存储明文对应的数字
        char[] cipherText=new char[plainText.length()];
        int k=0;
        int temp;
        for (int i = 0; i < plainText.length(); i++) {
            for (int j = 0; j 

你可能感兴趣的:(算法数学基础,java,开发语言)