日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

rust(58)-凯撒密码

發布時間:2025/3/12 编程问答 14 豆豆
生活随笔 收集整理的這篇文章主要介紹了 rust(58)-凯撒密码 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

在密碼學中,凱撒密碼(英語:Caesar cipher),或稱凱撒加密、凱撒變換、變換加密,是一種最簡單且最廣為人知的加密技術。它是一種替換加密的技術,明文中的所有字母都在字母表上向后(或向前)按照一個固定數目進行偏移后被替換成密文。例如,當偏移量是3的時候,所有的字母A將被替換成D,B變成E,以此類推。這個加密方法是以羅馬共和時期凱撒的名字命名的,據稱當年凱撒曾用此方法與其將軍們進行聯系。

凱撒密碼通常被作為其他更復雜的加密方法中的一個步驟,例如維吉尼亞密碼。凱撒密碼還在現代的ROT13系統中被應用。但是和所有的利用字母表進行替換的加密技術一樣,凱撒密碼非常容易被破解,而且在實際應用中也無法保證通信安全。

凱撒密碼的替換方法是通過排列明文和密文字母表,密文字母表示通過將明文字母表向左或向右移動一個固定數目的位置。例如,當偏移量是左移3的時候(解密時的密鑰就是3):

明文字母表:ABCDEFGHIJKLMNOPQRSTUVWXYZ
密文字母表:DEFGHIJKLMNOPQRSTUVWXYZABC
使用時,加密者查找明文字母表中需要加密的消息中的每一個字母所在位置,并且寫下密文字母表中對應的字母。需要解密的人則根據事先已知的密鑰反過來操作,得到原來的明文。例如:

明文:THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG
密文:WKH TXLFN EURZQ IRA MXPSV RYHU WKH ODCB GRJ

Finished dev [unoptimized + debuginfo] target(s) in 0.05sRunning `F:\learn\rustlearn\learn56\target\debug\learn56.exe` 源字符串: At MIT, pushing the boundaries of knowledge and possibility is our joyful obsession, and we celebrate fundamental discoveries and practical applications alike. As educators, we also value research as a potent form of learning by doing. Through MIT’s Undergraduate Research Opportunities Program (UROP(opens in new window)), more than 85% of undergraduates enrich their education through engaging in frontline, faculty-led research. 凱撒密碼加密 加密結果:M€,YU`8,|?tuzs,€tq,n{?zpm~uq,{r,wz{?xqpsq,mzp,|{unuxu€ ,u,{?~,v{ r?x,{nqu{z8,mzp,?q,oqxqn~m€q,r?zpmyqz€mx,puo{?q~uq,mzp,|~mo€uomx,m||xuom€u{z,mxuwq:,M,qp?om€{~8,?q,mx{,?mx?q,~qqm~ot,m,m,|{€qz€,r{~y,{r,xqm~zuzs,n ,p{uzs:,`t~{?st,YU`%,azpq~s~mp?m€q,^qqm~ot,[||{~€?zu€uq,\~{s~my,4a^[\4{|qz,uz,zq?,?uzp{?558,y{~q,€tmz,DA1,{r,?zpq~s~mp?m€q,qz~uot,€tqu~,qp?om€u{z,€t~{?st,qzsmsuzs,uz,r~{z€xuzq8,rmo?x€ 9xqp,~qqm~ot: 凱撒密碼解密 解密結果:At MIT, pushing the boundaries of knowledge and possibility is our joyful obsession, and we celebrate fundamental discoveries and practical applications alike. As educators, we also value research as a potent form of learning by doing. Through MITs Undergraduate Research Opportunities Program (UROP(opens in new window)), more than 85% of undergraduates enrich their education through engaging in frontline, faculty-led research.------------------ (program exited with code: 0)請按任意鍵繼續. . . use std::str;fn encrypt(s:&str,passwd:u8)->Vec<char>{let mut s_asc=Vec::new();for c in s.chars() {let mut ascii=c as u8;ascii=ascii+passwd;let c_new=ascii as char;s_asc.push(c_new);}s_asc } fn decrypt(s:String,passwd:u8)->Vec<char>{let mut s_asc=Vec::new();for c in s.chars() {let mut ascii=c as u8;ascii=ascii-passwd;let c_new=ascii as char;s_asc.push(c_new);}s_asc } fn main() {//&str是一個切片(&[u8]),它總是指向一個有效的UTF-8序列,并且可以用來查看String,就像&[T]是Vec的一個視圖一樣// 對只讀內存中分配的字符串的引用let str1: &'static str = "At MIT, pushing the boundaries of knowledge and possibility is our joyful obsession, and we celebrate fundamental discoveries and practical applications alike. As educators, we also value research as a potent form of learning by doing. Through MIT’s Undergraduate Research Opportunities Program (UROP(opens in new window)), more than 85% of undergraduates enrich their education through engaging in frontline, faculty-led research.";//let a = "abcdefghi";println!("源字符串: {}", str1);let password:u8=12;//密碼// 凱撒密碼,加密println!("凱撒密碼加密");let new_str1:Vec<char> = encrypt(&str1,password);let result_str1:String = new_str1.iter().collect();// new_str1.reverse();println!("加密結果:{}",result_str1); println!("凱撒密碼解密");let new_str2:Vec<char> = decrypt(result_str1,password);let result_str2:String = new_str2.iter().collect();println!("解密結果:{}",result_str2); } 與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的rust(58)-凯撒密码的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。