bugku——聪明的小羊(栅栏密码)


bugku——聪明的小羊


在这里插入图片描述
题目:一只小羊翻过了2个栅栏

KYsd3js2E{a2jda}
解题过程:
(1)总共16位——字母+{}+数字。
(2)栅栏数为:2.
(3)把密文分成2段,即KYsd3js2和E{a2jda}。
(4)K Y s d 3 j s 2
E { a 2 j d a }
(5)按照一上一下顺序依次写出明文,即KEY{sad2
3jjdsa2}。
(6)注意Flag输入格式 。
解码网站: http://ctf.ssleye.com/railfence.html
难度:简单

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Python可以使用以下方式实现凯撒密码和栅栏密码: 凯撒密码是一种简单的密码转换方法,通过对原文中的每个字母进行移位来加密和解密。在Python中,可以使用ord()和chr()函数来实现字母的ASCII码和字符之间的转换。 例如,我们要将明文字符串"HELLO"使用凯撒密码进行加密,假设移位值为3: ```python def caesar_cipher_encrypt(plaintext, shift): ciphertext = "" for char in plaintext: if char.isalpha(): # 只对字母进行加密 ascii_value = ord(char.upper()) # 转换为大写字母的ASCII码 shifted_ascii_value = (ascii_value - 65 + shift) % 26 + 65 # 字母移位 ciphertext += chr(shifted_ascii_value) # 转换为加密后的字符 else: ciphertext += char # 非字母字符直接添加到密文中 return ciphertext plaintext = "HELLO" shift = 3 ciphertext = caesar_cipher_encrypt(plaintext, shift) print(ciphertext) # 输出:KHOOR ``` 栅栏密码是一种换位密码,通过将明文的字母按照一定的规则重新排列来加密和解密。在Python中,可以使用循环和切片操作来实现栅栏密码。 例如,我们要将明文字符串"HELLO"使用栅栏密码进行加密,假设栏数为2: ```python def rail_fence_cipher_encrypt(plaintext, num_rails): rails = [[] for _ in range(num_rails)] # 创建栅栏列表 current_rail = 0 direction = 1 # 标识方向 for char in plaintext: rails[current_rail].append(char) # 根据当前栏添加字符 if current_rail == num_rails - 1: # 到达最后一栏时改变方向 direction = -1 elif current_rail == 0: # 回到第一栏时改变方向 direction = 1 current_rail += direction # 改变当前栏 ciphertext = "" for rail in rails: ciphertext += "".join(rail) # 将栏内字符拼接成密文 return ciphertext plaintext = "HELLO" num_rails = 2 ciphertext = rail_fence_cipher_encrypt(plaintext, num_rails) print(ciphertext) # 输出:HLOEL ``` 以上就是使用Python实现凯撒密码和栅栏密码的简单示例,这些代码可以作为基础来进一步扩展和优化。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值