影视娱乐资讯>>资讯>>内容

凯撒密码实现英文短句的加解密

日期:2024-03-06 06:04:51    标签:  

1. 将“We are students.”这个英文词句用k=4的凯萨密码翻译成密码

1. 恺撒密码,

作为一种最为古老的对称加密体制,他的基本思想是:

通过把字母移动一定的位数来实现加密和解密。

例如,如果密匙是把明文字母的位数向后移动三位,那么明文字母B就变成了密文的E,依次类推,X将变成A,Y变成B,Z变成C,由此可见,位数就是凯撒密码加密和解密的密钥。

如:ZHDUHVWXGHQWV(后移三位)

2. 凯撒密码,

是计算机C语言编程实现加密和解密。挺复杂的。你可以研究一下哦。

2. 将凯撒密码(K=7)的加密、解密过程用C语言编程实现

#include<stdio.h>

#include<ctype.h>

#define maxlen 100

#define K 7

char *KaisaEncode(char *str)//加密

{

char *d0;

d0=str;

for(;*str!='';str++)

{

if(isupper(*str))

*str=(*str-'A'+K)%26+'A';

else if(islower(*str))

*str=(*str-'a'+K)%26+'a';

else

continue;

}

return d0;

}

char *KaisaDecode(char *str)//解密

{

char *d0;

d0=str;

for(;*str!='';str++)

{

if(isupper(*str))

*str=(*str-'A'-K+26)%26+'A';

else if(islower(*str))

*str=(*str-'a'-K+26)%26+'a';

else

continue;

}

return d0;

}

int main(void)

{

char s[maxlen];

gets(s);

puts(KaisaEncode(s));

puts(KaisaDecode(s));

return 0;

}

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

(2)kaiser加密算法 具体程序:#include#include char encrypt(char ch,int n) { while(ch>='A'&&ch<='z') {="" return="" ('a'+(ch-'a'+n)%26);="" }="" while(ch="">='a'&&ch<='z') {="" return="" ('a'+(ch-'a'+n)%26);="" }="" return="" ch;="" }="" void="" menu()="" {="" clrscr();="" printf("n="========================================================");" printf("n1.encrypt="" the="" file");="" printf("n2.decrypt="" the="" file");="" printf("n3.force="" decrypt="" file");="" printf("n4.quitn");="" printf("="========================================================n");" printf("please="" select="" a="" item:");="" return;="" }="" main()="" {="" int="" i,n;="" char="" ch0,ch1;="" file="" *in,*out;="" char="" infile[20],outfile[20];="" textbackground(black);="" textcolor(lightgreen);="" clrscr();="" sleep(3);="" menu();="" ch0="getch();" while(ch0!='4' )="" {="" if(ch0="='1')" {="" clrscr();="" printf("nplease="" input="" the="" infile:");="" scanf("%s",infile);="" if((in="fopen(infile,"r"))==NULL)" {="" printf("can="" not="" open="" the="" infile!n");="" printf("press="" any="" key="" to="" exit!n");="" getch();="" exit(0);="" }="" printf("please="" input="" the="" key:");="" scanf("%d",&n);="" printf("please="" input="" the="" outfile:");="" scanf("%s",outfile);="" if((out="fopen(outfile,"w"))==NULL)" {="" printf("can="" not="" open="" the="" outfile!n");="" printf("press="" any="" key="" to="" exit!n");="" fclose(in);="" getch();="" exit(0);="" }="" while(!feof(in))="" {="" fputc(encrypt(fgetc(in),n),out);="" }="" printf("nencrypt="" is="" over!n");="" fclose(in);="" fclose(out);="" sleep(1);="" }="" if(ch0="='2')" {="" clrscr();="" printf("nplease="" input="" the="" infile:");="" scanf("%s",infile);="" if((in="fopen(infile,"r"))==NULL)" {="" printf("can="" not="" open="" the="" infile!n");="" printf("press="" any="" key="" to="" exit!n");="" getch();="" exit(0);="" }="" printf("please="" input="" the="" key:");="" scanf("%d",&n);="" n="26-n;" printf("please="" input="" the="" outfile:");="" scanf("%s",outfile);="" if((out="fopen(outfile,"w"))==NULL)" {="" printf("can="" not="" open="" the="" outfile!n");="" printf("press="" any="" key="" to="" exit!n");="" fclose(in);="" getch();="" exit(0);="" }="" while(!feof(in))="" {="" fputc(encrypt(fgetc(in),n),out);="" }="" printf("ndecrypt="" is="" over!n");="" fclose(in);="" fclose(out);="" sleep(1);="" }="" if(ch0="='3')" {="" clrscr();="" printf("nplease="" input="" the="" infile:");="" scanf("%s",infile);="" if((in="fopen(infile,"r"))==NULL)" {="" printf("can="" not="" open="" the="" infile!n");="" printf("press="" any="" key="" to="" exit!n");="" getch();="" exit(0);="" }="" printf("please="" input="" the="" outfile:");="" scanf("%s",outfile);="" if((out="fopen(outfile,"w"))==NULL)" {="" printf("can="" not="" open="" the="" outfile!n");="" printf("press="" any="" key="" to="" exit!n");="" fclose(in);="" getch();="" exit(0);="" }="" for(i=""><=25;i++) 暴力破解过程,在察看信息正确后,可以按'q'或者'q'退出*/="" {="" rewind(in);="" rewind(out);="" clrscr();="" printf("="=========================================================n");" printf("the="" outfile="" is:n");="" printf("="=========================================================n");" while(!feof(in))="" {="" ch1="encrypt(fgetc(in),26-i);" putch(ch1);="" fputc(ch1,out);="" }="" printf("n="=======================================================n");" printf("the="" current="" key="" is:="" %d="" n",i);="" printf("press="" 'q'="" to="" quit="" and="" other="" key="" to="">

