• This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #211
    admin
    Keymaster
      
      
      #include
      #include
      #include
      #include
      #include
      int main(int argc, string argv[])
      {
      int counter = 0;
          if (argc != 2)
          {
          return 1;
          }
          else
          {
          printf("enter plainkey: ");
          }
      string key = argv[1];
      int t = strlen(key);
          if(t != 26)
          {
          return 1;
          }
         while(counter < t)
          {
          isdigit (argv[1][counter]);
          return 1;
          counter = counter + 1;
          }
      string s = get_string("plaintext: ");
      int countstring = strlen(s);//count the number of characters entered by the user as plaintext
           for(int i = 0; i <= countstring; i++)//starts with first character of plaintext till the end
          {
              if (isalpha s)//if character is alphabetic
              {
              int s= argv[1];//replace index value of alphabetic character with the same position of key array
              }
              else
              {
              s = s;//if not alphabetic, then the entered character remains the same
              }
          }
      printf("ciphertext: %s",s);
      }
      
      
      
      

      What I intend to do is to check one-by-one if entered character as part of plaintext is alphabetic or not. If not alphabetic, then the output in ciphertext remains the same. If alphabetic, then the ASCII value of that alphabet is replaced with the key array value in that position.
      If I have failed to explain, kindly let me know so that I try to rephrase.


       Reply


      Details matter 🙂

      
      

      Here you forgot the () to use s as argument to isalpha:

      As I understand from the other comments here, you have already moved on to use isupper and islower here instead, good choice.

      Another thing is that in this pset you want to make sure that the key is all alphabetic and has no duplicates and has exactly 26 characters. You do check for 26 characters but you are not checking for duplicates and alphabetic.

      Unlike in caesar we don’t care if a character is a digit. There are other characters than digits that are not alphabetic. For example @#$%^& and more 🙂 So maybe isalpha can be useful afterall, just not where you used it before 🙂


      I think that isalpha should not be used here. Use isupper and islower directly because isalpha will add clutter to your code.

      If you’ll see at Substitution > Background, you’ll see that code should output small letter if it’s lowercase, and big letter if it’s uppercase.

      And small hint from me: make function for encryption that will take letter and key.


      The program should check if input meets requirements:

      • Only one input (you can use argc for that)

      • Check if key is made only from letters and is {some number} long

      If there’s different number of inputs, then output “Usage: ./substitution key”

      If there’s good number of input (1), check if key is correct. If key is not correct, output “Key must contain 26 characters.” If key is correct, do encryption (plaintext > ciphertext)

      Edit: I see that you added this, but you need to add printf statements to make it work the way it intended to work. It might help you with fixing code. If program is stuck on some point, try to find the bug

      Good luck 🤞

      [learn_press_profile]

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