凯撒密码一种代换密码,据说凯撒是率先使用加密函的古代将领之一,因此这种加密方法被称为恺撒密码。凯撒密码的基本思想是:通过把字母移动一定的位数来实现加密和解密。明文中的所有字母都在字母表上向后(或向前)按照一个固定数目进行偏移后被替换成密文。

使用JAVA程序实现对明文的加密:

package com.qikeyishu.www;

public class Kaisapwd {
  public static void main(String[] args) {
    char str[]={'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'};
    for(char out:str){
        System.out.print(out+" ");
      }
      for(int i=0;i<26;i++){
        if(i<23){
          str[i]+=3;
        }else{
          str[i]-=23;
        }
      }
      System.out.println("\n");
      for(char out:str){
        System.out.print(out+" ");
      }
}
}

加密前后:

使用JAVA程序实现对密文的解密:

package com.qikeyishu.www;

public class Kaisapwd {
  public static void main(String[] args) {
    char str[]={'d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','a','b','c'};
    for(char out:str){
      System.out.print(out+" ");
    }
    for(int i=0;i<26;i++){
      if(i<23){
        str[i]-=3;
      }else{
        str[i]+=23;
      }
    }
    System.out.println("\n");
    for(char out:str){
      System.out.print(out+" ");
    }
}
}

解密前后:

最新文章

  1. 及时取消代码中的AsyncTask
  2. SQL2008&quot;阻止保存要求重新创建表的更改&quot;问题的解决
  3. jackson json转实体 允许特殊字符和转义字符 单引号
  4. 让html元素随浏览器的大小自适应垂直居中
  5. G - A+B for Input-Output Practice (VI)
  6. SSH2中实例化不了Action的一个原因
  7. windows应用中调用DLL一步步试验
  8. JDBC操作数据时中文乱码
  9. 一句python,一句R︱python中的字符串操作、中文乱码
  10. MVC4 中的Model显示设置(含显示Shared/DisplayTemplates和编辑Shared/EditorTemplates)
  11. Linux学习之CentOS(一)--CentOS6.4环境搭建
  12. Windows Server 2008 R2 下载地址
  13. Python之路(第十二篇)程序解耦、模块介绍\导入\安装、包
  14. LeetCode: Best Time to Buy and Sell Stock 解题报告
  15. caffe安装编译问题-ImportError: No module named skimage.io
  16. Bug:src/lxml/lxml.etree.c:84:20: 致命错误:Python.h:没有那个文件或目录
  17. php BC高精确度函数库
  18. Python 百度语音识别与合成REST API及ffmpeg使用
  19. maven安装之后,或者升级之后遇到的问题:could not find or load main class org.codehaus.plexus.class.....
  20. python实现判断一个字符串是否是合法IP地址

热门文章

  1. Windows Azure Platform Introduction (14) 申请海外的Windows Azure账户
  2. JAVAEE——BOS物流项目05:OCUpload、POI、pinyin4J、重构分页代码、分区添加、combobox
  3. 使用DateTimeOffset 对xml中的日期时间格式时区进行处理
  4. ASP.NET Core Razor 页面使用指南
  5. win7(windows 7)系统下安装SQL2005(SQL Server 2005)图文教程
  6. Java经典编程题50道之七
  7. Yii2中JSONP跨域问题的解决
  8. uva103 动态规划
  9. Luogu P1092 虫食算
  10. Python基础学习参考(六):列表和元组