当前位置:首页 » 密码管理 » java凯撒加密代码

java凯撒加密代码

发布时间: 2025-01-06 12:37:16

❶ 凯撒加密解密算法问题 C语言描述

你这语句有问题吧?
#include<stdio.h>
main()
{ char i;
int n;
scanf("%d",&n);
printf("Input your word:");
while(1)
{ i=getchar();
if(i!='\0')
printf("%c",i+n);
else break;
}
} 这个是密钥自己输入的

❷ 用java 编写一个凯撒加密和解密

import java.util.Scanner;

public class Caeser {
private String table; // 定义密钥字母表
private int key; // 定义密钥key
public Caeser(String table, int key) {
// 根据不同的字母表和不同的密钥生成一个新的凯撒算法,达到通用的目的
super();
this.table = table;
this.key = key;
}
public String encrypt(String from) {
//凯撒加密算法,传入明文字符串,返回一个密文字符串
String to = "";
for (int i = 0; i < from.length(); i++) {
to += table.charAt((table.indexOf(from.charAt(i))+key)%table.length());
}
return to;
}

public static void main(String[] args) {
Caeser caeser = new Caeser("abcdefghijklmnopqrstuvwxyz", 3);
Scanner scanner = new Scanner(System.in);
System.out.println("请输入要加密的字符串");
String str =scanner.nextLine(); //输入字符串 security
String result = caeser.encrypt(str); //调用加密方法进行加密
System.out.print(result); // 可得结果 vhfxulwb
}
}

热点内容
java返回this 发布:2025-10-20 08:28:16 浏览:647
制作脚本网站 发布:2025-10-20 08:17:34 浏览:939
python中的init方法 发布:2025-10-20 08:17:33 浏览:634
图案密码什么意思 发布:2025-10-20 08:16:56 浏览:823
怎么清理微信视频缓存 发布:2025-10-20 08:12:37 浏览:734
c语言编译器怎么看执行过程 发布:2025-10-20 08:00:32 浏览:1069
邮箱如何填写发信服务器 发布:2025-10-20 07:45:27 浏览:302
shell脚本入门案例 发布:2025-10-20 07:44:45 浏览:163
怎么上传照片浏览上传 发布:2025-10-20 07:44:03 浏览:855
python股票数据获取 发布:2025-10-20 07:39:44 浏览:765