コード例 #1
0
 def find_multiple_key_test(self):
     key_a, key_b, key_c = [encryption.generate_key() for _ in range(3)]
     self.assertEqual([key_a, key_b, key_c],
                      encryption.get_keys(
                          "Key A: {}, Key B: {}, Key C: {}".format(
                              key_a, key_b, key_c)))
     self.assertEqual([key_a, key_c, key_b, key_a],
                      encryption.get_keys(key_a + key_c + key_b + key_a))
コード例 #2
0
    def find_single_key_test(self):
        key = encryption.generate_key()
        self.assertEqual(
            [key],
            encryption.get_keys(
                "some text some text some text {} some text some text some text"
                .format(key)))
        self.assertEqual([key], encryption.get_keys(key))

        self.assertEqual([key] * 7, encryption.get_keys(key * 7))
コード例 #3
0
    def attempt_decryption(self, keys):
        if self.decryption_keypage:
            try:
                response = requests.get(self.decryption_keypage)
                response.raise_for_status()
                keys_data = response.content.decode('utf-8')
                keys = keys + encryption.get_keys(keys_data)
            except Exception as e:
                print_error("Could not load decryption page {}: {}.".format(
                    self.decryption_keypage, e))
                print_error(
                    "You can pass in a key directly by running python3 ok --decrypt [KEY]"
                )

        decrypted_files = []
        undecrypted_files = []
        for file in self._get_files():
            with open(file) as f:
                if not encryption.is_encrypted(f.read()):
                    continue
            for key in keys:
                success = self._decrypt_file(file, key)
                if success:
                    decrypted_files.append(file)
                    break
            else:
                undecrypted_files.append(file)
        return decrypted_files, undecrypted_files