凯撒密码加密解密--JAVA实现(基础)
2024-10-11 22:34:44
凯撒密码一种代换密码,据说凯撒是率先使用加密函的古代将领之一,因此这种加密方法被称为恺撒密码。凯撒密码的基本思想是:通过把字母移动一定的位数来实现加密和解密。明文中的所有字母都在字母表上向后(或向前)按照一个固定数目进行偏移后被替换成密文。
使用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+" ");
}
}
}
解密前后:
最新文章
- 及时取消代码中的AsyncTask
- SQL2008";阻止保存要求重新创建表的更改";问题的解决
- jackson json转实体 允许特殊字符和转义字符 单引号
- 让html元素随浏览器的大小自适应垂直居中
- G - A+B for Input-Output Practice (VI)
- SSH2中实例化不了Action的一个原因
- windows应用中调用DLL一步步试验
- JDBC操作数据时中文乱码
- 一句python,一句R︱python中的字符串操作、中文乱码
- MVC4 中的Model显示设置(含显示Shared/DisplayTemplates和编辑Shared/EditorTemplates)
- Linux学习之CentOS(一)--CentOS6.4环境搭建
- Windows Server 2008 R2 下载地址
- Python之路(第十二篇)程序解耦、模块介绍\导入\安装、包
- LeetCode: Best Time to Buy and Sell Stock 解题报告
- caffe安装编译问题-ImportError: No module named skimage.io
- Bug:src/lxml/lxml.etree.c:84:20: 致命错误:Python.h:没有那个文件或目录
- php BC高精确度函数库
- Python 百度语音识别与合成REST API及ffmpeg使用
- maven安装之后,或者升级之后遇到的问题:could not find or load main class org.codehaus.plexus.class.....
- python实现判断一个字符串是否是合法IP地址
热门文章
- Windows Azure Platform Introduction (14) 申请海外的Windows Azure账户
- JAVAEE——BOS物流项目05:OCUpload、POI、pinyin4J、重构分页代码、分区添加、combobox
- 使用DateTimeOffset 对xml中的日期时间格式时区进行处理
- ASP.NET Core Razor 页面使用指南
- win7(windows 7)系统下安装SQL2005(SQL Server 2005)图文教程
- Java经典编程题50道之七
- Yii2中JSONP跨域问题的解决
- uva103 动态规划
- Luogu P1092 虫食算
- Python基础学习参考(六):列表和元组