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

熱點內容
linux程序設計第4版pdf 發布:2025-07-16 14:52:14 瀏覽:514
底層架演算法 發布:2025-07-16 14:52:07 瀏覽:64
攝影存儲卡哪種好 發布:2025-07-16 14:41:51 瀏覽:625
雙鏈式存儲結構講解 發布:2025-07-16 14:37:50 瀏覽:321
西安電信上傳 發布:2025-07-16 14:33:48 瀏覽:91
des解密java 發布:2025-07-16 14:26:45 瀏覽:796
sql2000新建資料庫 發布:2025-07-16 14:19:47 瀏覽:941
硬碟錄像機用nas存儲 發布:2025-07-16 14:16:55 瀏覽:911
南寧ip伺服器租用 發布:2025-07-16 14:11:30 瀏覽:505
androidcategory 發布:2025-07-16 14:11:25 瀏覽:214