c语言编程给密码加密,用c语言编使用密钥的单表代替密码的加和解密

满意答案

#include "stdio.h"

#include "conio.h"

main()

{ int i,j,k;

char a[]="abcdefghigklmnopqrstuvwxyz" ;

char str[100];

char c[126];

char b[126];

printf("shurukey:\n");

gets(str);

strcat(str,(const char *)a);

printf("%s\n",str);

for(i=strlen(str)-1;i>=0;i--)

for(j=strlen(str)-1;j>=0;j--)

{

if(i!=j&&str[i]==str[j])

{

for(k=i;k<=strlen(str)-1;i++)

str[i]=str[i-1];

}

}

printf("%s\n",str);

gets(b);

printf("shuru mingwen:") ;

for(i=1;i<=strlen(b);i++)

for(j=1;j<=26;j++)

if(b[i]==a[j])

{

for(k=0;;k++)

c[k]=j ;

}

printf("suode miwen shi:");

for(k=1;;k++)

{

printf("%c,",str[c[k]]);

}

getchar() ;

}

这个是我遍的,但是是死循环,可以帮我看一下吗?谢了

00分享举报

多表代换密码是一种替代加密技术,它将明文中的每个字母都替换成密文字母。可以使用C语言来实现这种密码。 以下是一个简单的多表代换密码C语言代码示例: ```c #include <stdio.h> #include <string.h> // 定义密钥表 char table[26] = {'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Z', 'X', 'C', 'V', 'B', 'N', 'M'}; // 加密函数 void encrypt(char *plaintext, char *ciphertext) { int len = strlen(plaintext); for (int i = 0; i < len; i++) { if (plaintext[i] >= 'a' && plaintext[i] <= 'z') { ciphertext[i] = table[plaintext[i] - 'a']; } else if (plaintext[i] >= 'A' && plaintext[i] <= 'Z') { ciphertext[i] = table[plaintext[i] - 'A']; } else { ciphertext[i] = plaintext[i]; } } ciphertext[len] = '\0'; } // 解密函数 void decrypt(char *ciphertext, char *plaintext) { int len = strlen(ciphertext); for (int i = 0; i < len; i++) { if (ciphertext[i] >= 'a' && ciphertext[i] <= 'z') { for (int j = 0; j < 26; j++) { if (table[j] == ciphertext[i]) { plaintext[i] = 'a' + j; break; } } } else if (ciphertext[i] >= 'A' && ciphertext[i] <= 'Z') { for (int j = 0; j < 26; j++) { if (table[j] == ciphertext[i]) { plaintext[i] = 'A' + j; break; } } } else { plaintext[i] = ciphertext[i]; } } plaintext[len] = '\0'; } int main() { char plaintext[100]; char ciphertext[100]; char decryptedtext[100]; printf("请输入明文:"); fgets(plaintext, 100, stdin); encrypt(plaintext, ciphertext); printf("加密后的密文:%s\n", ciphertext); decrypt(ciphertext, decryptedtext); printf("解密后的明文:%s\n", decryptedtext); return 0; } ``` 在这个例子中,我们定义了一个密钥表,它包含了26个字母的替代字母。加密函数接收明文作为输入,并将其转换为密文。解密函数接收密文作为输入,并将其转换回明文。最后,我们在主函数中使用这些函数来加密解密一段文字。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值