Open
Conversation
# Conflicts: # readme.md
delete classes Encrypt.java and Decrypt.java
delete classes Encrypt.java and Decrypt.java
and renaming in SymbolsBelonging.java
# Conflicts: # src/main/java/ua/com/javarush/gnew/Main.java # src/main/java/ua/com/javarush/gnew/crypto/Decrypt.java # src/main/java/ua/com/javarush/gnew/crypto/Encrypt.java # src/main/java/ua/com/javarush/gnew/crypto/KeyManager.java # src/main/java/ua/com/javarush/gnew/crypto/SymbolsBelonging.java # src/main/java/ua/com/javarush/gnew/file/FileManager.java
added the MostFrequentChar method (also for brute force)
oleksandr-jr
approved these changes
Oct 19, 2024
Contributor
oleksandr-jr
left a comment
There was a problem hiding this comment.
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
+5
to
+18
| public class SymbolsBelonging { | ||
| protected Character symbolsBelongingABC(char symbol, ArrayList<Character> rotateAlphabet) { | ||
| int index = ConstantsForCryptor.ALPHABET.getCharsArrayConstant().indexOf(Character.toUpperCase(symbol)); | ||
| if(Character.isLowerCase(symbol)){ | ||
| return Character.toLowerCase(rotateAlphabet.get(index)); | ||
| } | ||
| return rotateAlphabet.get(index); | ||
| } | ||
|
|
||
| protected Character symbolsBelongingPUNCTUATION(char symbol, ArrayList<Character> rotatePunctuation){ | ||
| int index = ConstantsForCryptor.PUNCTUATION.getCharsArrayConstant().indexOf(symbol); | ||
| return rotatePunctuation.get(index); | ||
| } | ||
| } |
Contributor
There was a problem hiding this comment.
Actually we already have similar method.
Character. isAlphabetic()
For punctuation, you could use Pattern.matches("\\p{IsPunctuation}", str)
| return sb.toString(); | ||
| } | ||
|
|
||
| public char MostFrequentChar(){ |
Comment on lines
+21
to
32
| if(runOptions.getCommand() == Command.ENCRYPT || runOptions.getCommand() == Command.DECRYPT){ | ||
| int key = keyManager.getKey(runOptions); | ||
| cryptor = new Cryptor(content, key); | ||
| String cryptoContent = cryptor.cypher(); | ||
| NewFileNamePath path = new NewFileNamePath(); | ||
| fileManager.write(path.newPath(runOptions) , cryptoContent); | ||
| } else if (runOptions.getCommand() == Command.BRUTEFORCE) { | ||
| cryptor = new Cryptor(content, keyManager.keySelection(runOptions)); | ||
| String cryptoContent = cryptor.cypher(); | ||
| NewFileNamePath path = new NewFileNamePath(); | ||
| fileManager.write(path.newPath(runOptions) , cryptoContent); | ||
| } |
Contributor
There was a problem hiding this comment.
Contains duplicates. See here how to get rid of it.
Author
|
Thank you for teaching👍
сб, 19 окт. 2024 г. в 16:37, oleksandr-jr ***@***.***>:
… ***@***.**** approved this pull request.
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. 🙂
------------------------------
In src/main/java/ua/com/javarush/gnew/crypto/SymbolsBelonging.java
<#6 (comment)>
:
> +public class SymbolsBelonging {
+ protected Character symbolsBelongingABC(char symbol, ArrayList<Character> rotateAlphabet) {
+ int index = ConstantsForCryptor.ALPHABET.getCharsArrayConstant().indexOf(Character.toUpperCase(symbol));
+ if(Character.isLowerCase(symbol)){
+ return Character.toLowerCase(rotateAlphabet.get(index));
+ }
+ return rotateAlphabet.get(index);
+ }
+
+ protected Character symbolsBelongingPUNCTUATION(char symbol, ArrayList<Character> rotatePunctuation){
+ int index = ConstantsForCryptor.PUNCTUATION.getCharsArrayConstant().indexOf(symbol);
+ return rotatePunctuation.get(index);
+ }
+}
Actually we already have similar method.
Character. isAlphabetic()
For punctuation, you could use Pattern.matches("\\p{IsPunctuation}", str)
------------------------------
In src/main/java/ua/com/javarush/gnew/crypto/Cryptor.java
<#6 (comment)>
:
> +
+ StringBuilder sb = new StringBuilder();
+ SymbolsBelonging symBel = new SymbolsBelonging();
+ for(char symbol : charsArray) {
+ if(ConstantsForCryptor.ALPHABET.getCharsArrayConstant().contains(Character.toUpperCase(symbol))){
+ sb.append(symBel.symbolsBelongingABC(symbol, rotator.rotateAlphabet(key)));
+ }else if (ConstantsForCryptor.PUNCTUATION.getCharsArrayConstant().contains(symbol)) {
+ sb.append(symBel.symbolsBelongingPUNCTUATION(symbol, rotator.rotatePunctuation(key)));
+ }else {
+ sb.append(symbol);
+ }
+ }
+ return sb.toString();
+ }
+
+ public char MostFrequentChar(){
I like the approach
------------------------------
In src/main/java/ua/com/javarush/gnew/Main.java
<#6 (comment)>
:
> + if(runOptions.getCommand() == Command.ENCRYPT || runOptions.getCommand() == Command.DECRYPT){
+ int key = keyManager.getKey(runOptions);
+ cryptor = new Cryptor(content, key);
+ String cryptoContent = cryptor.cypher();
+ NewFileNamePath path = new NewFileNamePath();
+ fileManager.write(path.newPath(runOptions) , cryptoContent);
+ } else if (runOptions.getCommand() == Command.BRUTEFORCE) {
+ cryptor = new Cryptor(content, keyManager.keySelection(runOptions));
+ String cryptoContent = cryptor.cypher();
+ NewFileNamePath path = new NewFileNamePath();
+ fileManager.write(path.newPath(runOptions) , cryptoContent);
}
Contains duplicates. See here
<https://refactoring.guru/uk/smells/duplicate-code> how to get rid of it.
—
Reply to this email directly, view it on GitHub
<#6 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AV6ZO45QPMAVDYPRBILNJSTZ4JOAVAVCNFSM6AAAAABNQ6HVX6VHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDGNZZGQZTOOBTHA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
--
С уважением. Сергей
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.