Finished project of the first module#10
Open
DevEvge wants to merge 14 commits intoJavaRush-GNEW:mainfrom
Open
Conversation
Create method ChandeFileName
oleksandr-jr
approved these changes
Oct 19, 2024
Contributor
oleksandr-jr
left a comment
There was a problem hiding this comment.
I like the implementation and see your effort here to make this project.
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. 🙂
Comment on lines
18
to
+30
| <dependencies> | ||
| <!-- JavaFX dependencies --> | ||
| <dependency> | ||
| <groupId>org.openjfx</groupId> | ||
| <artifactId>javafx-controls</artifactId> | ||
| <version>${javafx.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.openjfx</groupId> | ||
| <artifactId>javafx-fxml</artifactId> | ||
| <version>${javafx.version}</version> | ||
| </dependency> | ||
|
|
Contributor
There was a problem hiding this comment.
Having a UI interface is really cool.
Comment on lines
36
to
64
| public static void main(String[] args) { | ||
| Cypher cypher = new Cypher(); | ||
| FileManager fileManager = new FileManager(); | ||
| ArgumentsParser argumentsParser = new ArgumentsParser(); | ||
| RunOptions runOptions = argumentsParser.parse(args); | ||
|
|
||
| if (args.length == 0) { | ||
| launch(); | ||
| } | ||
| try { | ||
| RunOptions runOptions = argumentsParser.parse(args); | ||
| String content = fileManager.read(runOptions.getFilePath()); | ||
|
|
||
| if (runOptions.getCommand() == Command.ENCRYPT) { | ||
| String content = fileManager.read(runOptions.getFilePath()); | ||
| String encryptedContent = cypher.encrypt(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); | ||
| Path newFilePath = changeFileName.newFileName(runOptions, "ENCRYPTED"); | ||
| fileManager.write(newFilePath, cypher.encrypt(content, runOptions.getKey())); | ||
| } else if (runOptions.getCommand() == Command.DECRYPT) { | ||
|
|
||
| Path newFilePath = changeFileName.newFileName(runOptions, "DECRYPTED"); | ||
| fileManager.write(newFilePath, cypher.decrypt(content, runOptions.getKey())); | ||
| } else if (runOptions.getCommand() == Command.BRUTEFORCE) { | ||
|
|
||
| BruteForceResult result = cypher.bruteforce(content); | ||
| Path newFilePath = changeFileName.newFileNameWithKey(runOptions, "BRUTEFORCED", result.getKey()); | ||
| fileManager.write(newFilePath, result.getDecryptedContent()); | ||
| } | ||
| } catch (FileNotFoundException e) { | ||
| System.out.println("File not found"); | ||
| } catch (Exception e) { | ||
| System.out.println(e.getMessage()); | ||
| } | ||
| } |
Contributor
There was a problem hiding this comment.
It's always a good idea to keep the logic out of the main method.
| import java.nio.file.Path; | ||
| import java.util.ResourceBundle; | ||
|
|
||
| public class Controller implements Initializable { |
| @@ -0,0 +1,22 @@ | |||
| package ua.com.javarush.gnew.exeptions; | |||
|
|
|||
| public class FileNotFoundException extends RuntimeException { | |||
Contributor
There was a problem hiding this comment.
Own exception type. Cool 😎
Comment on lines
+7
to
+21
| public static final ArrayList<Character> ALPHABET_ENG = 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')); | ||
|
|
||
| private final ArrayList<Character> alphabet; | ||
| public static final ArrayList<Character> ALPHABET_UA = new ArrayList<>(Arrays.asList( | ||
| 'а', 'б', 'в', 'г', 'ґ', 'д', 'е', 'є', 'ж', 'з', 'и', 'і', 'ї', 'й', 'к', 'л', 'м', | ||
| 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'ь', 'ю', 'я')); | ||
|
|
||
| public static final ArrayList<Character> ALPHABET_ENG_UPPER = 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> ALPHABET_UA_UPPER = new ArrayList<>(Arrays.asList( | ||
| 'А', 'Б', 'В', 'Г', 'Ґ', 'Д', 'Е', 'Є', 'Ж', 'З', 'И', 'І', 'Ї', 'Й', 'К', 'Л', 'М', | ||
| 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ь', 'Ю', 'Я')); |
Contributor
There was a problem hiding this comment.
You could get rid of two lists for each language and process uppercase dynamically.
Contributor
There was a problem hiding this comment.
CSS Styles... Bravo 👏
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.