當前位置:首頁 » 密碼管理 » 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
}
}

熱點內容
android圖片組 發布:2025-03-04 16:41:09 瀏覽:48
為什麼租電腦店鋪讓加錢換配置 發布:2025-03-04 16:40:58 瀏覽:996
dvd光碟的文件夾 發布:2025-03-04 16:35:44 瀏覽:548
微信外賣訂餐系統源碼 發布:2025-03-04 16:35:41 瀏覽:245
洗牌演算法原理 發布:2025-03-04 16:35:36 瀏覽:264
電子郵件地址或伺服器指的是什麼 發布:2025-03-04 16:25:45 瀏覽:86
這次疫情對資產配置怎麼分 發布:2025-03-04 16:25:32 瀏覽:120
解壓摳東西 發布:2025-03-04 16:14:43 瀏覽:599
android動態圖片 發布:2025-03-04 16:13:09 瀏覽:44
linux讀取輸入 發布:2025-03-04 16:13:09 瀏覽:177