當前位置:首頁 » 密碼管理 » 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 瀏覽:547
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:832
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:536
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:716
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:639
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:954
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:210
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:67
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:760
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:665