#include <cs50.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
int main(int argc, string argv[])
{
string a = argv[1];
int s = strlen(a);
int h = 0;
int k = 0;
if(argc != 2)
{
printf("No keyword entered.\n");
return 1;
}
do
{
if(!isalpha(a[h]))
{
printf("Keyword must be alphabetical.\n");
h = h - h + s;
k = k + 1;
return 1;
}
h = h + 1;
}while(h == s);
string t = GetString();
int i = 0;
for (int n = strlen(t); i < n; i++)
{
if(isalpha(t[i]))
{
if(isupper(t[i]))
{
int p = a[i];
p = p - 65;
int l = t[i];
l = l - 65;
int b = (l + p%s)%26;
b = b + 65;
char c = b;
printf("%c", c);
}
if(islower(t[i]))
{
int p = a[i];
p = p - 97;
int l = t[i];
l = l - 97;
int b = (l + p%s)%26;
b = b + 97;
char c = b;
printf("%c", c);
}
}
else
{
printf("%c", t[i]);
}
}
printf("\n");
}
I have no idea what is going on with this code. Here is check50 output. Any ideas?
:) vigenere.c exists
:) vigenere.c compiles
:( encrypts "a" as "a" using "a" as keyword
\ expected prompt for input, not output of "Keyword must be alphabetical.\n"
:( encrypts "world, say hello!" as "xoqmd, rby gflkp!" using "baz" as keyword
\ expected output, but not "xoskb, say igmjp!\n"
:( encrypts "BaRFoo" as "CaQGon" using "BaZ" as keyword
\ expected output, but not "CaSDmn\n"
:( encrypts "BARFOO" as "CAQGON" using "BAZ" as keyword
\ expected output, but not "CASDOP\n"
:( handles lack of argv[1]
\ expected output, not standard error of "/opt/sandbox50/bin/run.sh: line 31:
6..."
:) handles argc > 2
:( rejects "Hax0r2" as keyword
\ expected output, not a prompt for input
https://sandbox.cs50.net/checks/55b0306dc27646cbae4ab088d8834742