曲路密码(Bend crypto)

阅读: 评论:0

曲路密码(Bend crypto)

曲路密码(Bend crypto)

曲路密码(Bend crypto)

  • 加密对象: 所有字符
  • 原理
    • 该密码和栅栏密码类似,是一种移位密码

    • 秘钥就是行列数,但我感觉只需要列数就好了(可能是我理解有问题),使用行列数构成一个表格,将明文依次填入,例如:行列为6列3行, 明文为: “flag{y0u_are_p1g@}”

      flag{y
      0u_are
      _p1g@}
    • 然后从最后一个字符像如下方式串起来即构成了密文:}ey{r@gaga_1pulf0_

  • 代码:
    # write by 2021/8/4
    # 曲路密码
    import redef encrypt_bend(string, col, row=10):ciphertext = ""temp = []for i in range(col):temp.append([])for index, i in enumerate(string):temp[index % col].append(i)re_temp = list(reversed(temp))for index, i in enumerate(re_temp):if index % 2 == 0:i = list(reversed(i))ciphertext += "".join(i)return ciphertextdef decrypt_bend(string, col, row=10):plaintext = ""length = len(string)min_row = length // col       # 最小的行数min_num = col - length % col  # 最小行数的列数# 分组temp = []index = 0for i in range(col):if i < min_num:temp.append(string[index:index+min_row])index += min_rowelse:temp.append(string[index:index+min_row+1])index += min_row + 1print(temp)# 改回列顺序for index, i in enumerate(temp):if index % 2 == 0:# print(re.findall(".{1}", temp[index]))temp[index] = "".join(list(reversed(re.findall(".{1}", temp[index]))))verse()for i in range(length):plaintext += temp[i % col][i // col]return plaintextif __name__ == '__main__':col_ = 7row_ = 5ciphertext_ = encrypt_bend("i will beat you this day", col_, row_)plaintext_ = decrypt_bend(ciphertext_, col_, row_)print(f"{plaintext_} : {ciphertext_}")

本文发布于:2024-02-04 14:29:29,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170709365056377.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:密码   Bend   crypto
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23