2025年关键字密码(Nihilist)

关键字密码(Nihilist)关键字密码 Nihilist 加密对象 小写字母 原理 是棋盘密码的变种 相对于棋盘密码 改密码的密码表是变化的 相对于关键字而变化 关键字就是一种秘钥 由字母组成 由加密双方约定而成 密码表有 25 个位置 依次不重复的填入秘钥 在不重复的填入 a z

大家好,我是讯享网,很高兴认识大家。

关键字密码(Nihilist)

  • 加密对象:小写字母
  • 原理:
    • 关键字就是一种秘钥,由字母组成,由加密双方约定而成。密码表有25个位置,依次不重复的填入秘钥,在不重复的填入a~z.
    • 如:秘钥为linux,则密码表为:


      讯享网

      1 2 3 4 5
      1 l i n u x
      2 a b c d e
      3 f g h k m
      4 o p q r s
      5 t v w y z
    • 在将明文的每个字符通过查表找出行号和列号,行号在前,列号在后就组成了密文,最后将所有字符的密文以空格隔开组成最后的密文
    • 如:在"linux"为关键字的情况下,加密"abc"
      • a -> 21
      • b -> 22
      • c -> 23
      • 故密文为: “21 22 23”
    是棋盘密码的变种,相对于棋盘密码,改密码的密码表是变化的,相对于关键字而变化
  • 代码
    # write by 2021/7/6 # 关键字密码,一种棋盘密码的变种 def create_table(key): key = key + "abcdefghiklmnopqrstuvwxyz" table = "" for i in key.replace("j", "i"): if i not in table: table += i return table def encrypt_nihilist(string, key): ciphertext = "" table = create_table(key) for i in string.replace("j", "i").replace(" ", ""): if i in table: index = table.index(i) ciphertext += str(index // 5 + 1) + str(index % 5 + 1) + " " else: return -1 return ciphertext.strip() def decrypt_nihilist(string, key): plaintext = "" table = create_table(key) lis = string.split(" ") try: for i in lis: index = (int(i[0]) - 1) * 5 + int(i[1]) - 1 plaintext += table[index] if table[index] == "i": plaintext += "(j)" except: return -1 return plaintext if __name__ == '__main__': ciphertext_ = encrypt_nihilist("linux", "linux") plaintext_ = decrypt_nihilist(ciphertext_, "linux") print(f"{plaintext_}: {ciphertext_}") 

    讯享网
小讯
上一篇 2025-03-28 14:58
下一篇 2025-03-05 22:50

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/86771.html