aes-cbc一例

#!/usr/bin/python
from Crypto.Cipher import AES
import binascii
from Crypto.Util.number import bytes_to_long
from flag import flag
import random
import string
import os

def genkey(l):
    return random.getrandbits(l)

iv = flag.strip(b'flag{').strip(b'}')

key = ''.join([random.choice(string.ascii_letters+string.digits) for _ in xrange(16)])
LENGTH = len(key)
assert LENGTH == 16

hint = os.urandom(4) * 8
print(bytes_to_long(hint)^bytes_to_long(key))

msg = b'Welcome, ctfer. Dont try too hard, its no use. Have a good day!!'

def encrypto(message):
    aes = AES.new(key,AES.MODE_CBC,iv)
    return aes.encrypt(message)

print(binascii.hexlify(encrypto(msg))[-32:])

'''
99748265546679089946917295913637945222843938798184123305418691873367322323659
bc03f3ac4ff8064acbcfaf0b0bf2ba7b
'''

本质是倒推出初始向量iv

msg共64byte,分为4组,给出最后一组的密文。key可以求出。

#!/usr/bin/python
from Crypto.Cipher import AES
import binascii
from Crypto.Util.number import *
from Crypto.Util.strxor import strxor as xor


msg = b'Welcome, ctfer. Dont try too hard, its no use. Have a good day!!'

hint=99748265546679089946917295913637945222843938798184123305418691873367322323659
c=0xbc03f3ac4ff8064acbcfaf0b0bf2ba7b
key=(hint>>(16*8))^(hint&((1<<16*8)-1))


key=long_to_bytes(key)
byte_c=long_to_bytes(c)

for msg_i in range(3,-1,-1):
    aes = AES.new(key,AES.MODE_ECB)
    print(msg[msg_i*16:msg_i*16+16])
    byte_c=xor(aes.decrypt(byte_c),msg[msg_i*16:msg_i*16+16])
print(byte_c)

相关推荐

  1. aes-cbc

    2024-06-10 17:44:01       37 阅读
  2. C# AES-128-CBC 加密

    2024-06-10 17:44:01       51 阅读
  3. openssl3.2 - exp - aes-128-cbc

    2024-06-10 17:44:01       30 阅读
  4. 代码示例:OpenSSL AES CBC 加密

    2024-06-10 17:44:01       32 阅读
  5. rust - 基于AES-CBC-128的双重加密实现

    2024-06-10 17:44:01       40 阅读
  6. rust - 基于AES-CBC-128的图片加密实现

    2024-06-10 17:44:01       36 阅读
  7. flink-cdc-学习笔记()

    2024-06-10 17:44:01       43 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-10 17:44:01       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-10 17:44:01       106 阅读
  3. 在Django里面运行非项目文件

    2024-06-10 17:44:01       87 阅读
  4. Python语言-面向对象

    2024-06-10 17:44:01       96 阅读

热门阅读

  1. 关于在 Ubuntu 下安装配置和调优 FTP 服务器

    2024-06-10 17:44:01       29 阅读
  2. 中介子方程十

    2024-06-10 17:44:01       33 阅读
  3. Mac环境如何使用Flutter Version Manager (fvm)

    2024-06-10 17:44:01       32 阅读
  4. 【Python入门与进阶】常见问题与解决方法

    2024-06-10 17:44:01       41 阅读
  5. 华为坤灵路由器配置telnet

    2024-06-10 17:44:01       34 阅读
  6. Position定位

    2024-06-10 17:44:01       32 阅读
  7. Docker日志相关命令

    2024-06-10 17:44:01       37 阅读
  8. TiDB Distributed NewSQL Database

    2024-06-10 17:44:01       35 阅读
  9. qt c++ 大小端字节序数据获取与转换

    2024-06-10 17:44:01       27 阅读
  10. GMT legend设置

    2024-06-10 17:44:01       38 阅读
  11. docker-compose部署mysql+nginx+redis

    2024-06-10 17:44:01       37 阅读
  12. vue面试题三

    2024-06-10 17:44:01       35 阅读
  13. C语言考试内容

    2024-06-10 17:44:01       27 阅读