代码拉取完成,页面将自动刷新
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();
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。