I have included the part of my cypher responsilble for converting a command line keyword into an array of integers that will indicate by how much each character in a phrase should be shifted in encryption. Ideally, if I enter 'a' as the keyword and 'a' as the phrase to be encrypted, the resulting encryption should be 'b'. As of now though, I get 'K'.
I have included a printf check to see how much the keyword is shifting the phrase, which for the above circumstances is a shift of -48. It should be a shift of 1.
Can anyone tell me how I messed up? I've been trying to figure this out for quite a while.
//prompt the user for a non-neg integer 'k' which is to be used as
//an arg
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <cs50.h>
int main (int argc, char *argv[])
{
if (argc!=2) //fail if 0 or more than one key
{
printf ("PROVIDE JUST ONE COMMAND LINE ARGUMENT\n");
return 1;
}
int keylength=strlen(argv[1]); // get length of keyword
int newkey[keylength];
//deal with upper and lower case chars in keyword first
for (int j=0; j<keylength; j++) //iterate through each char in key
{
if (islower(argv[1][j])) //if key char is lower case...
{
int x = (argv[1][j])-'0';
int y = x-97;
newkey[j]= y;
}
if (isupper(argv[1][j])) //if key char is upper case...
{
int x = (argv[1][j])-'0';
int y = x-65;
newkey[j]=y;
}
}
printf ("%i\n", newkey[0]);