1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
#!/usr/bin/python
#FireGPG replacement for Ubuntu 11.04 (Converted to Python by Author) 
#by nullbyt3
import getpass
import sys
import os




def banner():
    os.system('clear')
    print "-------------------------------------------------------------------------------"
    print "\t\t\t****Welcome to the GnuPG ****\n\t[*]File Encrypter/Decrypter--Key finder/Importer/Exporter/Deleter[*]\n\t\t\t[*]Built in Nano Text Editor![*]"
    print "--------------------------------[*]by nullbyt3[*]------------------------------"


def opts():
    opts = ["(1)Encrypt a File?","(2)Decrypt a file?", "(3)List ALL Keys?","(4)Grep for particular key?","(5)Import a Key?","(6)Export Public key to file?",
               "(7)Delete a Key?", "(8)GPG Text editor?(create a file then Encrypt/Decrypt it)" ,"(9)Move or Backup keys(public and/or private) to a new location?",
             "(10)Exit Program?"]
  
    for i in opts: 
        print(i)


def get_pass():
    you = getpass.getuser()
    if you != 'root':
        pass
    else:
        print "\n\n\t\t\t[-]ERROR: This is Not Good:[-] \n\n\t\t\tYour running the program as root.\n\n\t\t\tPlease exit root and try again\n\n\n"
        exit(1)    

def main():
    banner()
    get_pass()
    opts()
    resp = raw_input("Please choose an option: ")   
    if resp == '1': 
        file_encrypt = raw_input("File to Encypt:")   
        key_set = raw_input("Key to use: ")
        encrypt_cmd = 'gpg --recipient %s --armor --encrypt %s' % (key_set,file_encrypt)
        try:
            os.system(encrypt_cmd)
            is_valid = "echo $?"
            check = os.system(is_valid)
            if check == 0:
                print "[+]File Encrypted![+]"
                sys.exit(0)
            else:
                print "[-]Error Code: %s[-]" %(check) 
                sys.exit(1)
        except IndexError as e:
            print "Error Encrypting file"
    
        except KeyboardInterrupt:      
            print("Bye :)")


    elif resp == '2': 
        file_decrypt = raw_input("File to decrypt: ")
        file_out = raw_input("Outfile to use: ")
        decrypt_cmd = 'gpg --output %s --decrypt %s' %(file_out,file_decrypt)
        try:
            os.system(decrypt_cmd)
            valid = "echo $?"
            check = os.system(valid)
            if check == 0:
                print "[+]File successfully Decrypted![+]\n\nYou can find the message here: %s" % (file_out)
                sys.exit(0)
            else:
                print "[-]Error Code: %s[-]" %(check)  
                sys.exit(1)
        except IndexError as e:
            print "Error Decrypting file"

        except KeyboardInterrupt:      
            print("Bye :)")

    elif resp == '3': 
        gpg_cmd = 'gpg --list-keys | more'
        try:
            os.system(gpg_cmd)
            sys.exit(0)
        except IndexError, e:
            print "Error Encrypting file"

    elif resp == '4':
        key_grep = raw_input("Key to look for(Partial names are ok, it will be found): ")
        cmd = 'gpg --list-keys | grep %s' % (key_grep)
        try:
            os.system(cmd)
            sys.exit(0)
        except IndexError, e:
            print "Error Encrypting file"

        except KeyboardInterrupt:      
            print("Bye :)")

    elif resp == '5': 
        key_import = raw_input("Key to import(Full path to key is needed,please): ") 
        key_import_cmd = 'gpg --import %s' %(key_import)
        try:
            os.system(key_import_cmd)
            is_valid = "echo $?"
            check = os.system(is_valid)
            if check == 0:
                print "[+]Key Successfully imported![+]"
                sys.exit(0)
            else:
                print "[-]Error Code: %s[-]" %(check)
                sys.exit(1)
        except IndexError as e:
                print "Error Encrypting file"

        except KeyboardInterrupt:      
            print("Bye :)")

    elif resp == '6': 
        key_to_file = raw_input("Key to export to file: ")
        export_file = raw_input("Outfile to use?(key.asc is default location.)\n\nTo choose another location type in the full path:")   
        if export_file: 
            export_key_cmd = 'gpg --armor --export %s.asc -o %s' %(export_file,key_to_file)
            try:
                os.system(export_key_cmd)
                is_valid = "echo $?"
                check = os.system(is_valid)
                if check == 0:
                    print "[+]Key Exported![+]\n\nYou can find it under %s.asc" %(export_file)
                    sys.exit(0)
                else:
                    print "[-]Error Code: %s[-]" %(check)
                    sys.exit(1)
            except IndexError as e:
                print "Error Encrypting file"

            except KeyboardInterrupt:      
                print("Bye :)")
 
        else:
            default_export_key_cmd = "gpg --armor -o key.asc --export %s" %(key_to_file)
            try:
                os.system(default_export_key_cmd)
                is_valid = "echo $?"
                check = os.system(is_valid)
                if check == 0:
                    print "[+]Key Exported!\n\nYou can find it in the current directory under: key.asc\n"
                    sys.exit(0)
                else:
                    print "[-]Error Code: %s[-]" %(check)
                    sys.exit(1)
