凯撒加密解密
- 古罗马大帝凯撒发明:对字符串偏移
public static String encrypt(String str, int key) { StringBuilder stringBuilder = new StringBuilder(); char[] array = str.toCharArray(); for (char c : array) { int value = c; value += key; char cs = (char) value; stringBuilder.append(cs); } return stringBuilder.toString(); }
public static String decryp(String str, int key) { StringBuilder stringBuilder = new StringBuilder(); char[] array = str.toCharArray(); for (char c : array) { int value = c; value -= key; char cs = (char) value; stringBuilder.append(cs); } return stringBuilder.toString(); }
频度分析法破解凯撒加密算法
- 根据统计学破解凯撒算法:一篇英文文章字母e出现的概率很高