• This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #221
    admin
    Keymaster

      Need to compare elements from argv[1] [0] to argv[1][26]//there are 26 alphabets (0 – 25) plus one for end of array.
      Check if
      1. check if argv[1][0] == argv[1][1]
      2. If yes,
      3. return 1,
      4. else goto line 1
      5. argv[1][0] == argv[1][1+1]
      6. till argv[1][0] == argv[1][1+25]
      7. // 26th alphabetic character argv[1][25] needs to be compared with argv[1][0]
      8. Next, continue with argv[1][0+1] till argv[1][25] with line 1.
      I believe, the above pseudocode will consider uppercase and lowercase characters different. That is okay for the time being though final project will need a different approach (uppercase plaintext will have ciphertext in upper).
      Seeking guidance if the above is okay or needs correction.


      Reply


       

      Why not use the toupper() or tolower() function to get rid of case consideration. Otherwise the pseudocode seems fine. Ultimately leading to two loops.


      Query

      While the code could now spot duplicate keys, the next task is to ‘get rid of case consideration’.

      Your advice to use either toupper() or tolower() means either all the keys to be converted to uppercase or lowercase?

      
      
      for (int i = 0; i < 25; i++)
      {
          for (int j = i; j < 25; j++)
          {
              if(argv[1][j] == argv[1][j+1])
              {
              printf("keys should be unique");
              return 1;
              }
          }
      }


      Reply


      exactly


      Query


      Here is how I tried to convert all characters to uppercase:

      
      
      for (int i = 0; i < 25; i++)
          {
          for (int j = i; j < 25; j++)
          {
          argv[1][j] = toupper(argv[1][j]);
              if(argv[1][j] == argv[1][j+1])
              {
              printf("keys should be unique");
              return 1;
              }
          }
      }


      Query


      With the above code, the program is compiling. I tried to check actual conversion to uppercase with printf:

      
      
      for (int i = 0; i < 25; i++)
      {
          for (int j = i; j < 25; j++)
          {
          argv[1][j] = toupper(argv[1][j]);
          printf("%s",argv[1][j]);
              if(argv[1][j] == argv[1][j+1])
              {
              printf("keys should be unique");
              return 1;
              }
          }
      }

      Getting format error.


      Reply


      printf(“%s”,argv[1][j]);

      agrv is a string while argv[j] is a character. You should be using %c


      Query


      Though not part of the Substitution project, yet came across this scenario: The variable s of string type intended to be converted to uppercase.

      string s = get_string(“plaintext: “);

      s = toupper(s);

      Is it not correct ?


      Reply


      again s is a string. toupper() works on chars


      Reply


      https://edstem.org/us/courses/176/discussion/1152834?comment=2624763[learn_press_profile]

    Viewing 1 post (of 1 total)
    • You must be logged in to reply to this topic.
    Scroll to Top