#118
            except IndexError as e:
                print "Error Encrypting file"
   
            except KeyboardInterrupt:      
                print("Bye :)")

  
    elif resp == '7': 
        print "[!]WARNING[!]\nYou are about to delete a Key that cannot be retrieved(cntrl+z to kill program)"
        key_to_delete = raw_input("\n\nWhich Key would you like to delete?:")
        key_delete_cmd = 'gpg --delete-keys %s' %(key_to_delete)
        os.system(key_delete_cmd)
        is_valid = "echo $?"
        check = os.system(is_valid)
        if check == 0:
            print '[+]Key:'+key_to_delete+' has been successfully deleted![+]'
            sys.exit(0)
        else:
            print "[-]Error Code: %s[-]" %(check)
            sys.exit(1)

#Nano/Pico integration
    elif resp == '8':
        file_create = raw_input("File to create(gpg or txt?):") 
        if file_create == 'txt':
            file_txt = raw_input("Name of txt file(No extensions please ie myfile):")              
            txt_cmd = 'nano '+file_txt+'.txt'
            os.system(txt_cmd)
            file_encrypt_txt = raw_input("Would you like to Encrypt the new file?(Y or N):")
            file_encrypt_txt = file_encrypt_txt.lower()
            if file_encrypt_txt == 'y': 
                key_choice = raw_input("Key to use?:")                    
                nano_encrypt_cmd = 'gpg --recipient %s --armor --encrypt %s.txt' %(key_choice,file_txt)
                try:
                    os.system(nano_encrypt_cmd)
                    is_valid = "echo $?"
                    check = os.system(is_valid)
                    if check == 0:
                        print '[!]File Created and Encrypted! You can find it under the name: [+]%s.txt.asc[+]' % (file_txt)      
                        sys.exit(0)
                    else:
                        print "[-]Error Code: %s[-]" %(check)
                        sys.exit(1)
                except IndexError as e:
                    print "Error Encrypting file"

                except KeyboardInterrupt:      
                    print("Bye :)")
  
            
            else: 
                print "[+]File Created[+]"
                sys.exit(0)

        if file_create == 'gpg':
            file_gpg = raw_input("Name of gpg file(No extensions please!) ie;myfile:")
            nano_gpg_cmd = 'nano '+file_gpg+'.gpg'
            try:
                os.system(nano_gpg_cmd)
                file_decrypt_gpg = raw_input("Would you like to Decrypt the new file?(Y or N):")
                file_decrypt_gpg = file_decrypt_gpg.lower()
                if file_decrypt_gpg == 'y': 
                    nano_outfile = raw_input("Outfile for Decrypted the message(No extensions!) ie:myfile:")                  
                    nano_decrypt_cmd = 'gpg --output %s --decrypt %s.gpg' % (nano_outfile,file_gpg)              
                os.system(nano_decrypt_cmd)
                is_valid = "echo $?"
                check = os.system(is_valid)
                if check == 0:
                    print "[+]File Decrypted![+]\n\n You can find it in the current directory under: %s" % (nano_outfile) 
                    sys.exit(0)
                else:
                    print "[-]Error Code: %s[-]" %(check)
                    sys.exit(1)

            except IndexError as e:
                print "Error Encrypting file"

            except KeyboardInterrupt:      
                print("Bye :)")

        else: 
            print "[+]File Created![+]"
            sys.exit(0)
