CesarCypher_ByDenysBurduzhan#9
Conversation
# Conflicts: # readme.md
oleksandr-jr
left a comment
There was a problem hiding this comment.
Good implemented project with possible minor architectural improvements.
I hope you enjoyed the process and learned new things during this project.
Furthermore, I wish to see more of your projects in next modules. 🙂
| import java.io.IOException; | ||
| import java.nio.file.Path; | ||
|
|
||
| public class CryptAnalyzerGUI { |
| try { | ||
| if (runOptions.getCommand() == Command.ENCRYPT) { | ||
| String content = fileManager.read(runOptions.getFilePath()); | ||
| String encryptedContent = cypher.encrypt(content, runOptions.getKey()); | ||
| String encryptedContent = cryptanalyzer.encryption(content, runOptions.getKey()); | ||
| String fileName = runOptions.getFilePath().getFileName().toString(); | ||
| String newFileName = fileName.substring(0, fileName.length() - 4) + " [ENCRYPTED].txt"; | ||
|
|
||
| Path newFilePath = runOptions.getFilePath().resolveSibling(newFileName); | ||
| fileManager.write(newFilePath, encryptedContent); | ||
| } else if (runOptions.getCommand() == Command.DECRYPT) { | ||
| String content = fileManager.read(runOptions.getFilePath()); | ||
| String encryptedContent = cryptanalyzer.decryption(content, runOptions.getKey()); | ||
| String fileName = runOptions.getFilePath().getFileName().toString(); | ||
| String newFileName = fileName.substring(0, fileName.length() - 4) + " [DECRYPTED].txt"; | ||
|
|
||
| Path newFilePath = runOptions.getFilePath().resolveSibling(newFileName); | ||
| fileManager.write(newFilePath, encryptedContent); | ||
| } else if (runOptions.getCommand() == Command.BRUTEFORCE) { | ||
| String content = fileManager.read(runOptions.getFilePath()); | ||
| String encryptedContent = runBruteforce.bruteforce(content,dictionary.getDictionary(), dictionary.getDictionaryUKR()); | ||
| String fileName = runOptions.getFilePath().getFileName().toString(); | ||
| String key = runBruteforce.getKey(content, dictionary.getDictionary(), dictionary.getDictionaryUKR()).replace("Key: ", ""); | ||
| String newFileName = fileName.substring(0, fileName.length() - 4) + " [DECRYPTED Key -" + key + "].txt"; | ||
|
|
||
| Path newFilePath = runOptions.getFilePath().resolveSibling(newFileName); | ||
| fileManager.write(newFilePath, encryptedContent); | ||
| } | ||
| } catch (Exception e) { | ||
| System.out.println(e.getMessage()); | ||
| }catch (Exception e){ | ||
| System.out.println("Smth went wrong"); | ||
| } | ||
| } |
There was a problem hiding this comment.
This code looks complicated and contains duplicates.
Could be simplified. See more here.
| for (char symbol : array) { | ||
| if (Character.isLowerCase(symbol)) { | ||
| int originalIndex = constants.getEngLower().indexOf(symbol); | ||
| if (originalIndex != -1) { | ||
| Character encrypted = ENG_LOWER_MOD.get(originalIndex); | ||
| builder.append(encrypted); | ||
| continue; | ||
| } | ||
|
|
||
| originalIndex = constants.getUkrLower().indexOf(symbol); | ||
| if (originalIndex != -1) { | ||
| Character encrypted = UKR_LOWER_MOD.get(originalIndex); | ||
| builder.append(encrypted); | ||
| } else { | ||
| builder.append(symbol); | ||
| } | ||
| } | ||
| else if (Character.isUpperCase(symbol)) { | ||
| int originalIndex = constants.getEngUpper().indexOf(symbol); | ||
| if (originalIndex != -1) { | ||
| Character encrypted = ENG_UPPER_MOD.get(originalIndex); | ||
| builder.append(encrypted); | ||
| continue; | ||
| } | ||
|
|
||
| originalIndex = constants.getUkrUpper().indexOf(symbol); | ||
| if (originalIndex != -1) { | ||
| Character encrypted = UKR_UPPER_MOD.get(originalIndex); | ||
| builder.append(encrypted); | ||
| } else { | ||
| builder.append(symbol); | ||
| } | ||
| } else { | ||
| builder.append(symbol); | ||
| } | ||
| } | ||
| return builder.toString(); |
There was a problem hiding this comment.
Too complicated and hard to read / change. Might be simplified by extracting methods. See more here.
| import ua.com.javarush.gnew.Constants.Constants; | ||
|
|
||
|
|
||
| public class RunBruteforce { |
There was a problem hiding this comment.
Very good approach here. And my suggestion is the same here. It might be simplified by extracting methods and removing duplicates.
https://refactoring.guru/extract-method
https://refactoring.guru/uk/smells/duplicate-code
Ready to review