-
Notifications
You must be signed in to change notification settings - Fork 16
P1 Antonina #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
P1 Antonina #8
Conversation
…s and checkForCommonWords)
…ce mode, edited common words in Alphabet, bruteforce works partially
…it Cypher.calculateKey() into 2 simpler methods; updated readme.md.
oleksandr-jr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This project is pure simplicity and elegance in good meaning.
- Good documented code.
- Cool solutions.
- Sometimes the architecture might be more open for future improvements.
Live review:
https://youtu.be/qgbS_6g_D-w?si=jVurwICoEBpScE3E&t=3953
| for (int i = 0; i < text.length(); i++) { | ||
| char oneChar = text.charAt(i); // беремо символ з тексту | ||
| int index = Alphabet.ENGLISH_LOWERCASE.indexOf(oneChar); // шукаємо його в алфавіті lowercase | ||
| if (index != -1) { // якщо знайшли | ||
| result.append(rotatedLowercase.get(index)); // шифруємо і додаємо до результату | ||
| } else { // якщо немає | ||
| index = Alphabet.ENGLISH_UPPERCASE.indexOf(oneChar); // шукаємо його в алфавіті uppercase | ||
| if (index != -1) { // якщо знайшли | ||
| result.append(rotatedUppercase.get(index)); // шифруємо і додаємо до результату | ||
| } else { // якщо не знайшли в жодному з двох алфавітів, це спеціальний символ | ||
| result.append(text.charAt(i)); // НЕ шифруємо і просто додаємо | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be simplified.
| public static final ArrayList<Character> ENGLISH_UPPERCASE = new ArrayList<>(Arrays.asList( | ||
| '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')); | ||
| public static final ArrayList<Character> ENGLISH_LOWERCASE = new ArrayList<>(Arrays.asList( | ||
| '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')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could get rid of two lists and use only one by processing uppercase letters dynamically.
| for (String line : text) { | ||
| encrypted = line; | ||
| for (int i = 0; i < 26; i++) { | ||
| decrypted = decrypt(line, i); | ||
| if (checkForCommonWords(decrypted)) { | ||
| break; | ||
| } | ||
| } | ||
| break; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that you decrypt it using lines. In some cases, it's very effective, but there are also some cases when it might not work as expected. Maybe it's good idea to take more than 1 line if it contains not enough letters a.e. always use the text > 256 symbols.
| linesRead = fileManager.read(runOptions.getFilePath()); | ||
| switch (runOptions.getCommand()) { | ||
| case ENCRYPT: | ||
| for (String lineRead : linesRead) { | ||
| linesWritten.add(cypher.encrypt(lineRead, runOptions.getKey())); | ||
| } | ||
| resultFile = fileManager.getNewPath(runOptions.getFilePath(), runOptions.getCommand()); | ||
| break; | ||
| case DECRYPT: | ||
| for (String lineRead : linesRead) { | ||
| linesWritten.add(cypher.decrypt(lineRead, runOptions.getKey())); | ||
| } | ||
| resultFile = fileManager.getNewPath(runOptions.getFilePath(), runOptions.getCommand()); | ||
| break; | ||
| case BRUTEFORCE: | ||
| int key = cypher.bruteForceKey(linesRead); | ||
| for (String lineRead : linesRead) { | ||
| linesWritten.add(cypher.decrypt(lineRead, key)); | ||
| } | ||
| resultFile = fileManager.getNewPath(runOptions.getFilePath(), key); | ||
| break; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to keep the logic out of the main method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.jar file shouldn't be committed. It should be added as a release executable.
The project is done.