Я пытаюсь зашифровать и расшифровать сообщение, используя кодовую фразу и квадрат vigenere, хранящийся в массиве. Я могу зашифровать сообщение успешно, но я не могу решить, как его расшифровать после этого. Есть идеи?Расширение Vigenere Square в C
#include <stdio.h>
#include <string.h>
#include <ctype.h>
void encrypt(char *text, char *pass, int n, int m, char *vs);
void decrypt(char *text, char *pass, int n, int m, char *vs);
void vigsq(char *vs);
main()
{
char text[] = "HELLOWORLD";
char pass[] = "MAGIC";
int n, m;
char vs[26*26];
char *vsPointer, *textPointer, *passPointer;
char command;
char inputfile[10];
char outputfile[10];
//printf("Please enter e/d, pass phrase, input file, output file:");
//scanf("%c, %s, %s, %s", &command, &pass, &inputfile, &outputfile);
vsPointer = vs;
textPointer = text;
passPointer = pass;
vigsq(vsPointer);
//printf("%c, %s, %s, %s\n", command, pass, inputfile, outputfile);
n = strlen(text);
m = strlen(pass);
//printf("%d, %d", n, m);
encrypt(textPointer, passPointer, n, m, vsPointer);
printf("%s\n", text);
decrypt(textPointer, passPointer, n, m, vsPointer);
printf("%s\n", text);
}
void encrypt(char *text, char *pass, int n, int m, char *vs)
{
int i;
int ascii1;
int ascii2;
int passcount = 0;
char encrypt;
for (i = 0; i < n; i++)
{
ascii1 = (int)text[i];
ascii2 = (int)pass[passcount];
ascii1 = ascii1 - 64;
ascii2 = ascii2 - 64;
encrypt = vs[((ascii1 -1)*26) + (ascii2)];
// printf("%d, %d, %c\n", ascii1, ascii2, encrypt);
text[i] = encrypt;
passcount++;
if (passcount == m)
{
passcount = 0;
}
}
}
void decrypt(char *text, char *pass, int n, int m, char *vs)
{
int i;
int ascii1;
int ascii2;
int passcount = 0;
char decrypt;
for (i = 0; i < n; i++)
{
ascii1 = (int)text[i];
ascii2 = (int)pass[passcount];
ascii1 = ascii1 - 64;
ascii2 = ascii2 - 64;
decrypt = vs[//Don't know what to put here];
//printf("%d, %d, %c\n", ascii1, ascii2, decrypt);
text[i] = decrypt;
passcount++;
if (passcount == m)
{
passcount = 0;
}
}
}
void vigsq(char *vs)
{
char alphabet[] = {'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 a = 0, i, j, count = 0;
for(i = 1; i <= 26*26; i++)
{
vs[i] = alphabet[a];
a++;
if (i % 26 == 0)
{
count++;
a = count;
}
if (a == 26)
{
a = 0;
}
}
}
(Просьба игнорировать материал ввода/вывода я буду реализующим позже.) Спасибо за помощь :)
Голосование, чтобы закрыть * (Вопросы, ищущих отладки помощи («почему не этот код работает?») Должен включать в себя желаемое поведение, конкретную проблему или ошибку и кратчайший код, необходимый для воспроизведения его в самом вопросе. Вопросы без четкой постановки проблемы не полезны другим читателям.) * –