基本思想:

加密是把字符串中的每一个字符+3解密是每一个字符-3

源代码:

package demo;
import java.util.Scanner;

class Encryption{
String a;
public void encryption(String q){
String string= "";
for(int i = 0;i < q.length();i++)
{
char b=q.charAt(i);
if(b >= 'a'&&b <='z')
{
b += 3;
if(b > 'z')
b-=26;
if(b < 'a')
b=+26;
}
else if(b >= 'A'&&b <= 'Z')
{
b+=3;
if(b > 'Z')
b-=26;
if(b < 'A')
b+=26;
}
string += b;
}
System.out.println("加密后为:"+string);
}

}
class Decryption{
String a;
public void decryption(String q){
String string= "";
for(int i = 0;i < q.length();i++)
{
char b=q.charAt(i);
if(b >= 'a'&&b <='z')
{
b -= 3;
if(b > 'z')
b-=26;
if(b < 'a')
b+=26;
}
else if(b >= 'A'&&b <= 'Z')
{
b-=3;
if(b > 'Z')
b-=26;
if(b < 'A')
b+=26;
}
string += b;
}
System.out.println("解密后为:"+string);
}

}
public class Password{
public static void main(String[] args){
System.out.println("a。加密 b.解密");
Scanner choose = new Scanner(System.in);
String a = choose.nextLine();
if(a.equalsIgnoreCase("a"))
{
Scanner c = new Scanner(System.in);
System.out.println("请输入明文:");
String b = c.nextLine();
Encryption en = new Encryption();
en.encryption(b);
}
else if(a.equalsIgnoreCase("b")) // equals 用来比较两个对象所表示的字符是否相同
{ // equalsIgnoreCase 用来比较对象所代表的字符与括号中字符是否相同
Scanner c = new Scanner(System.in);
System.out.println("请输入密码:");
String b = c.nextLine();
Decryption de = new Decryption();
de.decryption(b);
}
}
}

结果截图:

最新文章

  1. java基础知识总结(1)
  2. 批处理——服务器的web文件备份
  3. CF570D:Tree Requests
  4. 二叉搜索树 POJ 2418 Hardwood Species
  5. SharePoint 2013 删除母版页报错“This file may not be moved, deleted, renamed, or otherwise edited”
  6. [MySQL]导入导出
  7. MYSQL里的索引类型介绍
  8. Java——泛型(最易懂的方式讲解泛型)
  9. IAR ERROR --- [Li006]
  10. 【Android】使用BaseAdapter实现复杂的ListView
  11. 12.04 ubuntu 更改IP
  12. mount挂接命令使用
  13. Ecelipse上添加Server
  14. Mybatis笔记三:全局配置文件
  15. vlc-ts
  16. ili9325--LCD寄存器配置研究
  17. 黄聪:实用WordPress SQL查询方法
  18. phalcon7开发环境搭建
  19. Redis系列一:reids的单机版安装
  20. Nunit常用的方法说明

热门文章

  1. PHP中文函数顺序排列一数组且其序数不变
  2. Web前端开发基础 第四课(CSS小技巧)
  3. session生命周期
  4. 打开网页自动弹出QQ对话框的实现办法
  5. SVN 远程无法联通
  6. thinkphp3.2整合phpexcel
  7. ORM系列之一:Dos.ORM
  8. swt小知识点
  9. 检测中文长度gbk下2个字节
  10. 在CentOS 6.6下安装与配置mysql