Skip to main content
deleted 41 characters in body
Source Link
#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <stdlib.h> //for converting argv to int
#include <ctype.h> //for isalpha function


int main (int argc, string argv[])  
{
    if (argc != 2)
    {
        printf("missing the key\n");
        return 1;
    }
    
    char* key = argv[1];
    
    for (int k = 0; k < strlen(key); k++) //check every char in key
    {
        if (!isalpha(key[k]))
        {
            printf("key should be the alphabetical\n");
            return 1;
        }
    }
    
    printf("plaintext: ");
    char *s = get_string();
    char *vc = s; //vigenere cipher
    
    int j;

    for (j = 0; j < strlen(s); j++) //qty of chars in string
            {
                j = j % strlen(key); //to loop the key word through string
            }
    
    if (s != NULL)
    {
        for (int i = 0; i < strlen(s); i++) 
            {
                if (isalpha(s[i])) //if chars are alphabet
                {
                    if (islower (s[i])) //if alpabet chars is lowerc
                    {
                         if (s[i] + key[j] > 122)
                         {
                             s[i] = s[i] - 26;
                         }
                    printf("%c", s[i] + key[j]);
                    }
                
                    else if (isupper (s[i])) //if alpabet chars is uppercase
                    {
                         if (s[i] + key[j] > 90)
                         {
                             s[i] = s[i] - 26;
                         }
                    printf("%c", s[i] + key[j]);
                    }
                }
                else
                {
                    printf("%c", s[i]);
                }
            }
        printf("\n");  
    }
    return 0;
}
#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <stdlib.h> //for converting argv to int
#include <ctype.h> //for isalpha function


int main (int argc, string argv[])  
{
    if (argc != 2)
    {
        printf("missing the key\n");
        return 1;
    }
    
    char* key = argv[1];
    
    for (int k = 0; k < strlen(key); k++) //check every char in key
    {
        if (!isalpha(key[k]))
        {
            printf("key should be the alphabetical\n");
            return 1;
        }
    }
    
    printf("plaintext: ");
    char *s = get_string();
    char *vc = s; //vigenere cipher
    
    int j;

    for (j = 0; j < strlen(s); j++) //qty of chars in string
            {
                j = j % strlen(key); //to loop the key word through string
            }
    
    if (s != NULL)
    {
        for (int i = 0; i < strlen(s); i++) 
            {
                if (isalpha(s[i])) //if chars are alphabet
                {
                    if (islower (s[i])) //if alpabet chars is lowerc
                    {
                         if (s[i] + key[j] > 122)
                         {
                             s[i] = s[i] - 26;
                         }
                    printf("%c", s[i] + key[j]);
                    }
                
                    else if (isupper (s[i])) //if alpabet chars is uppercase
                    {
                         if (s[i] + key[j] > 90)
                         {
                             s[i] = s[i] - 26;
                         }
                    printf("%c", s[i] + key[j]);
                    }
                }
                else
                {
                    printf("%c", s[i]);
                }
            }
        printf("\n");  
    }
    return 0;
}
#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <stdlib.h> //for converting argv to int
#include <ctype.h> //for isalpha function


int main (int argc, string argv[])  
{
    if (argc != 2)
    {
        printf("missing the key\n");
        return 1;
    }
    
    char* key = argv[1];
    
    for (int k = 0; k < strlen(key); k++) //check every char in key
    {
        if (!isalpha(key[k]))
        {
            printf("key should be the alphabetical\n");
            return 1;
        }
    }
    
    printf("plaintext: ");
    char *s = get_string();
    
    int j;

    for (j = 0; j < strlen(s); j++) //qty of chars in string
            {
                j = j % strlen(key); //to loop the key word through string
            }
    
    if (s != NULL)
    {
        for (int i = 0; i < strlen(s); i++) 
            {
                if (isalpha(s[i])) //if chars are alphabet
                {
                    if (islower (s[i])) //if alpabet chars is lowerc
                    {
                         if (s[i] + key[j] > 122)
                         {
                             s[i] = s[i] - 26;
                         }
                    printf("%c", s[i] + key[j]);
                    }
                
                    else if (isupper (s[i])) //if alpabet chars is uppercase
                    {
                         if (s[i] + key[j] > 90)
                         {
                             s[i] = s[i] - 26;
                         }
                    printf("%c", s[i] + key[j]);
                    }
                }
                else
                {
                    printf("%c", s[i]);
                }
            }
        printf("\n");  
    }
    return 0;
}
I change key checking
Source Link
#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <stdlib.h> //for converting argv to int
#include <ctype.h> //for isalpha function


