请教啊!java加密算法!要求用户输入要加密的字符(英文字符其他的不考虑)题目如下:我主要问的是《加密

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了请教啊!java加密算法!要求用户输入要加密的字符(英文字符其他的不考虑)题目如下:我主要问的是《加密相关的知识,希望对你有一定的参考价值。

2、类的设计
该系统中必须包括三个类。
输入台控制类(Swither)
Encryption(字符串加密类)
Decryption(字符串解密类)
3、具体要求及推荐实现步骤
1、创建控制台控制类Switcher,用于和操作者交互。
2、开发加密类Encryption,使用凯撒加密法对字符串加密,并把加密后的结果返回给Switcher。
3、开发解密类Dncryption,使用凯撒加密法对字符串解密,并把解密后的结果返回给Switcher。
凯撒加密法,就是将字母表中的每个字母向后移动3位,比如a被替换成d,b被替换成f,以此类推。字母表的最后三位xyz,会被替换为abc。比如hello,加密之后是khoor.对于拉丁字母之外的其他字符,一律不加密。
我只想知道怎么加密代码! 其他的不用啰嗦!

参考技术A public class Swither
public static void main(String[] args)
System.out.println("ab,cdx;yz中国");
System.out.println(Encryption.encryption( "ab,cdx;yz中国"));
System.out.println(Decryption.decryption((Encryption.encryption( "ab,cdx;yz中国"))));


运行结果如下:
ab,cdx;yz中国
de,fga;bc中国
ab,cdx;yz中国

public class Encryption

public static String encryption(String content)

if(content==null)
return null;
String temp="";
for(int i=0;i<content.length();i++)

char c=content.charAt(i);
//if(Character.isLetter(c))
if((c>='a' && c<='z')||(c>='A' && c<='Z'))
if(c=='x' || c=='y' || c=='z' || c=='X' || c=='Y' || c=='Z')
c=(char)(c-23);
else
c=(char)(c+3);
temp+=c;


return temp;




public class Decryption

public static String decryption(String content)

if(content==null)
return null;
String temp="";
for(int i=0;i<content.length();i++)

char c=content.charAt(i);
//if(Character.isLetter(c))
if((c>='a' && c<='z')||(c>='A' && c<='Z'))
if(c=='a' || c=='b' || c=='c' || c=='A' || c=='B' || c=='C')
c=(char)(c+23);
else
c=(char)(c-3);
temp+=c;


return temp;


追问

什么东东!不是你这么做的!

追答

import java.util.Scanner;
public class Swither
public static void main(String[] args)
Scanner sc=new Scanner(System.in);
System.out.println("请输入要加密的内容:");
String content=sc.next();
System.out.println(Encryption.encryption( content));
System.out.println(Decryption.decryption((Encryption.encryption( content))));

以上是关于请教啊!java加密算法!要求用户输入要加密的字符(英文字符其他的不考虑)题目如下:我主要问的是《加密的主要内容,如果未能解决你的问题,请参考以下文章

Java小案例——对字符串进行加密解密

java字串加密及String的各类函数说明

java对zip文件进行加密

JAVA如何对URL进行加密和解密啊

急求!!“1024位的RSA 公开密钥加密算法 ”数据结构课程设计!高手解答啊!!

JAVA字符串05之课程问题解决