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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

栅栏密码(Fence crypto)

發布時間:2023/12/31 编程问答 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 栅栏密码(Fence crypto) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

柵欄密碼(Fence crypto)

  • 加密對象: 所有字符

  • 原理:

    • 該密碼是一種移位密碼,將明文的順序按照某種規則打亂

    • 該密碼需要一個秘鑰,即在加密過程中需要使用到的列數,將明文按順序排成列,例如:列數為4,明文為: “i will beat you this day”,

      iwi
      llb
      eat
      you
      this
      day
    • 然后按照列順序組成明文,如表密文為: ileyt??laohdw tuiaib??sy

  • 代碼:

    # write by 2021/8/5 # 柵欄密碼def encrypt_fence(string, key):ciphertext = ""temp = []for i in range(key):temp.append("")for index, i in enumerate(string):temp[index % key] += i# print("".join(temp))ciphertext = "".join(temp)return ciphertextdef decrypt_fence(string, key):plaintext = ""length = len(string)min_row = length // keymax_num = length % keytemp = []index = 0for i in range(key):if i < max_num:temp.append(string[index:index+min_row+1])index += min_row + 1else:temp.append(string[index:index+min_row])index += min_row# print(temp)for i in range(length):plaintext += temp[i % key][i // key]return plaintextif __name__ == '__main__':key_ = 4ciphertext_ = encrypt_fence("i will beat you this day", key_)plaintext_ = decrypt_fence(ciphertext_, key_)print(f"{plaintext_} : {ciphertext_}")

總結

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

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