int main (int argc, string argv[])  
{
    if (argc != 2)
    {
        printf("missing the key\n");
        return 1;
    }
    
    char* key = argv[1];
    
    for (int k = 0; k < strlen(key); k++) //check every char in key
    {
        if (!isalpha(key[0]key[k]))
        {
            printf("key should be the alphabetical\n");
            return 1;
        }
    }
    char* 
 s   printf("plaintext: ");
    char *s = GetStringget_string();
    char *vc = s; //vigenere cipher
    
    int j;

    for (j = 0; j < strlen(s); j++) //qty of chars in string
            {
                j = j % strlen(key); //to loop the key word through string
            }
    
    if (s != NULL)
    {
        for (int i = 0; i < strlen(s); i++) 
            {
                if (isalpha(s[i])) //if chars are alphabet
                {
                    if (islower (s[i])) //if alpabet chars is lowerc
                    {
                         if (s[i] + key[j] > 122)
                         {
                             s[i] = s[i] - 26;
                         }
                    printf("%c", s[i] + key[j]);
                    }
                
                    else if (isupper (s[i])) //if alpabet chars is uppercase
                    {
                         if (s[i] + key[j] > 90)
                         {
                             s[i] = s[i] - 26;
                         }
                    printf("%c", s[i] + key[j]);
                    }
                }
                else
                {
                    printf("%c", s[i]);
                }
            }
        printf("\n");  
    }
    return 0;
}
#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <stdlib.h> //for converting argv to int
#include <ctype.h> //for isalpha function


int main (int argc, string argv[])  
{
    if (argc != 2)
    {
        printf("missing the key\n");
        return 1;
    }
    
    char* key = argv[1];
    
    if (!isalpha(key[0]))
    {
        printf("key should be the alphabetical\n");
        return 1;
    }
    
    char* s = GetString();
    int j;

    for (j = 0; j < strlen(s); j++) //qty of chars in string
            {
                j = j % strlen(key); //to loop the key word through string
            }
    
    if (s != NULL)
    {
        for (int i = 0; i < strlen(s); i++) 
            {
                if (isalpha(s[i])) //if chars are alphabet
                {
                    if (islower (s[i])) //if alpabet chars is lowerc
                    {
                         if (s[i] + key[j] > 122)
                         {
                             s[i] = s[i] - 26;
                         }
                    printf("%c", s[i] + key[j]);
                    }
                
                    else if (isupper (s[i])) //if alpabet chars is uppercase
                    {
                         if (s[i] + key[j] > 90)
                         {
                             s[i] = s[i] - 26;
                         }
                    printf("%c", s[i] + key[j]);
                    }
                }
                else
                {
                    printf("%c", s[i]);
                }
            }
        printf("\n");  
    }
    return 0;
}
#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <stdlib.h> //for converting argv to int
#include <ctype.h> //for isalpha function


int main (int argc, string argv[])  
{
    if (argc != 2)
    {
        printf("missing the key\n");
        return 1;
    }
    
    char* key = argv[1];
    
    for (int k = 0; k < strlen(key); k++) //check every char in key
    {
        if (!isalpha(key[k]))
        {
            printf("key should be the alphabetical\n");
            return 1;
        }
    }
     
    printf("plaintext: ");
    char *s = get_string();
    char *vc = s; //vigenere cipher
    
    int j;

    for (j = 0; j < strlen(s); j++) //qty of chars in string
            {
                j = j % strlen(key); //to loop the key word through string
            }
    
    if (s != NULL)
    {
        for (int i = 0; i < strlen(s); i++) 
            {
                if (isalpha(s[i])) //if chars are alphabet
                {
                    if (islower (s[i])) //if alpabet chars is lowerc
                    {
                         if (s[i] + key[j] > 122)
                         {
                             s[i] = s[i] - 26;
                         }
                    printf("%c", s[i] + key[j]);
                    }
                
                    else if (isupper (s[i])) //if alpabet chars is uppercase
                    {
                         if (s[i] + key[j] > 90)
                         {
                             s[i] = s[i] - 26;
                         }
                    printf("%c", s[i] + key[j]);
                    }
                }
                else
                {
                    printf("%c", s[i]);
                }
            }
        printf("\n");  
    }
    return 0;
}
added 313 characters in body
Source Link
MARS
  • 5.2k
  • 3
  • 14
  • 23

