-
Notifications
You must be signed in to change notification settings - Fork 16
Roman Tsaruk #12
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?
Roman Tsaruk #12
Conversation
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.
Some tests are still failing, but I believe you'll fix it.
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. 🙂
| for (int i = 1; i <= 25; i++) { | ||
| ArrayList<Character> rotatedAlphabet = new ArrayList<>(originalAlphabet); | ||
| Collections.rotate(rotatedAlphabet, i); | ||
| char[] charArray = input.toCharArray(); | ||
|
|
||
| StringBuilder builder = new StringBuilder(); | ||
| for (char symbol : charArray) { | ||
| builder.append(processSymbol(symbol, rotatedAlphabet)); | ||
| } | ||
| String output = builder.toString(); | ||
|
|
||
| int count = 0; | ||
| String[] words = output.split("\\s+"); | ||
| for (String word : words) { | ||
| if (engWords.contains(word.toLowerCase())) { | ||
| count++; | ||
| } | ||
| } | ||
|
|
||
| if (count > maxCount) { | ||
| maxCount = count; | ||
| key = i; | ||
| bestOutput = output; | ||
| } | ||
| } | ||
| Cypher.key = key; | ||
| return bestOutput; |
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 a little too complex. It might be simplified and split into methods. See more here
| try { | ||
| 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); | ||
| fileManager.write(pathManager.newFilePath(runOptions), encryptedContent); | ||
| } | ||
| if (runOptions.getCommand() == Command.DECRYPT) { | ||
| String content = fileManager.read(runOptions.getFilePath()); | ||
| String decryptedContent = cypher.decrypt(content, runOptions.getKey()); | ||
| fileManager.write(pathManager.newFilePath(runOptions), decryptedContent); | ||
| } | ||
| if (runOptions.getCommand() == Command.BRUTEFORCE) { | ||
| String content = fileManager.read(runOptions.getFilePath()); | ||
| String bruteForceContent = cypher.bruteForce(content); | ||
| fileManager.write(pathManager.newFilePath(runOptions), bruteForceContent); | ||
| } |
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 contains duplicates. See here how to fix it.
| String label = switch (runOptions.getCommand()) { | ||
| case ENCRYPT -> " [ENCRYPTED]"; | ||
| case DECRYPT -> " [DECRYPTED]"; | ||
| case BRUTEFORCE -> " [BRUTEFORCE]"; | ||
| default -> null; | ||
| }; |
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 solution.
No description provided.