@@ -0,0 +1,2405 @@
+#!/usr/bin/env python3%0A# -*- coding: utf-8 -*-%0A%0Afrom __future__ import absolute_import, division, unicode_literals%0A%0A# Copyright (C) 2018 Ben McGinnes %3Cben@gnupg.org%3E%0A#%0A# This program is free software; you can redistribute it and/or modify it under%0A# the terms of the GNU General Public License as published by the Free Software%0A# Foundation; either version 2 of the License, or (at your option) any later%0A# version.%0A#%0A# This program is free software; you can redistribute it and/or modify it under%0A# the terms of the GNU Lesser General Public License as published by the Free%0A# Software Foundation; either version 2.1 of the License, or (at your option)%0A# any later version.%0A#%0A# This program is distributed in the hope that it will be useful, but WITHOUT%0A# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS%0A# FOR A PARTICULAR PURPOSE.  See the GNU General Public License and the GNU%0A# Lesser General Public Licensefor more details.%0A#%0A# You should have received a copy of the GNU General Public License and the GNU%0A# Lesser General Public along with this program; if not, see%0A# %3Chttp://www.gnu.org/licenses/%3E.%0A%0Aimport gpg%0Aimport sys%0A%0A%22%22%22%0AEncrypts a file to a specified key.  If entering both the key and the filename%0Aon the command line, the key must be entered first.%0A%0AWill produce both an ASCII armoured and GPG binary format copy of the encrypted file.%0A%22%22%22%0A%0Aif len(sys.argv) %3E 3:%0A    a_key = sys.argv%5B1%5D%0A    filename = %22 %22.join(sys.argv%5B2:%5D)%0Aelif len(sys.argv) == 3:%0A    a_key = sys.argv%5B1%5D%0A    filename = sys.argv%5B2%5D%0Aelif len(sys.argv) == 2:%0A    a_key = sys.argv%5B1%5D%0A    filename = input(%22Enter the path and filename to encrypt: %22)%0Aelse:%0A    a_key = input(%22Enter the fingerprint or key ID to encrypt to: %22)%0A    filename = input(%22Enter the path and filename to encrypt: %22)%0A%0Arkey = list(c.keylist(pattern=a_key, secret=False))%0Awith open(filename, %22rb%22) as f:%0A    text = f.read()%0A%0Awith gpg.Context(armor=True) as ca:%0A    ciphertext, result, sign_result = ca.encrypt(text, recipients=rkey,%0A                                                 sign=False)%0A    with open(%22%7B0%7D.asc%22.format(filename), %22wb%22) as fa:%0A        fa.write(ciphertext)%0A%0Awith gpg.Context() as cg:%0A    ciphertext, result, sign_result = ca.encrypt(text, recipients=rkey,%0A                                                 sign=False)%0A    with open(%22%7B0%7D.gpg%22.format(filename), %22wb%22) as fg:%0A        fg.write(ciphertext)%0A

encrypt file