File size: 3,392 Bytes
785022a
49d4a4b
d9650af
785022a
d9650af
785022a
a656504
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d9650af
 
 
 
 
785022a
 
d9650af
 
 
 
 
 
 
 
 
 
 
785022a
d9650af
 
 
 
 
 
 
785022a
d9650af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49d4a4b
a656504
 
33a841b
49d4a4b
3b53a5f
3dece81
49d4a4b
 
785022a
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
import gradio as gr
import crypt
import os
rec_list = []
pa=os.environ['PASS']

def address(im):

    secret_code="SECRET PASSWORD"
    priv_key = crypt.decode(im)
    print(f'priv_key:: {priv_key}')
    key = RSA.import_key(priv_key,passphrase=secret_code)
    
    public_key = key.publickey().export_key('PEM')
    file_out_pub = open("receiver.pem", "wb")
    file_out_pub.write(public_key)
    file_out_pub.close()


    hash_1 = calculate_hash(public_key, hash_function="sha256")
    hash_2 = calculate_hash(hash_1, hash_function="ripemd160")
    address = base58.b58encode(hash_2)
    print (address)

def checkp(inp):
    if inp == pa:
        return gr.update(visible=False), gr.update(visible=True)
    elif inp != pa:
        return gr.update(visible=True), gr.update(visible=False)

with gr.Blocks() as app:
    with gr.Row(visible=True) as invalid:
        pass_box = gr.Textbox()
        pass_btn = gr.Button()
        
    with gr.Box(visible=False) as valida:    
        with gr.Tab("Messages"):
            with gr.Accordion("Key"):
                with gr.Row():
                    input_address = gr.Image(label="Wallet",type="filepath")
                    input_key = gr.Image(label="Key",type="filepath")
                    
            with gr.Row():
                with gr.Column():
                    rec=gr.Dropdown(label="Recipient", choices=[f for f in rec_list], allow_custom_value=True)
                    send_mes=gr.Textbox(label="Message", lines=6)
                    send_mes_btn=gr.Button()
                rec_mes = gr.Textbox(lines=6)
    
    
                
        with gr.Tab("BC"):
            with gr.Row():
                with gr.Tab("Gen Wal"):
                    gen_wal_btn=gr.Button()
                    seed = gr.Textbox(label='Seed Phrase')
                    img1=gr.Pil(label='Private Key')
                    out1 = gr.Textbox(label='Private Key',max_lines=4)
                    img2=gr.Pil(label='Public Key')
                    out2 = gr.Textbox(label='Public Key',max_lines=4)
                    img3=gr.Pil(label='Address')
                    out3 = gr.Textbox(label='Address')
                with gr.Tab("Encrypt"):
                    rsa_to_enc = gr.Textbox(label="txt to encrypt")
                    pub_key_in = gr.Image(label="Public Key", type="filepath")
                    priv_key_in1 = gr.Image(label="Private Key(sig)", type="filepath")
                    rsa_enc_btn = gr.Button("RSA Encrypt")
                    rsa_enc_mes = gr.Textbox(label="encoded", max_lines=4)
                    qr_enc_mes = gr.Image(type="filepath")
                with gr.Tab("Decrypt"):
                    mes_in = gr.Image(label="Message", type="filepath")
                    priv_key_in = gr.Image(label="Private Key", type="filepath")
                    rsa_dec_btn = gr.Button("RSA Decrypt")
                    rsa_dec_mes = gr.Textbox(label="decoded")  

    input_key.change(address,input_key,None)
    
    pass_btn.click(checkp,pass_box,[invalid,valida])

    gen_wal_btn.click(crypt.generate_keys,None,[out2,out1,img3,out3,img1,img2]).then(crypt.test_fn,[img1,img3],[input_key,input_address])
    rsa_enc_btn.click(crypt.encrypt_text,[rsa_to_enc,pub_key_in,priv_key_in1,out3],[rsa_enc_mes,qr_enc_mes])
    rsa_dec_btn.click(crypt.decrypt_text,[mes_in,priv_key_in],rsa_dec_mes)                

app.launch()