Программирование на C - Ceaser Cipher - PullRequest
0 голосов
/ 13 марта 2019

я пытаюсь ответить на вопрос "реализовать шифр Vigenère. Программа должна быть скомпилирована с помощью стандартного компилятора gcc. Ваша программа должна предоставить пользователю возможность либо зашифровать, либо расшифровать сообщение. Пользователю должно быть предложено ввести вводимую фразу-пароль и ключевое слово для используется в шифре "

# include <stdio.h>

main()
{
  int select; // variable declairation
  int i, j;
  char passphrase[256];
  char keyword[33];
  int value;

  while (1) // infinite loop
  {
    printf("n1.Encrypt n"); // Display options for the user
    printf("2. Decryptn"); // Encrypt or Decrypt
    scanf(" % d", & select); // read the option selected

    if (select == 1)
    {
      printf("Please Enter Message to be encrypted"); //text to be encrypted
      scanf(" % s", & passphrase);

      printf("Please Enter keyword"); // key word
      scanf(" % s", & keyword);

      for (i = 0, j = 0; i)
        {
          if (j >= strlen(keyword)) // repeat the key word
          {
            j = 0;
          }
          value = (((passphrase[i]) - 97) + ((keyword[j]) - 97)); //logic (passphrase+key)%26

          printf(" % c", 97 + (value % 26)); // display Encrypted text
        }
      }
      else if (select == 2)
      {
        printf("Please Enter Encrypted Message to be Decrypted"); //text to be decrypted
        scanf(" % s", & passphrase);

        printf("Please Enter key"); //key
        scanf(" % s", & keyword);

        for (i = 0, j = 0; i)
          {
            if (j >= strlen(keyword))
            {
              j = 0; // repeate the key
            }
            value = ((passphrase[i]) - 96) - (keyword[j] - 96); //logic (passphrase-key)%26
            if (value < 0)
            {
              value = value * -1; //make the value positive
            }
            printf(" % c", 97 + (value % 26)); // display dencrypted message
          }
        }
        else
          printf("Please Choose a correct option");
      }
    }

Список ошибок можно увидеть ниже:

Executing  gcc.exe...
gcc.exe "..c" -o "..exe"    -I"D:\Dev-Cpp\include"   -L"D:\Dev-Cpp\lib" 
..c: In function `main':
..c:38: error: syntax error before ')' token

..c: At top level:
 error: syntax error before "else"
.error: syntax error before string constant
.error: conflicting types for 'scanf'
.note: a parameter list with an ellipsis can't match an empty parameter name list declaration
.error: conflicting types for 'scanf'
.note: a parameter list with an ellipsis can't match an empty parameter name list declaration
.warning: data definition has no type or storage class
.error: syntax error before string constant
.error: conflicting types for 'printf'
.note: a parameter list with an ellipsis can't match an empty parameter name list declaration
.error: conflicting types for 'printf'
.note: a parameter list with an ellipsis can't match an empty parameter name list declaration
.warning: data definition has no type or storage class
error: syntax error before string constant

 warning: data definition has no type or storage class
 error: `passphrase' undeclared here (not in a function)
 error: `i' undeclared here (not in a function)
error: `keyword' undeclared here (not in a function)
 error: `j' undeclared here (not in a function)
 warning: data definition has no type or storage class
 error: syntax error before "if"
 error: syntax error before string constant

Может кто-нибудь помочь, пожалуйста Спасибо.

Refence: https://www.ukessays.com/essays/information-technology/vigenre-cipher-program-7373.php

1 Ответ

0 голосов
/ 13 марта 2019

У вас ошибка компилятора, потому что for(i=0, j=0; i) не подходит для синтаксиса цикла

Сначала исправьте эту проблему, и ваш код может скомпилироваться.Затем исправьте свои предупреждения.Тогда вы сможете запускать и отлаживать свой код.

Я также предлагаю , используя правильную подпись для main .

У вас есть другие проблемы, которые не связаны с вашей проблемой шифра, например, использование scanf для чтения строки без указания максимального количества символов.

...