-
Notifications
You must be signed in to change notification settings - Fork 16
CesarCypher_ByDenysBurduzhan #9
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?
Conversation
# Conflicts: # 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.
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 { |
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.
Very good job here.
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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