栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Java加密程序

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Java加密程序

package mypack;

import java.util.*;

public class Encry{
    public static void main (String[] args){
        Scanner sc = new Scanner(System.in);
        sc.useDelimiter("n");
        String hint = "****************This is QILE encryption app. "+"Type 'help' for more information"+"****************n"+"Your option:";
        while(true) {
            System.out.print(hint);
            String response = sc.next();
            System.out.println();
            if (response.equals("encry")) {
                System.out.println("***********");
                System.out.print("Enter the encryption code:");
                int encryB = 123;
                try {
                    encryB = sc.nextInt();
                    if (encryB <= 0) {
                        try {
                            throw new RuntimeException("Enter a non-negative number!");
                        } catch (RuntimeException e) {
                            System.out.println(e.getMessage());
                            break;
                        }
                    }
                } catch (InputMismatchException e) {
                    System.out.println();
                    System.out.println("Please enter a number!");
                    System.out.println();
                    break;
                }
                System.out.println();
                System.out.print("Enter the text you want to be encrypted:");
                String text = sc.next();
                char[] chars = text.toCharArray();
                for (int i = 0; i < chars.length; i++) {
                    chars[i] = (char) (chars[i] ^ encryB);
                }
                System.out.println("Your encrypted text is:");
                System.out.println(chars);
                System.out.println("***********");
            }
            else if (response.equals("code")){
                System.out.println();
                int num = new Random().nextInt(100000) + 1;
                System.out.println("your code is:" + num);
                System.out.println();
            } else if (response.equals("decry")){ System.out.println();
                System.out.print("Enter the encryption code:");
                int encryB1 = 123;
                try {
                    encryB1 = sc.nextInt();
                }catch (InputMismatchException e){
                    System.out.println();
                    System.out.println("Please enter a number!");
                    System.out.println();
                    break;
                }
                System.out.println();
                System.out.print("Enter the encrypted text:");
                String enText = sc.next();
                char[] chars1 = enText.toCharArray();
                for (int j = 0; j < chars1.length; j++) {
                    chars1[j] = (char) (chars1[j] ^ encryB1);
                }
                System.out.println("The decrypted text is:");
                System.out.println(chars1);
                System.out.println("***********");
            }else if (response.equals("help")){
                System.out.println("***********");
                System.out.println("QILE encryption app provides any encryption" +
                        " service you want.Here are some usual commands:");
                System.out.println("encry -- for encrypt a text");
                System.out.println("code -- for generating encryption code randomly");
                System.out.println("decry -- for decrypt a text");
                System.out.println("exit -- for quit the program");
                System.out.println();
                System.out.println("The encryption code(number) is a key, you will"
                        +"l need the key for decrypted and encrypted"
                        +"We suggested You should use a more longer key for safety"
                        +"Thanks very much choosing and using the QILE Encryption App!");
                System.out.println("** If you have a problem,contact us in vwu2021@outlook.com **");
                System.out.println("***********");
            }else if (response.equals("exit")) {
                System.out.println("***********");
                System.out.println("Bye,Thanks for using!");
                System.out.println("***********");
                System.exit(0);
            }
            else {
                System.out.println();
                System.out.println("Not a valid response!");
                System.out.println();
            }
        }
    }
}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/458487.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号