导航:首页 > 编程语言 > 凯撒密码编程

凯撒密码编程

发布时间:2024-09-01 02:43:52

java编程,凯撒密码,不用数组

代码如下:

publicclassApp{

publicstaticvoidmain(String[]args){

Strings="HelloWorld!";

Stringresult="";

for(inti=0;i<s.length();i++){
result+=(char)(s.charAt(i)+12);
}

System.out.println("加密结果:"+result);
}
}

Ⅱ 用matlab实现凯撒密码,仿射密码,维吉尼亚密码,素数判定和大数分解

functionY=caesarCode(plaintext,shift)
chars=['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'];
L=length(plaintext);
fori=1:L
forj=1:26
ifplaintext(i)==chars(j)
k=mod(j+shift,26);
ifk~=0
Y(i)=chars(k);
else
Y(i)=chars(26);
end
end
end
end

凯撒密码,来自Canhui WANG

Ⅲ C++编程 凯撒加密

#include<iostream>
#include<string>
usingnamespacestd;
voidencrypt(string&s)//加密
{

inti=s.length();
for(intj=0;j<i;++j)
{
if('A'<=s[j]&&s[j]<='Z')
{
if('A'<=s[j]&&s[j]<='W')
s[j]+=3;
else
s[j]-=23;
//cout<<s[j];
s[j]+=32;
//cout<<s[j]<<endl;
}
elseif('a'<=s[j]&&s[j]<='z')
{
if('a'<=s[j]&&s[j]<='w')
s[j]+=3;
else
s[j]-=23;
//cout<<s[j];
s[j]-=32;
//cout<<s[j]<<endl;

}

}
}

intmain()//测试
{
stringxy;
cout<<"输入字符串"<<endl;
cin>>xy;
encrypt(xy);
cout<<xy<<endl;
return0;

}

听说回答的够长才能够自动采纳

Ⅳ 将凯撒密码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);
}

Ⅳ 凯撒密码java编程实现图形界面化代码

class Caesar: def __init__(self): a = list(' ,.-!\'"') b = a[3:] + a[:3] self.emap = dict(zip(a,b)) self.dmap = dict(zip(b,a)) def encode(self, text): tmp = [ (x in self.emap and self.emap[x] or x) for x in text ] return ''.join(tmp) def decode(self, text): tmp = [ (x in self.dmap and self.dmap[x] or x) for x in text ] return ''.join(tmp)

Ⅵ Python编程-翻译密码

区分大小写的凯撒密码。

在凯撒密码的基础上针对大写与小字字符区分处理即可:

解密只需要将7换成19(因为26-7=19),或者使用-7也可以:

print(caesarcipher(caesarcipher('Student!', 7),19))

阅读全文

与凯撒密码编程相关的资料

热点内容
javaflex视频 浏览:823
轻量级的python解释器 浏览:127
我将永远不会持有加密货币资产 浏览:913
linux修改普通用户密码 浏览:364
程序员35岁之后去教学怎么样 浏览:204
cad加密工具致命错误 浏览:626
mud增加场景后编译不了 浏览:375
java生成6位随机数 浏览:674
合肥编程软件招聘 浏览:313
782简便算法 浏览:648
加密视频存在哪里 浏览:118
怎么对一段文字进行多重加密 浏览:467
命令行的用法视频教程 浏览:535
有毒app怎么鉴定真假 浏览:449
学编程需要英语吗 浏览:103
单片机最小系统的作用 浏览:714
如何用电脑设置校时服务器 浏览:561
安卓什么软件可以换铃声 浏览:565
如何解决解压馆的劣势 浏览:323
plc编程模块化 浏览:247