I am attempting to make the vigenere cipher. Information about it is here: https://www.youtube.com/watch?v=9zASwVoshiM My code doesnt seem to work for a few cases. My code is listed below please dont send me a link how to make the vigenere cipher but instead a way to fix mine. If I put the key as z for example it is value 25 acc to alphabet. Now if I put the to be encrypted text as c which is 2 the new text is of value 27 and should show b but for me it doesn't. So if the value exceeds 25 it doesn't show what I want else it works. And for the actual output example: ab as key should change ca to cb
#include<stdio.h>
#include<cs50.h>
#include<ctype.h>
#include<string.h>
#include<stdlib.h>
int main( int argc , string argv[]){
//string plaintext;
string key;
if(argc != 2){
printf("Please run the programme again this time using a command line argument!\n");
return 1;
}
key = argv[1];
int keys[strlen(key)];
for(int m = 0; m< strlen(key);m++){
if(isalpha(key[m])==false){
printf("Re-Run The programme without any symbols.\n");
return 1;
}
}
for(int b = 0; b < strlen(key);b++){
if(isupper(key[b]) == false){
keys[b] = key[b] - 'a';
}
else{
keys[b] = key[b] - 'A';
}
}
//printf("Enter a string which should be encrypted: \n");
string plaintext = GetString();
int plength = strlen(plaintext);
int klength = strlen(key);
string ciphertext = key;
for(int u = 0; u<plength;u++){
if(isalpha(plaintext[u])==false){
printf("%c",plaintext[u]);
continue;
}
int value = u % klength;
ciphertext[u] = (keys[value] + plaintext[u]);
//By the more than 90 I am referring to 'z'
if(ciphertext[u]>90){
ciphertext[u] = ciphertext[u] ;
}
printf("%c",ciphertext[u]);
}
printf("\n");
return 0;
}
Thanks Kalyan