I am writing an algorithm that encrypts text using a password word, Vigenère cipher. Upper and lower case characters should be encrypted, special characters, and numbers should be ignored. My questions:
- When you run the program, enter the password and then the text, the error Segmentation fault (recorded core image) occurs. Per What?
- The code is not working, how can I improve it?
code:
#include<cc50.h> // BIBLIOTECA DO CURSO QUE ESTOU FAZENDO.
#include<string.h>
#include<stdio.h>
int
main(int argc, char argv[])
{
if (argc != 2)
{
printf("Erro 1. Digite uma palavra na linha de comando.\n");
return 1;
}
printf("Texto a ser criptografado:\n");
string texto = GetString();
int k = 0;
int l = strlen(texto);
int m = strlen(argv);
for (int i = 0, j = 0; i < l; i++)
{
k = atoi(argv[j]);
if (j > m) // SE O CONTADOR J FOR MAIOR QUE A QUANTIDADE DE CARACTERES DA SENHA, REDEFINE J e K PARA 0.
{
j = 0;
k = 0;
}
else if (texto[i] >= 65 && texto[i] <= 90)
{
texto[i] = (((texto[i] - 65) + k) % 26) + 65;
j++;
}
else if (texto[i] >= 97 && texto[i] <= 122)
{
texto[i] = (((texto[i] - 97) + k) % 26) + 97;
j++;
}
else;
printf("%c", texto[i]);
}
printf("\n");
return 0;
}
It does not have to be a big answer, little tips that guide me the solution is good, since I'm already a few weeks stuck with this problem.