Exemple #1
0
def main(new_args, get_model_fn):

    args = Nestedspace()
    args.load_from_json(osp.join(new_args.path, 'args.json'))
    args.from_dict(new_args.to_dict())  # override previous args

    device = torch.device(args.device)
    cudnn.benchmark = False

    print(
        hue.info(
            hue.bold(hue.lightgreen('Working directory: {}'.format(
                args.path)))))

    np.random.seed(args.seed)
    torch.manual_seed(args.seed)
    torch.cuda.manual_seed_all(args.seed)

    gallery_loader, probe_loader = get_data_loader(args, train=False)

    model = get_model_fn(args, training=False, pretrained_backbone=False)
    model.to(device)

    args.resume = osp.join(args.path, 'checkpoint.pth')
    args, model, _, _ = resume_from_checkpoint(args, model)

    name_to_boxes, all_feats, probe_feats = \
        inference(model, gallery_loader, probe_loader, device)

    print(hue.run('Evaluating detections:'))
    precision, recall = detection_performance_calc(gallery_loader.dataset,
                                                   name_to_boxes.values(),
                                                   det_thresh=0.01)

    print(hue.run('Evaluating search: '))
    gallery_size = 100 if args.dataset == 'CUHK-SYSU' else -1
    ret = gallery_loader.dataset.search_performance_calc(
        gallery_loader.dataset,
        probe_loader.dataset,
        name_to_boxes.values(),
        all_feats,
        probe_feats,
        det_thresh=0.5,
        gallery_size=gallery_size)

    # import IPython
    # IPython.embed()
    return ret['mAP']
Exemple #2
0
def download_mp4(capitol):
    # Create save directory
    save_dir = Path("capitols")
    try:
        save_dir.mkdir()
    except FileExistsError:
        pass
    file_name = Path(f"{capitol['nom_friendly']}.mp4")
    if (save_dir / file_name).exists():
        print(good(f"{file_name} already exists"))
    else:
        print(run(f"Downloading {file_name}"))
        wget.download(capitol["url_mp4"], str(save_dir / file_name))
        print()
        print(good(f"{file_name} correctly downloaded"))
Exemple #3
0
 def connect(self, host, port, name, user, password):
     self.hashobject.update(password.encode('utf-8'))
     try:
         self.socket.connect((host, port))
         print(huepy.run('Successfully connected'))
         self.socket.send(
             str({
                 'type': 'login',
                 'database': str(name),
                 'user': str(user),
                 'password': self.hashobject.hexdigest()
             }).encode('utf-8'))
     except:
         print(
             huepy.bad(
                 'Connection failed, please check the network or address'))
         return False
     returnValue = dict(eval(self.socket.recv(3012)))
     if returnValue['type'] == 'error':
         if returnValue['state'] == '404':
             print(
                 huepy.bad(
                     'Connection failed, please check the address or databasename'
                 ))
             return False
         elif returnValue['state'] == '1304':
             print(
                 huepy.bad(
                     'Connection failed, please check the username or password'
                 ))
             return False
         else:
             print(huepy.bad('Connection failed'))
             return False
     elif returnValue['type'] == 'token':
         self.Token = returnValue['token']
         print(
             huepy.good('Downloaded identity certificate:' +
                        returnValue['token']))
         return True
Exemple #4
0
def run(text):
    print(huepy.run(text))
Exemple #5
0
 def print_stats(self):
     print(run(bg("Turn #{}".format(self.game.current_turn))))
     self.player.output_stats()
Exemple #6
0
from binascii import hexlify
from utils import hex2dec, xor_strings
from huepy import run, info, good, bad

if __name__ == '__main__':

    # Write a function that takes two equal-length buffers
    # and produces their XOR combination.

    # If your function works properly, then when you feed it the string:
    string1_hex = "1c0111001f010100061a024b53535009181c"
    print(run(f'string1 hex: {string1_hex}'))
    string1_dec = hex2dec(string1_hex, True)
    print(run(f'string1 decoded: {string1_dec}'))

    # ... after hex decoding, and when XOR'd against:
    string2_hex = "686974207468652062756c6c277320657965"
    print(run(f'string2 hex: {string2_hex}'))
    string2_dec = hex2dec(string2_hex, True)
    print(run(f'string2 decoded: {string2_dec}'))

    # ... should produce:
    expected_result = "746865206b696420646f6e277420706c6179"
    xored_dec = xor_strings(string1_dec, string2_dec, bytes_out=True)
    print(info(f'xored_decoded: {xored_dec}'))
    xored_hex = hexlify(xored_dec).decode('utf-8')
    print(info(f'xored_hex: {xored_hex}'))
    print(info(f'expected_result: {xored_hex}'))
    if xored_hex == expected_result:
        print(good('result true'))
    else:
