Skip to content

Conversation

@RomanTsaruk
Copy link

No description provided.

Copy link
Contributor

@oleksandr-jr oleksandr-jr left a 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. 🙂

Comment on lines +35 to +61
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;
Copy link
Contributor

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

Comment on lines 20 to 35
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);
}
Copy link
Contributor

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.

Comment on lines +10 to +15
String label = switch (runOptions.getCommand()) {
case ENCRYPT -> " [ENCRYPTED]";
case DECRYPT -> " [DECRYPTED]";
case BRUTEFORCE -> " [BRUTEFORCE]";
default -> null;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants