저는 Java에서 새로운 기능입니다. 나는 무차별 대입을 사용하여 Caesar의 암호를 해독 한 다음 사전에서 단어를 찾아 올바른 이동을 찾기위한 알고리즘을 작성해야합니다. 그것은 지금까지 작성한 코드입니다. 누군가가 편지를 이동하고 dictionary.txt 파일과 일치시키는 것을 도와 주면 정말 고맙습니다.Java caesars cipher brute forcing
decodedText[i] = alphabet[(alphabetList.indexOf(message[i])+key) % alphabet.length];
당신은 아마 반복을 시작해야합니다 후 다음 작업을 수행 할 수 있습니다 내부
private List<Character> alphabetList = java.util.Arrays.asList(alphabet);
:
private char[] alphabet = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
private char[] decodedText;
private String plainText;
public String producePlaintext(String cipherText) {
//put each letter of the ciphertext in an array of characters in the upper case format
char[] message = cipherText.toUpperCase().toCharArray();
//loop through all the possible keys
for (int key = 0; key < alphabet.length; key++) {
//set the value of the decrypted array of characters to be the same as the length of the cipher text
decodedText = new char[message.length];
//loop through the characters of the ciphertext
for (int i = 0; i < message.length; i++) {
//if character is not space
if (message[i] != ' ') {
//shift the letters
}else{
decodedText[i] = ' ';
}
}
plainText = String.valueOf(decodedText);
}
return plainText;
}
구체적으로 어떤 문제가 있습니까? 생성 된 일반 텍스트가 실제 일반 텍스트라는 확인 함수가 필요할 것입니다. 그렇지 않으면 해독 할 수 없습니다. 그러나 가능한 모든 26 개의 일반 텍스트를 인쇄하고 알려진 단어를 찾아 실제 일반 텍스트를 선택하려고 할 수 있습니다. 프로그래밍 방식으로도이 작업을 수행 할 수 있지만 단어 목록이 필요합니다. –
제 문제는 가능한 모든 일반 텍스트를 인쇄하는 것입니다. – user3451112