C编程 - 凯撒密码

问题描述 投票:-6回答:1

我试图回答这个问题“实现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

请有人帮助,谢谢。

参考:qazxsw poi

c vigenere
1个回答
0
投票

您有编译器错误,因为https://www.ukessays.com/essays/information-technology/vigenre-cipher-program-7373.php for(i=0, j=0; i)

首先,修复此问题,您的代码可能会编译。然后修复你的警告。然后,您将能够运行和调试代码。

我也建议is not the proper for loop syntax

此处还有其他与您的密码问题无关的问题,例如使用using the proper signature for main读取字符串而不指定最大字符数。

© www.soinside.com 2019 - 2024. All rights reserved.