Hi there trying to make a text cipher for cs50 ( coding beginner) , i didn't want to cheat and watch a guide . i Thought i had figured out a solution but i am getting unexpected behaviour.
the program takes a command line argument i.e the key for the cipher
followed by the message to be encrypted
i am subtracting the key from the regular alphabet to get the distance between ascii characters so i can then re apply the distance to the the message in order to encrypt it as per the key.
i have double checked the math and the distance is calculated properly yet upon re applying it something is going wrong and i cant figure out what.
string message = get_string("Plaintext :");
int meslen = strlen(message);
for(int i=0;i<meslen;i++){
if(isupper(message[i])){
message[i]+=32;
for(int a=0; a<alphlen;a++){
if(message[i]==alphabet[a]){
message[i]= message[i]-alphdiff[a];
}
else{}
}
message[i]-=32;
}
else if(islower(message[i])){
for(int a=0; a<alphlen;a++){
if(message[i]==alphabet[a]){
message[i]=message[i]-alphdiff[a];
}
else{}
}
}
else{message[i]=message[i];}
}
printf("%s",message);
}

