Skip to content
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

Refactor: redesign ColumnarTranspositionCipher #5223

Conversation

samuelfac
Copy link
Contributor

Related to #5164

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • All new code is formatted with clang-format -i --style=file path/to/your/file.java

@codecov-commenter
Copy link

codecov-commenter commented Jun 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 40.68%. Comparing base (8ea90fd) to head (f42f3ab).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #5223      +/-   ##
============================================
+ Coverage     40.35%   40.68%   +0.32%     
- Complexity     2486     2501      +15     
============================================
  Files           519      519              
  Lines         15479    15440      -39     
  Branches       2950     2943       -7     
============================================
+ Hits           6247     6282      +35     
+ Misses         8943     8867      -76     
- Partials        289      291       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@vil02
Copy link
Member

vil02 commented Jun 12, 2024

Please focus on #5221 first.

Samuel Facchinello added 2 commits June 12, 2024 17:13
@samuelfac samuelfac marked this pull request as ready for review June 12, 2024 15:29
for (int i = 0; i < sortedTable[0].length; i++) {
for (int j = 1; j < sortedTable.length; j++) {
wordEncrypted.append(sortedTable[j][i]);
public static String encrypt(String message, String key) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public static String encrypt(String message, String key) {
public static String encrypt(final String message, final String key) {

wordEncrypted.append(sortedTable[j][i]);
public static String encrypt(String message, String key) {
int numColumns = key.length();
int numRows = (int) Math.ceil((double) message.length() / numColumns);
Copy link
Member

Choose a reason for hiding this comment

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

This deserves a separate method, especially because it is used in decrypt.

for (int i = 1; i < table.length; i++) {
for (Object item : table[i]) {
wordDecrypted.append(item);
public static String decrypt(String message, String key) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public static String decrypt(String message, String key) {
public static String decrypt(final String message, final String key) {

Copy link
Contributor

Choose a reason for hiding this comment

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

hey, I am currently working on #5223, I think the decrypt method does not need any parameters, because we have included global variables to store the respective..

Comment on lines +13 to +32
@ParameterizedTest
@MethodSource("provideTestCases")
void encrypt(String key, String word) {
assertNotEquals(word, ColumnarTranspositionCipher.encrypt(word, key));
}

@ParameterizedTest
@MethodSource("provideTestCases")
void decrypt(String key, String word) {
String encrypted = ColumnarTranspositionCipher.encrypt(word, key);
assertEquals(word, ColumnarTranspositionCipher.decrypt(encrypted, key));
}

private static Stream<Arguments> provideTestCases() {
return Stream.of(Arguments.of("asd215", "This is a test of the Columnar Transposition Cipher"), //
Arguments.of("test123456", "test"), //
Arguments.of("my long secret pass 1234567890", "short message"), //
Arguments.of("secret", "My secret message") //
);
}
Copy link
Member

Choose a reason for hiding this comment

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

These tests check only that ColumnarTranspositionCipher.encrypt is not an identity and that encrypt is an inverse of decrypt. I would highly suggest to:

  • add the expected into the test cases, i.e. each test case should consists of message, key, encrypted.
  • remove the encrypt test (in its current form),
  • add test cases with empty word and/or key,
  • (as discussed earlier) remove the //

Copy link

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution!

@github-actions github-actions bot added the stale label Aug 11, 2024
Copy link

Please reopen this pull request once you have made the required changes. If you need help, feel free to ask in our Discord server or ping one of the maintainers here. Thank you for your contribution!

@github-actions github-actions bot closed this Aug 19, 2024
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.

4 participants