ADFGVX cipher: Difference between revisions

Content added Content deleted
(New post.)
Line 2,133: Line 2,133:
System.out.println();
System.out.println();
final String plainText = "ATTACKAT1200AM";
final String plainText = "ATTACKAT1200AM";
System.out.println("Plaintext: " + plainText);
System.out.println("Plain text: " + plainText);
System.out.println();
System.out.println();
final String encryptedText = encrypt(plainText, polybius, key);
final String encryptedText = encrypt(plainText, polybius, key);
Line 2,184: Line 2,184:
}
}
// Create a key using a word from "unixdict.txt"
// Create a key using a word from the dictionary 'unixdict.txt'
private static String createKey(int size) throws IOException {
private static String createKey(int size) throws IOException {
if ( size < 7 || size > 12 ) {
if ( size < 7 || size > 12 ) {
Line 2,191: Line 2,191:
List<String> candidates = Files.lines(Path.of("unixdict.txt"))
List<String> candidates = Files.lines(Path.of("unixdict.txt"))
.filter( word -> word.length() == size )
.filter( word -> word.length() == size )
.filter( word -> word.chars().distinct().count() == word.length() )
.filter( word -> word.chars().distinct().count() == word.length() )
.filter( word -> word.chars().allMatch(Character::isLetterOrDigit) )
.filter( word -> word.chars().allMatch(Character::isLetterOrDigit) )