zoukankan      html  css  js  c++  java
  • 字串加密、解密

    (一)设计思想:首先由用户键盘输入想要加密或解密的英文字符串,再输入是想要加密还是解密;之后利用条件语句

                          分两种情况讨论:1.若要加密,for循环从字符串的第一个字符扫描到最后一个,得到该位置的字符,

                          并输出该字符在字母表中向后数三个位置的字母,其中X、Y、Z则分三种情况输出A、B、C;2.若要

                          解密,for循环从字符串的第一个字符扫描到最后一个,得到该位置的字符,并输出该字符在字母表中

                          向前数三个位置的字母,其中A、B、C则分三种情况输出X、Y、Z。

    (二)程序流程图:

    (三)源代码:

    import java.util.Scanner;
    public class Secret {

    public static void main(String[] args) {
    // TODO Auto-generated method stub

        Scanner input = new Scanner(System.in);
        System.out.println("请输入一个英文字符串(大写):");
        String sss = input.nextLine();

        System.out.println("请问需要加密还是解密?(加密输入1,解密输入0)");
        int a = input.nextInt();

        if(a==1)
        {
            System.out.println("该英文字符加密后为:");
            for(int i=0;i<sss.length();i++)
            {
                char ch = sss.charAt(i);
                if(ch=='X')
               {
                    System.out.print('A');
               }
                else if(ch=='Y')
               {
                    System.out.print('B');
               }
                else if(ch=='Z')
               {
                    System.out.print('C');
               }
                else
                    System.out.print((char)(ch+3));
             }
        }
        if(a==0)
        {
             System.out.println("该英文字符解密后为:");
             for(int i=0;i<sss.length();i++)
            {
                char ch = sss.charAt(i);
                if(ch=='A')
               {
                   System.out.print('X');
               }
                else if(ch=='B')
               {
                   System.out.print('Y');
               }
                else if(ch=='C')
               {
                   System.out.print('Z');
               }
                else
                   System.out.print((char)(ch-3));
            }
        }

    (四)结果截图:

  • 相关阅读:
    caffe用到的命令和零碎知识
    Manjaro — ssh出现22端口拒绝访问问题(port 22: Connection refused)
    Linux 解压z01 .z02 .z03... zip分卷
    Manjaro_Windows双系统安装
    Linux 的chsh命令
    mat2json, python读取mat成字典, 保存json
    最便捷的caffe编译方法 ---- cmake+anaconda虚拟环境
    复制跳过软链接
    使用Screen解决ssh连接中断导致的训练中断问题
    Caffe训练时Loss=87.3365问题
  • 原文地址:https://www.cnblogs.com/96ZYJ/p/4905762.html
Copyright © 2011-2022 走看看