Skip to content

Conversation

@DenysBurduzhan
Copy link

@DenysBurduzhan DenysBurduzhan commented Sep 6, 2024

Ready to review

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.

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 {
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 job here.

Comment on lines 24 to 54
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");
}
}
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 complicated and contains duplicates.
Could be simplified. See more here.

Comment on lines +27 to +63
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();
Copy link
Contributor

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 {
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 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

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants