凯撒加密
<h5>最简单的对称加密-凯撒加密</h5>
<h6>入口函数:</h6>
<pre><code> public static void main(String[] args) {
String helloword = "aAhello word";
helloword = encodeKaiSa(helloword);
System.out.println("加密后:" + helloword);
helloword = decodeKaiSa(helloword);
System.out.println("解密后:" + helloword);
}</code></pre>
<h6>:加密:</h6>
<pre><code>/**
* 凯撒加密
*
* @param string
* @return
*/
private static String encodeKaiSa(String string) {
char[] arr = string.toCharArray();
StringBuffer stringBuffer = new StringBuffer();
for (char c : arr) {
int i = c;
i += 3;
char cc = (char) i;
stringBuffer.append(cc);
}
return stringBuffer.toString();
}
</code></pre>
<h6>解密:</h6>
<pre><code>/**
* 凯撒解密
*
* @param string
* @return
*/
private static String decodeKaiSa(String string) {
char[] arr = string.toCharArray();
StringBuilder stringBuilder = new StringBuilder();
for (char c : arr) {
int i = c;
i -= 3;
char cc = (char) i;
stringBuilder.append(cc);
}
return stringBuilder.toString();
}</code></pre>