示例#1
0
 def attack(self):
     message = b'\x00admin\x00true\x00'
     ciphertext = bytearray(self.oracle.encrypt(message))
     ciphertext[48] = bl(xor(bytes([ciphertext[48]]), self.semi_colon))
     ciphertext[48 + 6] = bl(xor(bytes([ciphertext[48 + 6]]), self.equal))
     ciphertext[48 + 11] = \
             bl(xor(bytes([ciphertext[48 + 11]]), self.semi_colon))
     return self.oracle.decrypt(ciphertext)
示例#2
0
def enc():
    global flag, ctr, go, e, n, pt, ct
    ct = pow(
        inc() * bl(pt) + (inc() << len(
            bin(
                bl(flag + "".join(
                    choice(ascii_uppercase + ascii_lowercase + digits)
                    for _ in range(16))))[2:])), e, n)
示例#3
0
def select_mission():
    m = {i + 1: i + 1024 for i in range(8)}
    print('Select mission:')
    [print('{}. Code {}'.format(k, v)) for k, v in m.items()]
    op = int(input('>> '))
    if op in m:
        KEY = RSA.import_key(
            open(os.path.join('keys',
                              str(1023 + op) + '.pem'), 'rb').read())
        assert KEY.n.bit_length() == m[op]
        KEY.o_o = math.ceil(KEY.n.bit_length() / 8)
        print('Here is your ID for this mission = ({},{},{})'.format(
            KEY.n, KEY.e, encrypt(bl(flag), KEY)))
        return KEY
    else:
        print('You are definitely not 007!')
        exit(0)
示例#4
0
 def encrypt(self, data):
     plaintext = self.prefix
     plaintext += data.replace(b';', b'?').replace(b'=', b'?')
     plaintext += self.suffix
     nonce = bl(urandom(self.blocksize // 2))
     return self.ctr.encrypt(nonce, plaintext)
示例#5
0
def encrypt(pt, key):
    pt = AGENT_CODE + AGENT_MESSAGE + lb(pt)
    pt = pt + os.urandom(key.o_o - len(pt))
    ct = pow(bl(pt) * 0x007 % key.n, key.e, key.n)
    return ct