#Back shit up 
    elif resp == "9": 
        my_choice = raw_input("Move Keys or Import keys?:(move or import?): ")
        if my_choice == "move":
            to_do = raw_input("Will you be moving public or private keys(pub or priv?): ")
            if to_do == "pub":
                key_name = raw_input("Backup key name(ie: jim.public.key): ")
                key_code = raw_input("Key code: ")
                key_cmd = "gpg -ao %s --export %s" %(key_name, key_code)
                try:
                    os.system(key_cmd)
                    is_valid = "echo $?"
                    check = os.system(is_valid)
                    if check == 0:
                        print "[+]Backup key: %s created![+]" %(key_name)
                        sys.exit(0)
                    else:
                        print "[-]Error Code: %s[-]" %(check)
                        sys.exit(1)

                except IndexError as e:
                    print "Error codes: %s" %(e)
 
                except KeyboardError:
                    print "Bye"

            elif to_do == "priv":
                priv_key_name = raw_input("Private key name?: ")
                priv_key_code = raw_input("Private key code: ")
                priv_key_cmd = "gpg -ao %s --export-secret-keys %s" %(priv_key_name,priv_key_code)
                try:
                    os.system(priv_key_cmd)
                    is_valid = "echo $?"
                    os.system(is_valid)
                    if check == 0:
                        print "[+]Backed up secret key: %s has been created![+]" %(priv_key_name)
                        sys.exit(0)
                    else:
                        print "[-]Error Code: %s[-]" %(check)
                        sys.exit(1)

                except IndexError as e:
                    print "Error Exporting file"

                except KeyboardInterrupt:      
                    print("Bye :)")


        elif my_choice == "import":
            pub_priv = raw_input("Import a private or Public key?(pub or priv?): ")
            if pub_priv == "priv":
                priv_key_file = raw_input("Name of secret key to import?: ")
                priv_cmd = "gpg --allow-secret-key-import --import %s" %(priv_key_file)
                try:
                    os.system(priv_cmd)
                    is_valid = "echo $?"
                    os.system(is_valid)
                    if check == 0:
                        print "[+]Secret Key has been imported, however you may(or may not) need to redistribute the pub key if there are uid changes.[+]"
                        sys.exit(0)
                    else:
                        print "[-]Error Code: %s[-]" %(check)
                        sys.exit(1)

                except IndexError as e:
                    print "Error Encrypting file"

                except KeyboardInterrupt:      
                    print("Bye :)")

            elif pub_priv == "pub":
                pub_key_file = raw_input("Name of public key file?(wildcards like * accepted\n for mass import): ")
                pub_cmd = "gpg --import %s" %(pub_key_file)
                try:
                    os.system(pub_cmd)
                    is_valid = "echo $?"
                    os.system(is_valid)
                    if check == 0:
                        print "[+]Public key(s) successfully imported![+]"
                        sys.exit(0)
                    else:
                        print "[-]Error Code: %s[-]" %(check)
                        sys.exit(1)

                except IndexError as e:
                    print "Error Encrypting file"

                except KeyboardInterrupt:      
                    print("Bye :)")

    elif resp == "10": sys.exit(0)  


    else: 
        main()

if __name__ == '__main__':
    sys.exit(main())