HridayAg0102/Encryption-Decryption-webapp
0
1import gradio as gr2 3 4description = """<center><img src='https://res.cloudinary.com/wonder4kids/image/upload/v1656014135/icon_ljflgz.png' height=200px width = 200px >5 <center><h2 align = 'center'>6 This Application is developed by <a href="https://github.com/HridayAg0102"> HRIDAY AGRAWAL </a>7 </h2>"""8 9def encrypt(data, key):10 shift = sum([ord(key[i])*(i+1) for i in range(len(key))]) % 2611 encrypted_result = ""12 for i in range(len(data)):13 encrypted_result += chr(ord(data[i]) - shift)14 15 return encrypted_result16 17def decrypt(encrypted_data, key):18 shift = sum([ord(key[i])*(i+1) for i in range(len(key))]) % 2619 decrypted_result = ''20 for i in range(len(encrypted_data)):21 decrypted_result += chr(ord(encrypted_data[i]) + shift)22 return decrypted_result23 24 25demo1 = gr.Interface(fn = encrypt, inputs = ['text', 'text'], outputs=gr.Textbox(label="Encrypted Text", lines=4),26 title = 'Encrypt Data',27 description = description)28demo2 = gr.Interface(fn = decrypt, inputs = ['text', 'text'], outputs=gr.Textbox(label="Decrypted Text", lines=4),29 title = 'Decrypt Data',30 description = description)31 32print('This is a simple Cryptographic Web Application for me to learn how to create webapps in python :)')33 34final_interface = gr.TabbedInterface([demo1, demo2], tab_names=['Encrypt data', 'Decrypt data']).launch(35 favicon_path = './icon.png', share = True)36 