C 将密码字母替换为QWERTY

C 将密码字母替换为QWERTY,c,C,我在做一个使用密码的程序。我需要使用的密码是qwerty的字母表。所以 abcdefghijklmnopqrstuvwxyz qwertyuiopasdfghjklzxcvbnm 程序需要获取编码密钥 qwertyuiopasdfghjklzxcvbnm 并产生解码密钥 我该怎么做呢?我过去只使用过凯撒密码。这里是C语言中的代码,用于将字符串输入转换为qwerty密码,假设您只使用小写字母,并且字符串的缓冲区大小为500: #include <stdio.h> #include

我在做一个使用密码的程序。我需要使用的密码是qwerty的字母表。所以

abcdefghijklmnopqrstuvwxyz
qwertyuiopasdfghjklzxcvbnm
程序需要获取编码密钥

qwertyuiopasdfghjklzxcvbnm
并产生解码密钥


我该怎么做呢?我过去只使用过凯撒密码。

这里是C语言中的代码,用于将字符串输入转换为qwerty密码,假设您只使用小写字母,并且字符串的缓冲区大小为500:

#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
const或static const查找表/数组。从“a”或“q”幻数偏移的索引:97:((