Update app.py
Browse files
app.py
CHANGED
|
@@ -52,7 +52,7 @@ def unpad_data(data):
|
|
| 52 |
return unpadded_data
|
| 53 |
|
| 54 |
def main():
|
| 55 |
-
def
|
| 56 |
if len(key) > 32:
|
| 57 |
return 'Key is too long. Maximum key length is 32 characters.'
|
| 58 |
key = key.encode('utf-8')
|
|
@@ -65,33 +65,21 @@ def main():
|
|
| 65 |
iv = bytes(iv)
|
| 66 |
|
| 67 |
AesCbc = CBCEncryption(key, iv)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
return '
|
| 74 |
-
key = key.encode('utf-8')
|
| 75 |
-
key = key.ljust(32, b'\x35')
|
| 76 |
-
|
| 77 |
-
iv = key[:16]
|
| 78 |
-
iv = bytearray(iv)
|
| 79 |
-
for i in range(16):
|
| 80 |
-
iv[i] = iv[i] ^ 0x35
|
| 81 |
-
iv = bytes(iv)
|
| 82 |
-
|
| 83 |
-
AesCbc = CBCEncryption(key, iv)
|
| 84 |
-
output_path = DecryptImage(AesCbc, image, key)
|
| 85 |
return output_path
|
| 86 |
|
| 87 |
# Define the Gradio interface
|
| 88 |
iface = gr.Interface(
|
| 89 |
-
|
| 90 |
-
["image", "text"], # Input types
|
| 91 |
-
|
| 92 |
-
["Encrypt", "Decrypt"], # Button labels
|
| 93 |
title="AES CBC Encryption/Decryption",
|
| 94 |
-
description="Upload an image
|
| 95 |
)
|
| 96 |
|
| 97 |
iface.launch()
|
|
|
|
| 52 |
return unpadded_data
|
| 53 |
|
| 54 |
def main():
|
| 55 |
+
def action(image, key, action_type):
|
| 56 |
if len(key) > 32:
|
| 57 |
return 'Key is too long. Maximum key length is 32 characters.'
|
| 58 |
key = key.encode('utf-8')
|
|
|
|
| 65 |
iv = bytes(iv)
|
| 66 |
|
| 67 |
AesCbc = CBCEncryption(key, iv)
|
| 68 |
+
if action_type == 'Encrypt':
|
| 69 |
+
output_path = EncryptImage(AesCbc, image, key)
|
| 70 |
+
elif action_type == 'Decrypt':
|
| 71 |
+
output_path = DecryptImage(AesCbc, image, key)
|
| 72 |
+
else:
|
| 73 |
+
return 'Invalid action type. Choose either Encrypt or Decrypt.'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
return output_path
|
| 75 |
|
| 76 |
# Define the Gradio interface
|
| 77 |
iface = gr.Interface(
|
| 78 |
+
action, # Single function to wrap
|
| 79 |
+
["image", "text", "text"], # Input types: image, key, action_type
|
| 80 |
+
"image", # Output type
|
|
|
|
| 81 |
title="AES CBC Encryption/Decryption",
|
| 82 |
+
description="Upload an image, a key, and choose Encrypt or Decrypt to process the image."
|
| 83 |
)
|
| 84 |
|
| 85 |
iface.launch()
|