Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -409,12 +409,13 @@ def decrypt_blowfish(data, key):
|
|
| 409 |
pt = unpad(cipher.decrypt(ct), Blowfish.block_size)
|
| 410 |
return pt.decode('utf-8')
|
| 411 |
|
| 412 |
-
def encrypt_hill(
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
|
|
|
| 418 |
|
| 419 |
def decrypt_hill(data, key_matrix):
|
| 420 |
encrypted_vector = np.array([ord(char) - 65 for char in data])
|
|
@@ -424,10 +425,15 @@ def decrypt_hill(data, key_matrix):
|
|
| 424 |
decrypted_text = ''.join(chr(int(round(num)) + 65) for num in decrypted_vector.flatten())
|
| 425 |
return decrypted_text
|
| 426 |
|
| 427 |
-
def encrypt_vigenere(
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 431 |
|
| 432 |
def decrypt_vigenere(data, key):
|
| 433 |
key = (key * (len(data) // len(key)) + key[:len(data) % len(key)]).upper()
|
|
|
|
| 409 |
pt = unpad(cipher.decrypt(ct), Blowfish.block_size)
|
| 410 |
return pt.decode('utf-8')
|
| 411 |
|
| 412 |
+
def encrypt_hill(plaintext, key_matrix):
|
| 413 |
+
plaintext_vector = [ord(char) - ord('A') for char in plaintext]
|
| 414 |
+
key_matrix = Matrix(key_matrix)
|
| 415 |
+
plaintext_matrix = Matrix(plaintext_vector)
|
| 416 |
+
ciphertext_matrix = key_matrix * plaintext_matrix % 26
|
| 417 |
+
ciphertext = ''.join(chr(int(num) + ord('A')) for num in ciphertext_matrix)
|
| 418 |
+
return ciphertext
|
| 419 |
|
| 420 |
def decrypt_hill(data, key_matrix):
|
| 421 |
encrypted_vector = np.array([ord(char) - 65 for char in data])
|
|
|
|
| 425 |
decrypted_text = ''.join(chr(int(round(num)) + 65) for num in decrypted_vector.flatten())
|
| 426 |
return decrypted_text
|
| 427 |
|
| 428 |
+
def encrypt_vigenere(plaintext, key):
|
| 429 |
+
key_length = len(key)
|
| 430 |
+
key_as_int = [ord(i) for i in key]
|
| 431 |
+
plaintext_int = [ord(i) for i in plaintext]
|
| 432 |
+
ciphertext = ''
|
| 433 |
+
for i in range(len(plaintext_int)):
|
| 434 |
+
value = (plaintext_int[i] + key_as_int[i % key_length]) % 26
|
| 435 |
+
ciphertext += chr(value + 65)
|
| 436 |
+
return ciphertext
|
| 437 |
|
| 438 |
def decrypt_vigenere(data, key):
|
| 439 |
key = (key * (len(data) // len(key)) + key[:len(data) % len(key)]).upper()
|