Is it right or am I doing something wrong? If so, what? The goal is to encrypt a user given message using a key given as a command line argument:
Code:
// Vignere
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <typec.h>
int main (int argc, char* argv[]){
void encryptor (char k[], char string[2000]);
int sizeofa = strlen(argv);
int k[sizeofa] = argv[];
char phrase2e[2000];
if (argc != 2 || k < 0) {
printf("give me ONLY one positive int\n");
return 1;
}
else
printf("please give me a phrase to encrypt\n");
gets(phrase2e);
encryptor(k, phrase2e);
return 0;
}
void encryptor (char k[],char string[]) {
for (int i = 0, n = strlen(string); i < n; i++)
for (int j = 0, m = strlen(k); j < m; j++)
{
if (isalpha(string[i]) {
string[i] = string[i] + k[j];
printf("%c", string[i])
}
else {
printf("%c", string[i]);
j--;
}
if (j = m - 1)
j = 0;
}
}