示例#1
0
def encrypt(pt):
    pt = junk() + pt + junk()
    k, iv = util.rbytes(16), util.rbytes(16)
    if util.rbool():
        return "ECB", util.AesEcbCipher(k).encrypt(pt)
    else:
        return "CBC", util.AesCbcCipher(k, iv).encrypt(pt)
示例#2
0
 def __init__(self):
     self.ecb = util.AesEcbCipher(util.rbytes(16))
     self.suffix = base64.b64decode(INPUT)
示例#3
0
def create_ct(known_pt):
    seed = util.rint(0, 0xFFFF)
    pt = util.rbytes(util.rint(1, 20)) + known_pt
    return seed, MtCipher(seed).crypt(pt)
示例#4
0
 def __init__(self):
     self.key = util.rbytes(16)
示例#5
0
 def create_token(self, userdata: str) -> bytes:
     if ";" in userdata or "=" in userdata:
         raise ValueError("invalid userdata")
     s = f"comment1=cooking%20MCs;userdata={userdata};comment2=%20like%20a%20pound%20of%20bacon"
     nonce = util.rbytes(8)
     return nonce + util.AesCtrCipher(self.key, nonce).crypt(s.encode())
示例#6
0
def test_solve():
    ecb = util.AesEcbCipher(b"YELLOW SUBMARINE")
    ctr = AesCtrEditingCipher(util.rbytes(16), util.rbytes(8))
    with open("files/25.txt") as f:
        pt = ecb.decrypt(base64.b64decode(f.read()))
    assert recover_pt(ctr, ctr.crypt(pt)) == pt
示例#7
0
def test_aes_ecb_cipher():
    for n in range(1, 33):
        k, pt = util.rbytes(16), util.rbytes(n)
        cipher = util.AesEcbCipher(k)
        assert cipher.decrypt(cipher.encrypt(pt)) == pt
示例#8
0
def test_aes_ctr_cipher():
    for n in range(1, 33):
        k, n, pt = util.rbytes(16), util.rbytes(8), util.rbytes(n)
        cipher = util.AesCtrCipher(k, n)
        assert cipher.crypt(cipher.crypt(pt)) == pt
示例#9
0
def test_aes_cbc_cipher():
    for n in range(1, 33):
        k, iv, pt = util.rbytes(16), util.rbytes(16), util.rbytes(n)
        cipher = util.AesCbcCipher(k, iv)
        assert cipher.decrypt(cipher.encrypt(pt)) == pt
示例#10
0
def junk():
    return util.rbytes(util.rint(5, 10))  # 5-10 random bytes.
示例#11
0
 def __init__(self):
     self.key = util.rbytes(16)
     self.cbc = util.AesCbcCipher(self.key, self.key)
示例#12
0
 def create_token(self):
     iv, pt = util.rbytes(16), util.rchoice(self.secrets)
     return iv + util.AesCbcCipher(self.key, iv).encrypt(pt)
示例#13
0
 def __init__(self):
     self.key = util.rbytes(16)
     self.secrets = [base64.b64decode(s) for s in INPUT.split()]
示例#14
0
 def __init__(self):
     self.ecb = util.AesEcbCipher(util.rbytes(16))
示例#15
0
def create_cts(s):
    pts = [base64.b64decode(line) for line in s.split()]
    k, n = util.rbytes(16), util.rbytes(8)
    return [util.AesCtrCipher(k, n).crypt(pt) for pt in pts]