gpt4 book ai didi

c - 使用给定算法解密消息

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:24:38 25 4
gpt4 key购买 nike

以下代码生成一个文本文件,其中包含来自不同的可读文本文件的编码消息。

   #include <stdio.h>
#include <time.h>
#include <stdlib.h>

main()
{
FILE *f, *f_enc;
char c, c_enc;
int ind, a[26], r_val;

srandom(time(NULL));
for (ind=0; ind<26; ind++) a[ind]=-1;
for (ind=0; ind<26; ind++){
do
r_val=random()%26;
while (a[r_val]!=-1);
a[r_val]=ind;
}

f=fopen("plain.txt","r");
f_enc=fopen("cipher.txt","w");
while (!feof(f)) {
c=fgetc(f);
if ((c>='A' && c<='Z')||(c>='a' && c<='z')) {
if (c>='A' && c<='Z') c = c + 'a' - 'A';
c=a[c-'a']+'a';
}
fputc(c,f_enc);
}
fclose(f);
fclose(f_enc);
}

我不清楚的是代码正在实现的对消息进行编码的总体算法。

  • 是否从字符中减去 ASCII 值 ('a - 'A) 以生成编码字符?

示例输出如下:

xohq xpu ouuf yubliu spieqxkhq, hzj hcc xpilnap xpu plnqu
tln slncj puhi ku yuhxeza xpu slkmnxui oexp xpu klnqu.
xpu jeqf ohq pnza nm ez xpu jeqf jieru oexp shiu,
hzj, zuujcuqq xl qht, e zuhict mnccuj lnx kt phei.

e ahru nm bli xphx zeapx, alx iuhjt bli yuj,
hzj olzjuiuj, "qplncj e gnqx ynt shijq ezqxuhj?"
khkh hzj jhjjt phj gnqx pex xpu pht,
ql e xlcj xpuk allj zeapx, hzj ouzx lz kt oht.

我将尝试对此进行逆向工程,看看我是否可以了解正在发生的事情。欢迎任何猜测!

最佳答案

这是一个简单的替换,例如在密码谜题中使用的。可以用letter frequency analysis解决.

存在automated solvers .示例原文为:

twas the week before christmas, and all through the house you could hear me beating the computer with the mouse. the disk was hung up in the disk drive with care, and, needless to say, i nearly pulled out my hair. i gave up for that night, got ready for bed, and wondered, 'should i just buy cards instead?' mama and daddy had just hit the hay, so i told them good night, and went on my way.

关于c - 使用给定算法解密消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13687828/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com