1 Star 0 Fork 0

haolin/tags2

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
thirdapi01.java 1.29 KB
一键复制 编辑 原始数据 按行查看 历史
haolin 提交于 2020-09-14 23:34 . commit-thirdapi01.java
package com.ciphers;
public class CaesarBruteForce {
/**
* Recursively Brute forces a parsed encrypted text, trying out all shifting keys from 1-26, printing out all decryption attempts
* @param message (String) The encrypted text.
* @param Key (int) The key used to decrypt the encrypted text and is increment upon a recursive call.
* @return (String) Concatenated string of all decryption attempts (For unit testing purposes).
*/
public String decrypt(String message, int Key) {
final String LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
if (Key > 26){ System.out.println(); return null; }
StringBuilder plainText = new StringBuilder();
for (char character : message.toUpperCase().toCharArray()) {
int index = LETTERS.indexOf(character);
if (index != -1) {
index -= Key;
//Wrap around index value range[1-26]
if (index < 0) { index += LETTERS.length(); }
plainText.append(LETTERS.toCharArray()[index]);
} else { plainText.append(character); }
}
System.out.println(String.format("Current Decryption Key %d : %s", Key, plainText));
return plainText.append(decrypt(message, Key+1)).toString();
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/haolin16/tags2.git
git@gitee.com:haolin16/tags2.git
haolin16
tags2
tags2
master

搜索帮助