-
Notifications
You must be signed in to change notification settings - Fork 16
File manager #6
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?
File manager #6
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
left a comment
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.
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. 🙂
| 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); | ||
| } | ||
| } |
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.
Actually we already have similar method.
Character. isAlphabetic()
For punctuation, you could use Pattern.matches("\\p{IsPunctuation}", str)
| return sb.toString(); | ||
| } | ||
|
|
||
| public char MostFrequentChar(){ |
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.
I like the approach
| 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); | ||
| } |
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.
Contains duplicates. See here how to get rid of it.
|
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:
***@***.***>
--
С уважением. Сергей
|
No description provided.