凯撒密码

/**
	 * 凯撒密码
	 */
	public static void getA21(){
		String s = "hello word";/* 明文 */
        int key=Integer.parseInt("2");/* 密钥 */
        String es="";
        for(int i=0;i<s.length( );i++){  
        	char c=s.charAt(i);
               if(c>='a' && c<='z') { // 是小写字母
					c+=key%26;  //移动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;
           }
       System.out.println(es);
    }

你可能感兴趣的:(C++,c,C#)