Repository navigation
rail-fence-cipher: add to track - #765
Conversation
|
Oh, now I'm confused; which PR is the most up-to-date, @LeonDsouza? I see this one includes those config changes I mentioned in your other PR. |
|
In order to fix the failing build, you need to add a folder src/main/java and put an empty .keep file in it in order for git to see it let you commit that folder. Otherwise, the build fails because the folder doesn't exist. Also, as a side note, it's perfectly fine to keep using the original pull request when you push new changes. Github adds any more pushed changes to the pull request, and it also allows you to edit the title when you like. Just using one pull request helps to keep out confusion :) |
Smarticles101
left a comment
There was a problem hiding this comment.
I left a few comments, most of them being minor. Thanks for your work on this @LeonDsouza sorry for the late review
| "difficulty": 1, | ||
| "topics": [ | ||
|
|
||
| ] |
There was a problem hiding this comment.
This should have an indent of 4 spaces.
| { | ||
| "slug": "rail-fence-cipher", | ||
| "core": true, | ||
| "unlocked_by": null, |
There was a problem hiding this comment.
Would you be able to estimate a difficulty and add topics? If not, we can open a separate issue for that once this gets merged.
There was a problem hiding this comment.
Also core should be false. We've already decided a set of core exercises and we probably don't want to add to them at this point. See this issue for our discussion about which exercises should be core exercises. Also this issue and this PR where we changed the config.json structure after finding out exercises should only be unlocked by core exercises.
If you want @LeonDsouza, you could look through the core exercises (listed in this PR) and choose want you think should unlock this one. But it can also be kept as "core": false and "unlocked_by": null :)
Let me know if any of that didn't make sense! :)
There was a problem hiding this comment.
I just found this document which explains very well what needs to be in this file (including uuid, unlocked_by and core) :)
| @Test | ||
| public void encodeWithThreeRails() { | ||
| railFenceCipher = new RailFenceCipher(3); | ||
| Assert.assertEquals("WECRLTEERDSOEEFEAOCAIVDEN", railFenceCipher.getEncryptedData("WEAREDISCOVEREDFLEEATONCE")); |
There was a problem hiding this comment.
These lines might be easier to read with each parameter on a different line.
| decrypted = buffer.toString().replaceAll(",", "").replaceAll("\\s+", "").replace("[", "").replace("]", ""); | ||
| return decrypted; | ||
| } | ||
| } |
There was a problem hiding this comment.
I don't have any comments on the example implementation. @FridaTveit usually does if she cares to look at it
There was a problem hiding this comment.
The most important thing is that this file should be in .meta/src/reference/java/ instead of src/example/java/. Sorry about that, it's been changed very recently :) You can look at the other exercises @LeonDsouza to make sure your folder structure matches theirs :)
|
Did those changes @Smarticles101 @stkent @FridaTveit. Got the build to succeed! 👍 |
FridaTveit
left a comment
There was a problem hiding this comment.
Thank you for making these changes @LeonDsouza! It's looking great :)
There are a couple of things to do with the config.json that still need changing. Let me know if you have any problems with that :)
I've also left a few comments on the example solution. Feel free to ignore them/disagree with me, they're only suggestions :)
| "conditionals" | ||
| ], | ||
| "unlocked_by":null, | ||
| "uuid":"8382f1c7-4ba4-4d6e-abe1-2d5a2519a11a" |
There was a problem hiding this comment.
Thank you for adding the difficulty, topics and and unlocked_by! :) It's looking great, thank you for taking the time to do that!
A couple of things:
- You've got unlocked_by twice, you only need it once.
- This should be moved to where the other exericses with difficulty 6 are in this array, e.g. before spiral-matrix.
- You've changed the spacing of everything in this file. That makes it hard to see which changes were actually yours and the spacing was fine as it was before. It would be great if you could change that back. Let me know if you have any problems with that :)
| railFence.add(number, temp + c); | ||
| number += increment; | ||
| } | ||
| String buffer = ""; |
| railFence.add(""); | ||
| } | ||
|
|
||
| int number = 0, increment = 1; |
There was a problem hiding this comment.
I find this a bit hard to follow. Using variables like number and increment makes it quite difficult to understand what you're doing since they don't describe what the variable actually is. From what I can tell number represents the currentRailNumber, so it should be named that :) It looks like you're using increment to increment the current rail number modulo the number of rails. To make that easier and more clear you could iterate over the characters with an old fashioned loop (so that you've got an index i) and then update the current rail number using:
currentRailNumber = i % numberOfRails
Does that make sense? Let me know if it doesn't or if you think it won't work :)
There was a problem hiding this comment.
I'm actually using the increment variable to know the extent of how far down or up i can go
There was a problem hiding this comment.
Okay. That still doesn't explain why it's called increment. The name of the variable should explain what you're using it for :)
| increment = 1; | ||
| } | ||
| String temp = railFence.get(number); | ||
| railFence.remove(number); |
There was a problem hiding this comment.
remove will return the item so you can do:
String currentCharacter = railFence.remove(number)
(I would also name it currentCharacter to make it more obvious what it is :) )
|
|
||
| String getDecryptedData(String cipherText) { | ||
| String decrypted; | ||
| ArrayList<ArrayList<Integer>> railFence = new ArrayList<>(noOfRails); |
There was a problem hiding this comment.
Is there any particular reason you're storing each rail as a list of integers? You could just store it as a string and append characters to it as you go through the ciphertext. That should make it easier to get the final output at the end :)
There was a problem hiding this comment.
I've stored it in a kind of matrix form for a 2 loop iteration
There was a problem hiding this comment.
Sure, but since you're dealing with characters it makes more sense to store it as characters rather than integers. You can have a list of strings and loop through the characters of each string.
And as a tip for the future, it would be really helpful if you could respond to reviews relatively soon after we do them. For big reviews like this it takes time for me to get into the mindset of the code and understand what you're doing. If you had made these comments a month ago when I first reviewed this code I would have been able to give way more useful answers. And I'm guessing it would be easier for you too to change your code right after you wrote it instead of more than a month after.
I know you're probably very busy with work and things, but in that case it might be easier for you to work on smaller issues rather than trying to implement a whole exercise? Like I said, this is just a suggestion for the future since PRs that remain open for months become really hard to review. But I do really appreciate you trying to help improve the track :)
| } | ||
| } | ||
|
|
||
| decrypted = buffer.toString().replaceAll(",", "").replaceAll("\\s+", "").replace("[", "").replace("]", ""); |
There was a problem hiding this comment.
Do you really need these replaces?
|
|
||
| int rowIncrementFactor = 0, step = 1; | ||
|
|
||
| for (int i = 0; i < cipherText.length(); ++i) { |
There was a problem hiding this comment.
Again, this is a bit hard to follow. Say you have n rails, then you want to go through the ciphertext and add each letter to the correct rail. You can find the correct rail by i % n I think. If i % n is 0 then you add it to the first rail, if i % n is 1 then you add it to the second rail. Does that make sense?
FridaTveit
left a comment
There was a problem hiding this comment.
You appear to have accidentally reverted all your changes to config.json which is why the build is failing. It was only the indentation changes I wanted you to revert, you still need to add the exercise to config.json as explained in the contribution guide. Let me know if you need any help with that or if you have any questions :)
|
Hi @LeonDsouza :) How's it going with this? :) |
|
Poke @LeonDsouza :) How's it going? If you're too busy to finish this one off, let us know and we'll carry it across the finish line. I wouldn't want your hard work so far to be wasted 😢 |
|
Seeing as this has been inactive a little while, does anyone mind if I pick it up and finish it off so this work isn't wasted? 🙂 As a sidenote, what normally happens with abandoned PRs? |
I think it's safe to do so at this point.
I'm not sure this has happened often enough for us to have a 'normal' response. We trialed running probot on the repository a while back, but that was mostly for support-related issues and it was missing features we needed. |
|
@sjwarner-bp It's as simple as cloning the branch that will be merged through the pull request and committing to it! :) |
|
Ok, so we have a passing build (I've updated |
FridaTveit
left a comment
There was a problem hiding this comment.
This is looking great, thanks for working on this @sjwarner-bp! :)
I've left some comments but there are only a few important things:
- The unlocked by exercise needs to be a core exercise
- The readme is missing I think
- I don't think the methods should be static
Apart from that it looks great! Thanks again for working on this! :)
| "loops", | ||
| "conditionals" | ||
| ], | ||
| "unlocked_by": "atbash-cipher", |
There was a problem hiding this comment.
atbash-cipher isn't a core exercise so it can't be unlocked by that. rotational-cipher would probably be a good exercise for it to be unlocked by? :)
| @@ -0,0 +1,64 @@ | |||
| public class RailFenceCipher { | |||
There was a problem hiding this comment.
This could be package private :)
| @@ -0,0 +1,64 @@ | |||
| public class RailFenceCipher { | |||
|
|
|||
| private static int key; | |||
There was a problem hiding this comment.
I don't think this or any of the methods should be static. Either all the methods are static and you pass in the key to each method, or the methods are all instance methods and you pass in the key to the constructor. Since we prefer instance methods according to our policies doc I would suggest the latter :)
|
|
||
| public static String getEncryptedData(String message) { | ||
| String[] lines = splitIntoLines(message, false); | ||
| String result = ""; |
There was a problem hiding this comment.
You could use a StringBuilder :)
| } | ||
| } | ||
|
|
||
| String result = ""; |
There was a problem hiding this comment.
Could use StringBuilder :)
| } | ||
|
|
||
| private static String[] generateEmptyStrings(int num) { | ||
| String[] strings = new String[num]; |
There was a problem hiding this comment.
Could you do:
String[] strings = new String[num];
Arrays.fill(strings, "");
return strings;
? :)
|
Oops! Silly mistakes - hopefully they're all fixed up now 🙂 |
FridaTveit
left a comment
There was a problem hiding this comment.
Looks great! Thanks for all your hard work @sjwarner-bp and @LeonDsouza! :)
Reviewer Resources:
Track Policies