Example #1
0
    def print_results_details(self, publickeyname):
        """Print extra output according to requested action.
        Uncipher data if needed.
        """
        # check and print resulting private key
        if self.partitial_priv_key is not None and self.args.private:
            self.logger.info("d: %i" % self.partitial_priv_key.key.d)
            self.logger.info("e: %i" % self.partitial_priv_key.key.e)
            self.logger.info("n: %i" % self.partitial_priv_key.key.n)

        # If we wanted to decrypt, do it now
        if self.cipher and self.priv_key is not None:
            for cipher in self.cipher:
                if not isinstance(self.priv_key, list):
                    priv_keys = [self.priv_key]
                else:
                    priv_keys = self.priv_key

                for priv_key in priv_keys:
                    unciphered = priv_key.decrypt(cipher)
                    if not isinstance(unciphered, list):
                        unciphered = [unciphered]

                self.unciphered = self.unciphered + unciphered
        elif self.cipher and self.partitial_priv_key is not None:
            # needed, if n is prime and so we cant calc p and q
            enc_msg = bytes_to_long(self.cipher)
            dec_msg = self.partitial_priv_key.key._decrypt(enc_msg)
            self.unciphered.append(long_to_bytes(dec_msg))

        print_results(self.args, publickeyname, self.priv_key, self.unciphered)
Example #2
0
def main():
    args = parse_arguments()
    if args.task not in ['haystack', 'form', 'issue', 'target', 'multi']:
        print("User error: --task must be either " +\
                        "haystack, form, issue, target or multi.")
        sys.exit(0)

    # Read the article as string into variable
    with open(args.article, 'r') as file:
        text = file.read().replace('\n', '')

    model, tokenizer = load_model(args)

    # Tokenize article as input to model
    text_tokenized = torch.tensor([tokenizer.encode(text)])

    results = predict(model, text_tokenized, args)
    print_results(results, args)
    if args.output_path != '':
        store_results(results, args)
Example #3
0
        for uncipher in args.uncipherfile.split(","):
            try:
                with open(uncipher, "rb") as cipherfile_fd:
                    uncipher = get_base64_value(cipherfile_fd.read())
                    uncipher_array.append(uncipher)
            except OSError:
                logger.info("--uncipherfile : file not found or not readable.")
                exit(1)
        args.uncipher = uncipher_array

    # If we have a private key in input and uncipher in args (or uncipherfile)
    if args.key and args.uncipher:
        priv_key = PrivateKey(filename=args.key, password=args.password)
        for u in args.uncipher:
            unciphers.append(priv_key.decrypt(args.u))
        print_results(args, None, priv_key, unciphers)
        exit(0)

    # If we have n and one of p and q, calculated the other
    if args.n and (args.p or args.q):
        args.p, args.q = generate_pq_from_n_and_p_or_q(args.n, args.p, args.q)

    # convert a idrsa.pub file to a pem format
    if args.convert_idrsa_pub:
        # for publickey in args.publickey:
        publickeys = glob(args.publickey)
        for publickey in publickeys:
            logger.info("Converting %s: to pem..." % publickey)
            with open(publickey, "r") as key_data_fd:
                for line in key_data_fd:
                    n, e = disect_idrsa_pub(line.rstrip())