def dict_attack(): found = False for p in pass_list: v = pow(g, sha256().intdigest(salt + p.encode()), N) s = pow(pk * pow(v, u, N), b, N) k = sha256().digest(int2bytes(s)) if sha256().hmac(salt, k).hex() == hmac: found = True break return p if found else None
def decrypt(self, msg, tobytes=False): if type(msg) == bytes: msg = int.from_bytes(msg, 'big') msg = pow(msg, self.d, self.n) return int2bytes(msg) if tobytes else msg
def decrypt_unpadded(ct, oracle): e, n = oracle.publickey() ct_new = (pow(2, e, n) * ct) % n # s = 2 pt_new = oracle.decrypt(ct_new) pt = pt_new * invmod(2, n) % n return int2bytes(pt)
def session_key(self, pk): s = pow(int(pk, 16) * pow(self.v, self.u, N), self.priv, N) self.key = sha256().digest(int2bytes(s))
def session_key(self, pk): u = sha256().intdigest(bytes.fromhex(pk) + self.publickey()) s = pow(int(pk, 16) * pow(self.v, u, N), self.priv, N) self.key = sha256().digest(int2bytes(s))
def publickey(self, tobytes=True): if tobytes: return int2bytes(k * self.v + super().publickey(False)) return k * self.v + super().publickey(False)
def session_key(self, salt, pk, u): self.salt = salt x = sha256().intdigest(salt + P) s = pow(pk, self.priv + u * x, N) self.key = sha256().digest(int2bytes(s))