Doing week 2 of CS50.Its supposed to be a ciphering algorithm. Ive gotten to the point where it ciphers my code BUT for some reason when I try testing my code and using my name, it doesnt make my second A char a lower cased a.
Key: NQXPOMAFTRHLZGECYJIUWSKDVB
Typing in: Armando
What I get–> ciphertext: NjzNgpe
What I want–> ciphertext: Njzngpe
#include <cs50.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
char alpha[] = {'A','B','C','D','E','F','G','H','I','J','K','L','M',
'N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
int cypher[] = {};
char new[] = {};
void cypher_s(string k);
void scramble(string s, int l);
int main(int argc, string argv[])
{
if (argc == 2)
{
string key = argv[1];
cypher_s(key);
string text = get_string("plaintext: ");
scramble(text, strlen(key));
}
else
{
printf("You suck, you need a command line argument or typed too manyn");
return 1;
}
}
void cypher_s(string k)
{
for (int i = 0; i < strlen(k); i++)
{
cypher[i] = k[i];
}
}
void scramble(string s, int l)
{
for (int i = 0; i < strlen(s); i++)
{
int position = 0;
for (int k = 0; k < l; k++)
{
if (s[i] == alpha[position])
{
printf("Capital %cn", s[i]);
new[i] = cypher[position];
position++;
}
else if (s[i] == tolower(alpha[position]))
{
printf("Lower %cn", s[i]);
new[i] = tolower(cypher[position]);
position++;
}
else
{
position++;
}
}
}
printf("ciphertext: ");
for (int j = 0; j < strlen(new); j++)
{
printf("%c", new[j]);
}
printf("n");
}