Exemple #7
0
    real_ciphertext = encryption_oracle.encrypt(prefix)
    for i in range(256):
        test_ciphertext = encryption_oracle.encrypt(prefix + known_bytes +
                                                    bytes([i]))
        if test_ciphertext[:test_length] == real_ciphertext[:test_length]:
            return bytes([i])
    return b''


if __name__ == '__main__':

    data = read_data('12')

    encryption_oracle = EncryptionOracleECB(data)

    print(run("Discovering block size..."))
    block_size = discover_block_size(encryption_oracle)
    print(good(f"Block size: {block_size} bytes"))
    if not detect_ecb_mode(encryption_oracle):
        print(bad("The cipher is NOT using ECB mode"))
    else:
        print(info("The cipher is using ECB mode"))
        decrypted_data = b''
        data_length = len(encryption_oracle.encrypt(b''))
        for i in range(data_length):
            next_byte = find_byte(encryption_oracle, block_size,
                                  decrypted_data)
            decrypted_data += next_byte
            # print(decrypted_data)
            print(run("Decrypting: " +
                      "{:4.2f}".format(100 * (i + 1) / data_length) + "%"),
Exemple #8
0
#!/usr/bin/env python3

# huepy muss vorher installiert werden.
import huepy

print(huepy.bold(huepy.red("red and bold")))

print(huepy.run("Starte..."))
print(huepy.info("Info!!"))
print(huepy.bad("Schlecht!"))
print(huepy.good("Gut!"))
input(huepy.que("Frage? "))

# mit Fortschritt:
from tqdm import tqdm

for x in tqdm(range(5000000), desc=huepy.run("Dinge")):
    pass

        rpn_pre_nms_top_n_test=args.test.rpn_pre_nms_top_n,
        rpn_post_nms_top_n_test=args.test.rpn_post_nms_top_n,
        rpn_nms_thresh=args.test.rpn_nms_thresh,
        # Box parameters
        box_nms_thresh=args.test.nms,
        box_detections_per_img=args.test.rpn_post_nms_top_n,
    )
    model.to(device)

    args.resume = osp.join(args.path, 'checkpoint.pth')
    args, model, _, _ = resume_from_checkpoint(args, model)

    name_to_boxes, all_feats, probe_feats = \
        inference(model, gallery_loader, probe_loader, device)

    print(hue.run('Evaluating detections:'))
    precision, recall = detection_performance_calc(gallery_loader.dataset,
                                                   name_to_boxes.values(),
                                                   det_thresh=0.01)

    print(hue.run('Evaluating search: '))
    gallery_size = 100 if args.dataset == 'CUHK-SYSU' else -1
    ret = gallery_loader.dataset.search_performance_calc(
        gallery_loader.dataset,
        probe_loader.dataset,
        name_to_boxes.values(),
        all_feats,
        probe_feats,
        det_thresh=0.5,
        gallery_size=gallery_size)
Exemple #10
0
        print(info(f"Oracle: {lpurple('ECB')}"))
    else:
        iv = generate_aes_key()
        cipher_text = aes128_cbc_encrypt(plain_text_ext, iv, key)
        print(info(f"Oracle: {lblue('CBC')}"))

    return cipher_text


if __name__ == '__main__':
    '''
    This function detect if ECB of CBC mode is used
    The problem with ECB is that it is stateless and deterministic; the same
    16 byte plaintext block will always produce the same 16 byte ciphertext.
    Due that, if we generate always the same data, the ecb mode will be always
    output the same ciphertext (except the random bytes added)
    '''

    data = bytes([0]) * 200
    cipher_text = encryption_oracle(data)

    blocks = divide_in_blocks(cipher_text, 16)
    num_repeated_blocks = len(blocks) - len(set(blocks))

    if num_repeated_blocks:
        print(run(f"Number of repeated blocks: {red(num_repeated_blocks)}"))
        print(good(f"The cipher is using {lpurple('ECB')} mode"))
    else:
        print(run(f"Number of repeated blocks: {green(num_repeated_blocks)}"))
        print(good(f"The cipher is using {lblue('CBC')} mode"))