java凯撒密码实现完美版.wps资料文档下载

上传人:b****1 文档编号:13161342 上传时间:2022-10-07 格式:WPS 页数:5 大小:66KB
下载 相关 举报
java凯撒密码实现完美版.wps资料文档下载_第1页
第1页 / 共5页
java凯撒密码实现完美版.wps资料文档下载_第2页
第2页 / 共5页
java凯撒密码实现完美版.wps资料文档下载_第3页
第3页 / 共5页
java凯撒密码实现完美版.wps资料文档下载_第4页
第4页 / 共5页
java凯撒密码实现完美版.wps资料文档下载_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

java凯撒密码实现完美版.wps资料文档下载

《java凯撒密码实现完美版.wps资料文档下载》由会员分享,可在线阅读,更多相关《java凯撒密码实现完美版.wps资料文档下载(5页珍藏版)》请在冰豆网上搜索。

java凯撒密码实现完美版.wps资料文档下载

publicclassCryptologycharciphertext;

/密文intkey;

charplaintext;

/明文StringBufferplaintextStr;

StringBufferciphertextStr;

finalintmax=500;

Cryptology()key=0;

plaintextStr=newStringBuffer();

ciphertextStr=newStringBuffer();

intsetKey()System.out.println(请输入一个Caesar密钥);

Scannersc=newScanner(System.in);

trykey=sc.nextInt()%26;

catch(Exceptione)System.out.println(需要输入整数!

);

returnkey;

voidgetPlaintext()/获得明文plaintext=newcharmax;

for(intj=0;

j=a&

ch=A&

ch=Z|ch=|ch=,|ch=.|ch=!

)plaintexti=ch;

i+;

elseSystem.out.println(输入不支持!

break;

trych=(char)bf.read();

catch(IOExceptione1)catch(IOExceptione)voidencryption()/加密inttemp=0;

ciphertext=newcharmax;

jmax;

j+)ciphertextj=;

for(inti=0;

i=a&

plaintexti122)ciphertexti=(char)(97+temp-123);

elseciphertexti=(char)temp;

if(plaintexti=A&

plaintexti90)ciphertexti=(char)(65+temp-91);

ciphertextStr.append(ciphertexti);

elsebreak;

voiddeciphering()/解密charc=;

inttemp=0;

i=97&

ciphertexti=122)c=(char)(temp);

if(temp=65&

ciphertexti=90)c=(char)(temp);

if(temp65)c=(char)(26+temp);

plaintextStr.append(c);

voiddisplay()System.out.println(密文明文对比);

System.out.println(密文:

+ciphertextStr);

System.out.println(明文:

+plaintextStr);

主函数部分:

publicclassComplicationpublicstaticvoidmain(Stringargs)Cryptologycry=newCryptology();

cry.setKey();

cry.getPlaintext();

cry.encryption();

cry.deciphering();

cry.display();

结果1:

结果2:

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 考试认证 > IT认证

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1