stdio.h cs50.h string.h stdlib.h //for converting argv to int ctype.h //for isalpha function

int main (int argc, string argv[])
{ if (argc != 2) { printf("missing the key\n"); return 1; }

#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <stdlib.h> //for converting argv to int
#include <ctype.h> //for isalpha function


int main (int argc, string argv[])  
{
    if (argc != 2)
    {
        printf("missing the key\n");
        return 1;
    }
    
    char* key = argv[1];
    
    if (!isalpha(key[0]))
    {
        printf("key should be the alphabetical\n");
        return 1;
    }
    
    char* s = GetString();
    int j;

    for (j = 0; j < strlen(s); j++) //qty of chars in string
            {
                j = j % strlen(key); //to loop the key word through string
            }
    
    if (s != NULL)
    {
        for (int i = 0; i < strlen(s); i++) 
            {
                if (isalpha(s[i])) //if chars are alphabet
                {
                    if (islower (s[i])) //if alpabet chars is lowerc
                    {
                         if (s[i] + key[j] > 122)
                         {
                             s[i] = s[i] - 26;
                         }
                    printf("%c", s[i] + key[j]);
                    }
                
                    else if (isupper (s[i])) //if alpabet chars is uppercase
                    {
                         if (s[i] + key[j] > 90)
                         {
                             s[i] = s[i] - 26;
                         }
                    printf("%c", s[i] + key[j]);
                    }
                }
                else
                {
                    printf("%c", s[i]);
                }
            }
        printf("\n");  
    }
    return 0;
}

}

stdio.h cs50.h string.h stdlib.h //for converting argv to int ctype.h //for isalpha function

int main (int argc, string argv[])
{ if (argc != 2) { printf("missing the key\n"); return 1; }

char* key = argv[1];

if (!isalpha(key[0]))
{
    printf("key should be the alphabetical\n");
    return 1;
}

char* s = GetString();
int j;

for (j = 0; j < strlen(s); j++) //qty of chars in string
        {
            j = j % strlen(key); //to loop the key word through string
        }

if (s != NULL)
{
    for (int i = 0; i < strlen(s); i++) 
        {
            if (isalpha(s[i])) //if chars are alphabet
            {
                if (islower (s[i])) //if alpabet chars is lowerc
                {
                     if (s[i] + key[j] > 122)
                     {
                         s[i] = s[i] - 26;
                     }
                printf("%c", s[i] + key[j]);
                }
            
                else if (isupper (s[i])) //if alpabet chars is uppercase
                {
                     if (s[i] + key[j] > 90)
                     {
                         s[i] = s[i] - 26;
                     }
                printf("%c", s[i] + key[j]);
                }
            }
            else
            {
                printf("%c", s[i]);
            }
        }
    printf("\n");  
}
return 0;

}

#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <stdlib.h> //for converting argv to int
#include <ctype.h> //for isalpha function


int main (int argc, string argv[])  
{
    if (argc != 2)
    {
        printf("missing the key\n");
        return 1;
    }
    
    char* key = argv[1];
    
    if (!isalpha(key[0]))
    {
        printf("key should be the alphabetical\n");
        return 1;
    }
    
    char* s = GetString();
    int j;

    for (j = 0; j < strlen(s); j++) //qty of chars in string
            {
                j = j % strlen(key); //to loop the key word through string
            }
    
    if (s != NULL)
    {
        for (int i = 0; i < strlen(s); i++) 
            {
                if (isalpha(s[i])) //if chars are alphabet
                {
                    if (islower (s[i])) //if alpabet chars is lowerc
                    {
                         if (s[i] + key[j] > 122)
                         {
                             s[i] = s[i] - 26;
                         }
                    printf("%c", s[i] + key[j]);
                    }
                
                    else if (isupper (s[i])) //if alpabet chars is uppercase
                    {
                         if (s[i] + key[j] > 90)
                         {
                             s[i] = s[i] - 26;
                         }
                    printf("%c", s[i] + key[j]);
                    }
                }
                else
                {
                    printf("%c", s[i]);
                }
            }
        printf("\n");  
    }
    return 0;
}
deleted 14 characters in body
Source Link
Loading
Source Link
Loading