当前位置:首页 » 编程语言 » c语言凯撒密码

c语言凯撒密码

发布时间: 2022-06-25 13:14:19

⑴ 凯撒密码,c语言,求救!

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

int main()
{
int i = 0;
int len = 0;
char ch;
char buf[256] = {0};
char nor[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char enc[26] = {'s','u','w','y','a','c','e','g','i','k','m','o','q','r','t','v','x','z','b','d','f','h','j','l','n','p'};

printf("Encode or Decode: ");
scanf("%c",&ch);
printf("please input your string: ");
fflush(stdin);
gets(buf);
len = strlen(buf);

switch (ch)
{
case 'e':
case 'E':
for (i=0;i<len;i++)
{
buf[i] = enc[buf[i] - 'a'];
}
break;
case 'd':
case 'D':
for (i=0;i<len;i++)
{
buf[i] = nor[i];
}
break;
default:
printf("wrong input!\n");
}

printf("<%s>\n",buf);

return 0;
}

⑵ 用C语言实现凯撒密码加密解密,急!

忘了说解密了,解密过程完全可以使用上面的代码,只要把key的值改成26-key就行了。比如,加密的密钥是3,那么解密密钥就是23,这样就可以使用同一段代码。至于为什么+23和-3的效果一样,还请翻阅数论有关剩余类环的知识。

⑶ 凯撒密码,要求C语言编写,求救!

写的一般般,希望对LZ有所帮助
#include <stdio.h>
#include <string.h>
int main()
{
char str[201];//存放字符
char tmp[11];//临时变量
int i;//循环变量
int len;//存放消息长度
scanf("%s",tmp);//这里输入START,开始
getchar();//接收回车
while(strcmp(tmp,"ENDOFINPUT"))
{
gets(str);//由于输入中有空格,所以用gets输入
getchar();//接收回车
len = strlen(str);
for(i=0;i<len;i++)
{
if(str[i]>='A'&&str[i]<='Z')
{
str[i] -= 5 ;
if(str[i] < 65)
{
str[i] +=26;
}
}
}
scanf("%s",tmp);//这里输入END,结束
printf("%s\n",str);//处理完就直接输出结果
scanf("%s",tmp);//输入START表示继续,输入ENDOFINPUT则表示最后一个数据集
getchar();//接收回车
}
return 0;

}

⑷ c语言里的凯撒密码

#include<stdio.h>
#include<string.h>
intmain()
{
inti;intnumber;
chara[100];
scanf("%s",a);
number=strlen(a);
for(i=0;i<number;i++){
a[i]=a[i]+4;
}
for(i=0;i<number;i++){
printf("%c",a[i]);
}

return0;
}

⑸ 凯撒密码 C语言

#include<stdio.h>
#include<string.h>
void main ()
{
char str[100];
char str1[100];
printf("输入字符串:");
scanf("%s",&str);
int len;
len=strlen(str);
for(int i=0;i<len;i++)
{
str1[i]=(str[i]-97+3)%26+97;
}
str1[len]='\0';
printf ("密文为:%s\n",str1);
}

⑹ 凯撒密码的算法c语言的怎么实现啊

凯撒密码是一种非常古老的加密方法,相传当年凯撒大地行军打仗时为了保证自己的命令不被敌军知道,就使用这种特殊的方法进行通信,以确保信息传递的安全。他的原理很简单,说到底就是字母于字母之间的替换。下面让我们看一个简单的例子:“”用凯撒密码法加密后字符串变为“edlgx”,它的原理是什么呢?把“”中的每一个字母按字母表顺序向后移3位,所得的结果就是刚才我们所看到的密文。

#include <stdio.h>
main()
{
char M[100];
char C[100];
int K=3,i;
printf("请输入明文M(注意不要输入空白串)\n");
gets(M);

for(i=0;M[i]!='\0';i++)
C[i]=(M[i]-'a'+K)%26+'a';
C[i]='\0';

printf("结果是:\n%s\n",C);
}

⑺ 将凯撒密码X的加密、解密过程用C语言编程实现

1、在密码学中,恺撒密码(或称恺撒加密、恺撒变换、变换加密)是一种最简单且最广为人知的加密技术。它是一种替换加密的技术,明文中的所有字母都在字母表上向后(或向前)按照一个固定数目进行偏移后被替换成密文。例如,当偏移量是3的时候,所有的字母A将被替换成D,B变成E,以此类推。这个加密方法是以恺撒的名字命名的,当年恺撒曾用此方法与其将军们进行联系。恺撒密码通常被作为其他更复杂的加密方法中的一个步骤,例如维吉尼尔密码。恺撒密码还在现代的ROT13系统中被应用。但是和所有的利用字母表进行替换的加密技术一样,恺撒密码非常容易被破解,而且在实际应用中也无法保证通信安全。例子恺撒密码的替换方法是通过排列明文和密文字母表,密文字母表示通过将明文字母表向左或向右移动一个固定数目的位置。

2、kaiser加密算法具体程序:

#include<stdio.h>
#include<conio.h>
charencrypt(charch,intn)/*加密函数,把字符向右循环移位n*/
{
while(ch>='A'&&ch<='Z')
{
return('A'+(ch-'A'+n)%26);
}
while(ch>='a'&&ch<='z')
{
return('a'+(ch-'a'+n)%26);
}
returnch;
}
voidmenu()/*菜单,1.加密,2.解密,3.暴力破解,密码只能是数字*/
{
clrscr();
printf(" =========================================================");
printf(" 1.Encryptthefile");
printf(" 2.Decryptthefile");
printf(" 3.Forcedecryptfile");
printf(" 4.Quit ");
printf("========================================================= ");
printf("Pleaseselectaitem:");
return;
}
main()
{
inti,n;
charch0,ch1;
FILE*in,*out;
charinfile[20],outfile[20];
textbackground(BLACK);
textcolor(LIGHTGREEN);
clrscr();
sleep(3);/*等待3秒*/
menu();
ch0=getch();
while(ch0!='4')
{
if(ch0=='1')
{
clrscr();
printf(" Pleaseinputtheinfile:");
scanf("%s",infile);/*输入需要加密的文件名*/
if((in=fopen(infile,"r"))==NULL)
{
printf("Cannotopentheinfile! ");
printf("Pressanykeytoexit! ");
getch();
exit(0);
}
printf("Pleaseinputthekey:");
scanf("%d",&n);/*输入加密密码*/
printf("Pleaseinputtheoutfile:");
scanf("%s",outfile);/*输入加密后文件的文件名*/
if((out=fopen(outfile,"w"))==NULL)
{
printf("Cannotopentheoutfile! ");
printf("Pressanykeytoexit! ");
fclose(in);
getch();
exit(0);
}
while(!feof(in))/*加密*/
{
fputc(encrypt(fgetc(in),n),out);
}
printf(" Encryptisover! ");
fclose(in);
fclose(out);
sleep(1);
}
if(ch0=='2')
{
clrscr();
printf(" Pleaseinputtheinfile:");
scanf("%s",infile);/*输入需要解密的文件名*/
if((in=fopen(infile,"r"))==NULL)
{
printf("Cannotopentheinfile! ");
printf("Pressanykeytoexit! ");
getch();
exit(0);
}
printf("Pleaseinputthekey:");
scanf("%d",&n);/*输入解密密码(可以为加密时候的密码)*/
n=26-n;
printf("Pleaseinputtheoutfile:");
scanf("%s",outfile);/*输入解密后文件的文件名*/
if((out=fopen(outfile,"w"))==NULL)
{
printf("Cannotopentheoutfile! ");
printf("Pressanykeytoexit! ");
fclose(in);
getch();
exit(0);
}
while(!feof(in))
{
fputc(encrypt(fgetc(in),n),out);
}
printf(" Decryptisover! ");
fclose(in);
fclose(out);
sleep(1);
}
if(ch0=='3')
{
clrscr();
printf(" Pleaseinputtheinfile:");
scanf("%s",infile);/*输入需要解密的文件名*/
if((in=fopen(infile,"r"))==NULL)
{
printf("Cannotopentheinfile! ");
printf("Pressanykeytoexit! ");
getch();
exit(0);
}
printf("Pleaseinputtheoutfile:");
scanf("%s",outfile);/*输入解密后文件的文件名*/
if((out=fopen(outfile,"w"))==NULL)
{
printf("Cannotopentheoutfile! ");
printf("Pressanykeytoexit! ");
fclose(in);
getch();
exit(0);
}
for(i=1;i<=25;i++)/*暴力破解过程,在察看信息正确后,可以按'Q'或者'q'退出*/
{
rewind(in);
rewind(out);
clrscr();
printf("========================================================== ");
printf("Theoutfileis: ");
printf("========================================================== ");
while(!feof(in))
{
ch1=encrypt(fgetc(in),26-i);
putch(ch1);
fputc(ch1,out);
}
printf(" ======================================================== ");
printf("Thecurrentkeyis:%d ",i);/*显示当前破解所用密码*/
printf("Press'Q'toquitandotherkeytocontinue...... ");
printf("========================================================== ");
ch1=getch();
if(ch1=='q'||ch1=='Q')/*按'Q'或者'q'时退出*/
{
clrscr();
printf(" GoodBye! ");
fclose(in);
fclose(out);
sleep(3);
exit(0);
}
}
printf(" Forcedecryptisover! ");
fclose(in);
fclose(out);
sleep(1);
}
menu();
ch0=getch();
}
clrscr();
printf(" GoodBye! ");
sleep(3);
}

⑻ C语言编程问题,凯撒密码

#include<stdio.h>
chars[]="(BTBU)isakeystate-,Sciences,Engineering,Law,Economics,History,PhilosophyandManagement.";
voidfun(char*s,intn)
{
inti=0;
while(s[i]!=0)
{
if(s[i]<='z'&&s[i]>='a')
{
s[i]+=n;
if(s[i]>'z')s[i]-=24;
}
elseif(s[i]<='Z'&&s[i]>='A')
{
s[i]+=n;
if(s[i]>'Z')s[i]-=24;
}
i++;
}
}
voidmain()
{
fun(s,3);
puts(s);
}

⑼ 关于凯撒密码的问题C++(要答案)

摘要 #include

⑽ 如何用C语言实现加强版的凯撒密码破解!

供参考 译码只需要一句即可

感兴趣自己分析下

#include<stdio.h>
intmain()
{
chars[100];
intk;
inti;
while(~scanf("%s%d",s,&k))
{
k%=26;
for(i=0;s[i];i++)
s[i]=(s[i]-'A'+26-(k+i+1)%26)%26+'A';
printf("%s ",s);
}
return0;
}
热点内容
安卓手机中的投影在哪里 发布:2025-02-05 08:01:57 浏览:594
php调用定义函数 发布:2025-02-05 08:00:30 浏览:451
ubuntujava环境变量 发布:2025-02-05 07:57:13 浏览:442
sql语句on 发布:2025-02-05 07:41:42 浏览:597
取消电脑密码怎么设置8 发布:2025-02-05 07:24:16 浏览:393
洗脑编程 发布:2025-02-05 07:23:52 浏览:948
osd加密 发布:2025-02-05 07:17:39 浏览:36
微信游戏源码下载 发布:2025-02-05 07:17:29 浏览:384
计算机内存储器是 发布:2025-02-05 07:13:35 浏览:144
classpathlinux 发布:2025-02-05 07:12:57 浏览:564