當前位置:首頁 » 密碼管理 » 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-07-16 05:07:09 瀏覽:462
電腦安卓軟體哪個好下載 發布:2025-07-16 04:57:08 瀏覽:399
動態磁碟存儲池 發布:2025-07-16 04:46:34 瀏覽:312
php多維數組數組排序 發布:2025-07-16 04:45:19 瀏覽:375
煉妖壺文件夾 發布:2025-07-16 04:43:11 瀏覽:155
phpfile亂碼 發布:2025-07-16 03:57:54 瀏覽:93
手機存儲空間擴容 發布:2025-07-16 03:52:07 瀏覽:861
小米4清除緩存 發布:2025-07-16 03:03:17 瀏覽:563
如何緩解壓力英語作文 發布:2025-07-16 03:03:15 瀏覽:15
手機視頻怎麼緩存 發布:2025-07-16 02:59:05 瀏覽:933