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

熱點內容
怎麼注銷電腦密碼 發布:2025-05-09 19:18:47 瀏覽:145
台灣中華電信大型伺服器雲伺服器 發布:2025-05-09 19:09:08 瀏覽:407
oracle11g編程 發布:2025-05-09 19:08:52 瀏覽:739
玩游戲選哪個安卓 發布:2025-05-09 19:02:55 瀏覽:46
web前端開發用到什麼腳本 發布:2025-05-09 18:51:33 瀏覽:893
php映射 發布:2025-05-09 18:35:14 瀏覽:992
linux加入服務 發布:2025-05-09 18:35:06 瀏覽:984
ps人像修圖需要什麼配置 發布:2025-05-09 18:33:41 瀏覽:95
android靜默安裝apk 發布:2025-05-09 18:33:40 瀏覽:784
c語言編譯過程指令 發布:2025-05-09 18:06:10 瀏覽:951