#include<stdio.h>;
char table[26];
int key[2];
void init()
{
int i,j;
char ch='a';
char c;
printf("start here!\n");
for(i=0;i<26;i++)
{
table[i]=ch;
ch++;
}
}
void setkey()
{
int i,j;
int k1[]={5,7,9,11,15,17,19,21,23};
printf("please enter two encryting key k1=(1,3,5,7,9,11,15,17,19,21,23)\n");
scanf("k1=%d,k2=%d",&key[0],&key[1]);
for(i=0;i<26;i++)
{
}
}
void encrypt(int key) //加密
{
char plaintext[50];
char ciphertext[50];
char c;
int i=0,j;
int k,n;
printf("\nplease enter plaintext\nplaintext: ");
scanf("%s",plaintext);
for(c=plaintext[i];c=plaintext[i]!='\0';i++)
{
for(j=0;j<26;j++)
{
if(plaintext[i]==table[j])
{
ciphertext[i]=table[j+key%26];
}
}
}
n=i;
printf("ciphertext: ");
for(i=0;i<n;i++)
{
printf("%c",ciphertext[i]);
}
printf("\n");
}
void decrypt(int key) //解密
{
char plaintext[50];
char ciphertext[50];
char c;
int i=0,j,k;
printf("please enter ciphertext\nThe ciphertext: ");
scanf("\n%s",ciphertext);
for(c=ciphertext[i];c=ciphertext[i]!='\0';i++)
{
for(j=0;j<26;j++)
{
if(ciphertext[i]==table[j])
plaintext[i]=table[j-3%26];
}
}
k=i;
i=0;
printf("The plaintext: ");
for(i=0;i<k;i++)
{
printf("%c",plaintext[i]);
}
printf("\n");
}
void main()
{
printf("Please enter the key\nkey=");
scanf("%d",&key);
init();
encrypt(key);
decrypt(key) ;
}
仿射密码加解密 C 程序
5星 · 超过95%的资源 需积分: 20 187 浏览量
2009-10-09
16:08:03
上传
评论 3
收藏 648B RAR 举报
xlzhan
- 粉丝: 3
- 资源: 22
最新资源
- TG-2024-04-26-183849310.mp4
- 汇编语言的概要介绍与分析
- 个人博客系统设计与开发.zip
- 2023-04-06-项目笔记 - 第一百十五阶段 - 4.4.2.113全局变量的作用域-113 -2024.04.26
- 2023-04-06-项目笔记 - 第一百十五阶段 - 4.4.2.113全局变量的作用域-113 -2024.04.26
- htmlzwbjq_downyi.com.zip
- 无头单向非循环链表的实现(Test.c)
- 无头单向非循环链表的实现(SList.c)
- 浏览器重定向插件更新文件
- SSA-BP麻雀算法优化BP神经网络多特征分类预测(Matlab实现完整源码和数据)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