Java学习之“凯撒密码”实例
来源:互联网 发布:nba2k17帅哥捏脸数据 编辑:程序博客网 时间:2024/06/06 03:56
代码实现容易,关键点在于,字母移位后是否越界,及相应的处理
public class Caesar { String s; int key; Caesar(String es, int n) { this.s = es; this.key = n; } public String process() { String es = ""; for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (c >= 'a' && c <= 'z') { c += key % 26; if (c < 'a') c += 26; if (c > 'z') c -= 26; } else if (c >= 'A' && c <= 'Z') { c += key % 26; if (c < 'A') c += 26; if (c > 'Z') c -= 26; } es += c; } return es; } public static void main(String[] args) { String s = "hello"; Caesar c = new Caesar(s, 2); String str = c.process(); System.out.println("加密字符串为: " + str); Caesar c1 =new Caesar(str, -2); str = c1.process(); System.out.println("解密字符串为:" + str); }}
阅读全文
0 0
- Java学习之“凯撒密码”实例
- Java安全学习笔记(一)--凯撒密码
- 凯撒密码学习
- FZU1406 之 凯撒密码
- 凯撒密码的java实现
- java解决凯撒密码问题
- 凯撒密码
- 凯撒密码
- 凯撒密码
- 凯撒密码
- 凯撒密码
- 凯撒密码
- 凯撒密码
- 凯撒密码
- 凯撒密码
- 凯撒密码
- 凯撒密码
- 凯撒密码
- Common(二)—— CMemQueue
- google-chrome 启动报错 nss_util.cc(627)] NSS_VersionCheck("3.26") failed. NSS >= 3.26 is required
- React Native布局详细指南
- Leetcode: 13. Roman to Integer(Week2, Easy)
- 第4章 随机变量的数字特征
- Java学习之“凯撒密码”实例
- 垃圾收集器
- Android虚拟机多开检测
- mysql高级笔记(二)
- java包jar下载
- Jenkins入门系列之——02第二章 Jenkins安装与配置
- 饿了么项目(四)
- 怎么打开注册表
- next_permutation