Skip to content

Conversation

@BevzyukIvan
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.

I can't run test. Please have a look and try to fix it.

@BevzyukIvan
Copy link
Author

BevzyukIvan commented Oct 19, 2024 via email

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.

Overall, looks good to me.

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 +23 to +60
try {
Arguments arguments = ArgumentParser.parse(args);

String content = FileManager.read(arguments.getFilePath());
String result;
String newFile;

EncryptionUtil encryptionUtil = new EncryptionUtil();
if (arguments.isEncryptionMode()) {
result = encryptionUtil.encrypt(content, arguments.getKey());
newFile = NewFileName.getNewFileName(arguments.getFilePath(), "[ENCRYPTED]");
} else if (arguments.isDecryptionMode()) {
result = encryptionUtil.decrypt(content, arguments.getKey());
newFile = NewFileName.getNewFileName(arguments.getFilePath(), "[DECRYPTED]");
} else if (arguments.isBruteForce()) {
if (arguments.hasFrequencyAnalysisFile()) {
String referenceContent = FileManager.read(arguments.getFrequencyAnalysisFilePath());
FrequencyAnalysis frequencyAnalysis = new FrequencyAnalysis();
result = frequencyAnalysis.analysis(content, referenceContent);
int foundKey = frequencyAnalysis.getKey_bf();
newFile = NewFileName.getNewFileName(arguments.getFilePath(), "[DECRYPTED_KEY_" + foundKey + "]");
System.out.println("Key found using frequency analysis: " + foundKey);
} else {
// Стандартний brute force
int key = new BruteForce().brute_force(content);
result = encryptionUtil.decrypt(content, key);
newFile = NewFileName.getNewFileName(arguments.getFilePath(), "[DECRYPTED]");
System.out.println("Key found using brute force: " + key);
}
}else {
throw new IllegalArgumentException("Invalid mode. Use '-e' for encryption, '-d' for decryption, or '-bf' for brute force.");
}

FileManager.write(newFile, result);
System.out.println("Operation completed successfully. Output file: " + newFile);
} catch (Exception e) {
e.printStackTrace();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks a little too complex. It could be split into a couple of separate methods. See more.

return key_bf;
}

public String analysis(String encryptedText, String referenceText) {
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, I like it.
This method also cad be simplified a bit to be more readable.

int result = 0;
int maxPopular = 0;

LanguageDetector languageStrategy = new CreateLanguage().createLanguageStrategy(s);
Copy link
Contributor

Choose a reason for hiding this comment

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

Calling this method using whole text might be uneffective.


private boolean isEnglish(String text) {
for (char c : text.toLowerCase().toCharArray()) {
if ("abcdefghijklmnopqrstuvwxyz".indexOf(c) != -1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What if the text is in Ukrainian but contains some English words?

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