凯撒加密算法

设计思想:

先确定26个字母的一定的序列,输入一个字符串,在序列中找到单个字符的位置,输出该位置往后3个位置的字母

程序流程图:

  

 

源代码:

import java.util.Scanner;

 

public class Encrypt 

{

public static void main(String[] args)

{

String s="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

char c[]=s.toCharArray();

System.out.println("请输入字符串");

Scanner sc=new Scanner(System.in);

String s1=sc.next();

char c2[]=s1.toCharArray();

System.out.println("加密后为");

for(int i=0;i<s1.length();i++)

{

int index=s.indexOf(c2[i]);

  if(index>=23)
   {
    index=index-26;
   }

System.out.println(c[index+3]+" ");

}

}

}

 

运行结果:

 

posted @ 2015-10-24 13:39  木子金帛  阅读(565)  评论(0编辑  收藏  举报