Skip to content

Update Caesar.java - #412

Merged
christianbender merged 3 commits into
TheAlgorithms:masterfrom
cyberkhalil:master
Apr 12, 2018
Merged

christianbender merged 3 commits into
TheAlgorithms:masterfrom
cyberkhalil:master

Conversation

@cyberkhalil

@cyberkhalil cyberkhalil commented Apr 9, 2018 •

Copy link
Copy Markdown
Contributor

changes :-
*fix documentation
*methods (encode,decode) can take any number of shifts now and better performed.

@christianbender christianbender left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good Work! I have some requests.

Comment thread ciphers/Caesar.java Outdated
// int current = message.charAt(i); //using char to shift characters because ascii is in-order latin alphabet
char current = message.charAt(i); // Java law : char + int = char

if (current >= 'A' && current <= 'Z') {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Instead of this complex if use Character.isLetter(c) see here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Character.isLetter(c) method return true if the input was 'ф' or 'أ' or '褥' while we don't shift them in this method , it's just for shifting Latin letters .

Comment thread ciphers/Caesar.java Outdated
final int length = encryptedMessage.length();
for (int i = 0; i < length; i++) {
char current = encryptedMessage.charAt(i);
if (current >= 'A' && current <= 'Z') {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Same thing as above.

Comment thread ciphers/Caesar.java Outdated
int shift = input.nextInt() % 26;
System.out.println("(E)ncode or (D)ecode ?");
char choice = input.next().charAt(0);
if (choice == 'E' || choice == 'e') {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Here you can simpler use a switch

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thanks for advice here 👍

@christianbender
christianbender merged commit 2d5a9b1 into TheAlgorithms:master Apr 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants