吳宗恩
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # 古典密碼學 ## 簡介 密碼學是一門研究如何保護信息安全的學科,主要包含加密技術、解密技術、訊息驗證及金鑰管理等領域。密碼學的目標是確保機密性、完整性、身份驗證和不可否認性。 ## 凱薩密碼 * 將字母一固定為依加密 * 優點 * 簡單易實作:只需固定位移量即可加密 * 運算速度快:加密和解密只需進行位移計算 * 缺點 * 極易破解:僅有 25 種可能的密鑰,可以暴力破解。 * 易受頻率分析攻擊:由於字母的相對順序不變,攻擊者可以透過常見字母頻率 ### Code 加密 ```cpp= #include<bits/stdc++.h> using namespace std; string casar(string text,int shift,int dir){ if(dir<0) shift=26-shift; string ans=""; for(char c : text){ if(isalpha(c)){ char base=isupper(c)? 'A' : 'a'; ans+=(c-base+shift)%26+base; } else ans+=c; } return ans; } ``` 解密 ```cpp= #include<bits/stdc++.h> using namespace std; string key(string text,int shift,int dir){ if(dir>0)return casar(text,26-shift,-dir); else return casar(text,shift,-dir) } ``` ## 維吉尼亞密碼 * 利用關鍵字進行多表替換,加強安全性 * 優點 * 適用於較長文本:使用關鍵字來變化加密方式,增強安全性 * 缺點 * 如果關鍵字過短,仍然容易被破解 : 透過卡西斯基檢驗找到重複模式後可以破解。 * 需要記住關鍵字:比起單一位移,需記住更長的密鑰 ### Code 加密 ```cpp= #include<bits/stdc++.h> using namespace std; string extend(string text,string key){ string extendkey=""; int keylen=key.size(); for(int i=0; i<text.size(); i++) extendkey+=key[i%keylen]; return extendkey; } string encrypt(string text,string key){ string ans=""; key=extend(text,key); for(int i=0; i<text.size(); i++){ if(isalpha(text[i])){ char base=isupper(text[i])? 'A' : 'a'; ans+=(text[i]-base+(key[i]-base))%26+base; } else ans+=text[i]; } } ``` 解密 ```cpp= #include<bits/stdc++.h> using namespace std; string decrypt(string text, string key){ string ans=""; key=extend(text, key); for(int i=0;i<text.size();i++){ if(isalpha(text[i])){ char base=isupper(text[i])? 'A' : 'a'; ans+=(text[i]-base-(key[i]-base)+26)%26+base; } else ans+=text[i]; } return ans; } ``` ### 補充-卡西斯基檢驗 #### 破解原理 1.尋找密文中重複的字母序列 * 例如密文:RIJVS UYVJN RIJVS,發現 RIJVS 重複出現。 2.記錄這些重複字串的間距 * 例如,RIJVS 出現在密文的第 1 和 11 個位置,間距為 10。 * 假設還有其他重複字串,間距可能是 5, 10, 15...。 3.找出這些間距的 最大公因數 (GCD) * 如果這些間距的最大公因數為 5,那麼關鍵字長度很可能是 5。 4.將密文拆分為多組單獨的凱撒密碼進行破解 * 一旦知道關鍵字長度,將密文分成 5 組,然後對每組單獨執行**頻率分析攻擊**,破解凱撒密碼。 ## 單表代換密碼 * 單表代換密碼是固定對應關係的替換密碼,每個字母都被唯一對應到另一個字母。不同於凱撒密碼的固定位移,單表代換的對應關係可以是任意排列,因此比凱撒密碼更難破解。 * 優點 * 增加混淆性:攻擊者無法輕易知道加密規則。 * 缺點 * 仍然受頻率分析攻擊影響:每個字母的對應關係固定,因此可以根據字母出現頻率進行破解。 * 密鑰需要儲存與管理:如果對應表洩漏,加密內容將不再安全。 ### Code 創建映射表 ```cpp= #include<bits/stdc++.h> using namespace std; unordered_map<char, char> graph(string src, string target){ unordered_map<char, char> mapping; for(int i=0; i<src.size(); i++){ mapping[src[i]]=target[i]; mapping[tolower(src[i])]=tolower(target[i]); } return mapping; } ``` 加密 ```cpp= string encrypt(string text,unordered_map<char, char> &encryptmap){ string ans=""; for(char c : text) ans+=encryptmap.count(c)? encryptmap[c] : c; return ans; } ``` 解密 ```cpp= string decrypt(string text,unoudered_map<char,char> &decryptmap){ string ans=""; for(char c : text) ans+=decryptmap.count(c)? decryptmap[c] : c; return ans; } ``` ### 結論 古典密碼學已不再安全,但它是現代密碼學的起點,為今日的資訊安全技術奠定了堅實的基礎。

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully