在 C Caesar Cipher 中使用 ASCII 解密具有未知密钥的打开的文本文件

Decrypting opened textfile with unknown key using ASCII in C Caesar Cipher

所以我想知道如何使用 ASCII 和未知密钥解密通过命令行参数打开的加密文本文件,然后使用答案密钥将其全部打印出来。我似乎已经能够实际打印出加密的消息,但不知道如何确定如何找到密钥并将其打印出来。

int main( int argc, char *argv[]) {
  FILE *fp = stdin;  // defaults
  int  n = 13;
  int shift;
  // process command line
  switch (argc) {
    default:
      fp = fopen(argv[1], "r"); // should check for problems
      n  = atoi(argv[2]);
      break;
  }
  // rotate text
  int c, key;
  int i;
  while( (c = fgetc(fp)) != EOF) {
  // This is where I have managed to make C an integer 
  // and print out the encrypted message using the printf function.

通常情况下,不知道密钥是不可能解密的。幸运的是,您的消息已使用最简单的方法之一加密...
凯撒密码加密的工作原理如下:
* 选择偏移量 K
* 对消息中的每个字母做
** 字母 = 字母+K

因此,如果我们想破解该代码,我们可以遍历 K (255) 的所有可能值并排除生成非字母或数字的 ASCII 代码的所有可能性(假设原始消息是明文英语).

您可能仍需要一些用户交互来决定是否有多个选项,但选项将受到限制。