-
Notifications
You must be signed in to change notification settings - Fork 16
Finished project of the first module #10
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
Create method ChandeFileName
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.
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. 🙂
| <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> | ||
|
|
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.
Having a UI interface is really cool.
| 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()); | ||
| } | ||
| } |
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 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 { |
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
| @@ -0,0 +1,22 @@ | |||
| package ua.com.javarush.gnew.exeptions; | |||
|
|
|||
| public class FileNotFoundException extends RuntimeException { | |||
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.
Own exception type. Cool 😎
| 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( | ||
| 'А', 'Б', 'В', 'Г', 'Ґ', 'Д', 'Е', 'Є', 'Ж', 'З', 'И', 'І', 'Ї', 'Й', 'К', 'Л', 'М', | ||
| 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ь', 'Ю', 'Я')); |
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 for each language and process uppercase dynamically.
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.
CSS Styles... Bravo 👏
No description provided.