字符串如何使用ascii码对java中的caesar进行加密,使每个字符旋转13位
如何使用ascii码对java中的caesar进行加密将每个字符旋转13位示例如果输入的句子是abcd,它应该显示nopq i无法从字母n到z获得它显示问号。 节目
import java.util.Scanner;
class caesarcipher
{
public static void main(String args[])
{
Scanner ga=new Scanner(System.in);
System.out.println("Enter a text to be ciphered");
String s=ga.nextLine();String cc="";
int l=s.length();
for(int i=0;i<=l-1;i++)
{
char c=s.charAt(i);
int n=(int)c;
if(c!=' '&&c!='!'&&c!='?'&&c!='.')//to check for special characters
{
if(c>'A'||c<'M'||c>'a'||c<'m')
{
n=n+13;//to mo
char f=(char)n;
cc=cc+f;
}
}
if(c!=' '&&c!='!'&&c!='?'&&c!='.')
{
if(c>'N'||c<'Z'||c>'n'||c<'z')
{
int p=(int)c;
p=p-13;//toget value 13 times behind
System.out.println(p);
char f=(char)p;
cc=cc+f;
}
}
else
{
cc=cc+c;
}
}
System.out.println("The ciphered text is : "+cc);
}
}
//output of my program= Enter a text to be ciphered stuvwxyz-The ciphered //text is : ?f?g?h?i?j?k?l?m
//输入输出=fghhijklm
共 (0) 个答案