Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 破译qwert密码_C_Encryption - Fatal编程技术网

C 破译qwert密码

C 破译qwert密码,c,encryption,C,Encryption,我无法从qwerty将此代码反向解密回abc 我不知道从哪里开始。 我试图用包含ABC的字符串替换索引。。。 我还试着把密文换成abc,把索引改成qwerty,但没有用 这是原始代码 #include <stdio.h> #include <string.h> int main() { char* ciphertext = "qwertyuiopasdfghjklzxcvbnm"; // cipher lookup char input[500]

我无法从qwerty将此代码反向解密回abc

我不知道从哪里开始。 我试图用包含ABC的字符串替换索引。。。 我还试着把密文换成abc,把索引改成qwerty,但没有用

这是原始代码

#include <stdio.h>
#include <string.h>

int main() {
    char* ciphertext = "qwertyuiopasdfghjklzxcvbnm";    // cipher lookup

    char input[500];                                    // input buffer
    printf("Enter text: ");
    fgets(input, sizeof(input), stdin);                 // safe input from user
    input[strlen(input) - 1] = 0;                       // remove the \n (newline)
    int count = strlen(input);                          // get the string length

    char output[count];                                 // output string
    for(int i = 0; i < count; i++) {                    // loop through characters in input
        int index = ((int) input[i]) - 97;              // get the index in the cipher by subtracting 'a' (97) from the current character
        if(index < 0) {
            output[i] = ' ';                            // if index < 0, put a space to account for spaces
        }
        else {
            output[i] = ciphertext[index];              // else, assign the output[i] to the ciphertext[index]
        }
    }
    output[count] = 0;                                  // null-terminate the string

    printf("output: %s\n", output);                     // output the result
}
#包括
#包括
int main(){
char*ciphertext=“qwertyuiopasdfghjklzxcvnm”//密码查找
字符输入[500];//输入缓冲区
printf(“输入文本:”);
fgets(输入,sizeof(输入),stdin);//用户的安全输入
input[strlen(input)-1]=0;//删除\n(换行符)
int count=strlen(输入);//获取字符串长度
字符输出[计数];//输出字符串
对于(int i=0;i
我的努力没有起到任何作用,它只是重新打印我输入的内容,因此您从“a”(ascii 97)开始,并通过
char\u value-97将其转换为一个字符数组的索引

要转换回纯文本,您需要从
q
转到
a


一种方法是搜索
ciphertext
以查找字符(q)出现的索引,然后将97添加到该索引以获得原始值。

Fyi,
output[count]=0=超出写入范围。
“kxvmcnophqrszyijadlegwbuft”
-您可以在纸上完成。或者循环字符串,直到找到匹配项。