曲路密码(Bend crypto)

简介: 曲路密码(Bend crypto)

曲路密码(Bend crypto)

  • 加密对象: 所有字符
  • 原理
  • 该密码和栅栏密码类似,是一种移位密码
  • 秘钥就是行列数,但我感觉只需要列数就好了(可能是我理解有问题),使用行列数构成一个表格,将明文依次填入,例如:行列为6列3行, 明文为: “flag{y0u_are_p1g@}”
f l a g { y
0 u _ a r e
_ p 1 g @ }

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


5c18c117ab7948e697f59bbecfd4014f.png

代码:

# write by 2021/8/4
# 曲路密码
import re
def 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 ciphertext
def decrypt_bend(string, col, row=10):
    plaintext = ""
    length = len(string)
    min_row = length // col       # 最小的行数
    min_num = col - length % col  # 最小行数的列数
    # 分组
    temp = []
    index = 0
    for i in range(col):
        if i < min_num:
            temp.append(string[index:index+min_row])
            index += min_row
        else:
            temp.append(string[index:index+min_row+1])
            index += min_row + 1
    print(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]))))
    temp.reverse()
    for i in range(length):
        plaintext += temp[i % col][i // col]
    return plaintext
if __name__ == '__main__':
    col_ = 7
    row_ = 5
    ciphertext_ = encrypt_bend("i will beat you this day", col_, row_)
    plaintext_ = decrypt_bend(ciphertext_, col_, row_)
    print(f"{plaintext_} : {ciphertext_}")


目录
相关文章
|
4月前
|
Java 数据安全/隐私保护
Java 中使用 OpenSSL 生成公钥私钥进行数据加解密
Java 中使用 OpenSSL 生成公钥私钥进行数据加解密
66 0
|
3月前
|
网络安全 数据安全/隐私保护
【网络安全 | Crypto】初识RSA XSCTF
【网络安全 | Crypto】初识RSA XSCTF
27 0
【网络安全 | Crypto】初识RSA XSCTF
|
4月前
|
移动开发 JavaScript 安全
js的常见的三种密码加密方式-MD5加密、Base64加密和解密和sha1加密详解总结
js的常见的三种密码加密方式-MD5加密、Base64加密和解密和sha1加密详解总结
115 0
|
8月前
|
算法 安全 Java
Hutool-crypto 加密、解密详解!
Hutool-crypto 加密、解密详解!
288 0
|
6月前
|
数据安全/隐私保护
BCryptPasswordEncoder
BCryptPasswordEncoder
31 0
|
8月前
|
安全 Go 数据安全/隐私保护
Golang将密码盐加密
Golang将密码盐加密
72 0
|
9月前
|
算法 安全 Java
Security实现密码加密处理
Security实现密码加密处理
301 0
|
存储 JSON 负载均衡
crypto的加解密
散列函数(英语:Hash function)又称散列算法、哈希函数,是一种从任何一种数据中创建小的数字“指纹”的方法。基本原理是将任意长度数据输入,最后输出固定长度的结果。
|
安全 Java API
Java中使用Shiro实现对密码加盐并使用MD5加密处理
我们在保存用户密码等敏感信息的时候,需要进行加密处理保存,才能更安全地保护用户个人信息安全
227 0
|
算法 安全 量子技术
CTF_ CRYPTO(Cryptography)_密码学/密码编码学
CTF_ CRYPTO(Cryptography)_密码学/密码编码学
CTF_ CRYPTO(Cryptography)_密码学/密码编码学