n"); printf("==========================================================n"); ch1=getch(); if(ch1=='q'||ch1=='Q') { clrscr(); printf("nGood Bye!n"); fclose(in); fclose(out); sleep(3); exit(0); } } printf("nForce decrypt is over!n"); fclose(in); fclose(out); sleep(1); } menu(); ch0=getch(); } clrscr(); printf("nGood Bye!n"); sleep(3); }。

4. 怎样编写程序:实现恺撒密码加密单词"julus"

用下面程序:新建个txt,放进去任意单词,设置#define N 5中的值,实现字母移位,达到加密目的。

本程序提供解密功能#include #define N 5void jiami(char namea[256]) { FILE *fp_jiami,*fp_file2; char c; fp_jiami=fopen(namea,"rb"); fp_file2=fopen("file2.txt","wb"); while(EOF!=(fscanf(fp_jiami,"%c",&c))) { if((c>='A'&&c<='z')||(c>='a'&&c<='z')) {="" c="c+N;" if="" (!((c="">='A'&&c<='z')||(c>='a'&&c<='z')))c=c-26; if(c="">='a'&&c<='z')c=c-32; }="" fprintf(fp_file2,"%c",c);="" }="" fclose(fp_file2);="" fclose(fp_jiami);="" }="" void="" jiemi(char="" en_name[256])="" {="" file="" *fp_jiemi,*fp_file3;="" char="" c;="" fp_jiemi="fopen(en_name,"rb");" fp_file3="fopen("file3.txt","wb");" while(eof!="(fscanf(fp_jiemi,"%c",&c)))" {="" if((c="">='A'&&c<='z')||(c>='a'&&c<='z')) {="" c="c-N;" if="" (!((c="">='A'&&c<='z')||(c>='a'&&c<='z')))c=c+26; if(c="">='A'&&c<='z')c=c+32; }="" fprintf(fp_file3,"%c",c);="" }="" fclose(fp_file3);="" fclose(fp_jiemi);="" }int="" main(){="" char="" name[256];="" int="" n;="" printf("输入你要操作的txt文本:");="" gets(name);="" printf("n请选择需要进行的操作:n");="" printf("="" 1:加密="" 2:解密="" n");="" printf("输入你的选择:");="" scanf("%d",&n);="" switch(n)="" {="" case="" 1:{jiami(name);printf("t加密成功!!nn");="" break;}="" case="" 2:{jiemi(name);printf("t解密成功!!nn");="" break;}="" default:{printf("输入操作不存在!");}="" }="" return="">

5. 谁有PYTHON编写的凯撒密码的加密和解密代码

给你写了一个.

def convert(c, key, start = 'a', n = 26):

a = ord(start)

offset = ((ord(c) - a + key)%n)

return chr(a + offset)

def caesarEncode(s, key):

o = ""

for c in s:

if c.islower():

o+= convert(c, key, 'a')

elif c.isupper():

o+= convert(c, key, 'A')

else:

o+= c

return o

def caesarDecode(s, key):

return caesarEncode(s, -key)

if __name__ == '__main__':

key = 3

s = 'Hello world!'

e = caesarEncode(s, key)

d = caesarDecode(e, key)

print e

print d

运行结果:

Khoor zruog!

Hello world!

相关花絮

百蝶剧情网致力于提供最新电视剧剧情介绍 、电视剧分集剧情明星个人资料 Copyright @2008-2014 All Rights Reserved 百蝶剧情网版权所有 备案号:蜀ICP备2021011373号-2