The Wayback Machine - https://web.archive.org/web/20200916132752/https://github.com/TheAlgorithms/C/pull/585
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

Cryptography using C #585

Open
wants to merge 17 commits into
base: master
from

Conversation

@Rishabhpatel803
Copy link

Rishabhpatel803 commented Jul 30, 2020

Description of Change

References

Checklist

  • Added description of change
  • Added file name matches File name guidelines
  • Relevant documentation/comments is changed or added
  • PR title follows semantic commit guidelines
  • I acknowledge that all my contributions will be made under the project's license.

Notes:

@Rishabhpatel803
Copy link
Author

Rishabhpatel803 commented Jul 30, 2020

All files are checked and tested on various platforms.

@kvedala
Copy link
Collaborator

kvedala commented Jul 30, 2020

Thank you for the contributions 👍

  1. No need to close an existing PR, we can continue working on the comments made there. This will ensure for the reviewers to know exactly what has been reviewed and the progress along with it.
  2. Please add appropriate documentation to the functions as in other files in the repo. See this file for an example on documenting the code for this repo. We are following the Doxygen standard for documentation.
  3. Please split the main function into atomic functions and implement one or more test() functions to auto-test the code using assert(). See this file for example.

This was mentioned in the PR description as one of the checklist for the authors. Please ensure the description is completed the checklist is followed.

Thank you

Copy link
Author

Rishabhpatel803 left a comment

Done changes

@kvedala

This comment was marked as outdated.

Copy link
Collaborator

kvedala left a comment

Thank you.
Can you please see the structure of the codes as below:

/**
 * @file 
 * @brief Add one line description here
 * @details 
 * This is a multi line
 * description containing links, references,
 * math equations, etc
 * @author [Name](https://github.com/handle)
 * @see related_file.c, another_file.c     <-- this line is optional
 */

#include 

/**
 * Structure documentation
 */
struct strct_name {
    int var1;  /**< short info of this variable */
    char *msg;  /**< short info */
};

/**
 * Function documentation 
 * @param param1 one-line info about param1
 * @param param2 one-line info about param2
 * @returns `true` if ...
 * @returns `false` if ... 
 */
bool func(*int param1, size_t param2) {
    // function statements here 
    if(/*something bad*/)
        return false;

    return true;
}

/** Test function
   * @returns None
   */
void test() {
 /* some statements */
 assert(func(...) == ...); // this ensures that the algorithm works as expected 

 // can have multiple checks
}

/** Main function
  * @returns 0 on clean exit
  * @returns nonzero on error.
  */
int main(int argc, char *argv[]) {
    // code here
    return 0;
}
@Rishabhpatel803
Copy link
Author

Rishabhpatel803 commented Aug 4, 2020

Added documentation to the code

@Rishabhpatel803
Copy link
Author

Rishabhpatel803 commented Aug 4, 2020

No need of test cases in code therefore not implemented test cases

@Rishabhpatel803 Rishabhpatel803 requested a review from kvedala Aug 4, 2020
@kvedala
Copy link
Collaborator

kvedala commented Aug 5, 2020

Thank you, @Rishabhpatel803
There is definitely a need of test cases. If you see the other programs in the folder, you will see the following steps to verify that the code works:

  1. Create one or more test string(s): "Hello World!"
  2. Encrypt it to some text "gibberish"
  3. decrypt this text back. By logic, the original string should be obtained verbatim. This is where you check using strcmp or similar and ensure using assert that the result is 0.
@Rishabhpatel803
Copy link
Author

Rishabhpatel803 commented Aug 5, 2020

Ok i will update it by tomorrow

@Rishabhpatel803
Copy link
Author

Rishabhpatel803 commented Aug 6, 2020

done adding test cases to the program

Copy link
Collaborator

kvedala left a comment

Well written code. Please review the suggestions and comments.

The code, lacks in the documentation standards. Please refer to the Doxygen standards and also my comment from above where I provided with a full snippet of documenting functions, function parameters, etc.

Thank you 👍

}
}
printf("\nEncrypted message: %s", msg);
decrypt(msg, key);

This comment has been minimized.

@kvedala

kvedala Aug 7, 2020

Collaborator

should not happen here.
Encrypt should only perform encryption

Also, it would be better to make the encrypt and decrypt functions atomic. The printf statements should be made by the calling function.

{
char msg[] = "Grofers";
printf("First Texst case");
encrypt(msg, 5);

This comment has been minimized.

@kvedala

kvedala Aug 7, 2020

Collaborator

This does not test the implementation. To test,

char *original_msg = "Gofers";
char msg[10];
strcpy(msg, original_msg); // retain original copy
int key = 5;

encrypt(msg, key);  // encrypt the text. 
decrypt(msg, key); // decrypt the text with the same key

assert(strcmp(msg, original_msg) == 0); // this will ensure that after encrypt and decrypt operations, the original message was obtained. This will fail if there is an error in the code.
#include <string.h>
#define MX 5

int choice;

This comment has been minimized.

@kvedala

kvedala Aug 7, 2020

Collaborator

Use of global variables is discouraged. Please pass variables as function arguments.

* designing the function of encryption and
* decryption using playfair cipher
*/
void playfair(char ch1, char ch2, char key[MX][MX]) {

This comment has been minimized.

@kvedala

kvedala Aug 7, 2020

Collaborator
Suggested change
void playfair(char ch1, char ch2, char key[MX][MX]) {
void playfair(char ch1, char ch2, char **key) {

Can the function be made better by allowing any size of keys and arrays? Not mandatory, but a suggestion.

#include <ctype.h>
#include <stdio.h>
#include <string.h>
#define MX 5

This comment has been minimized.

@kvedala

kvedala Aug 7, 2020

Collaborator

If using macros, please use descriptive names of at least 5 characters long. Something like KEY_SIZE?

{
char msg[] = "Playfair", key[] = "Good";
choice = 1;
printf("First Test Case");

This comment has been minimized.

@kvedala

kvedala Aug 7, 2020

Collaborator

Please refer to the suggestion made for the teaser cipher code on implementing a self-test funcition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.