File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,11 @@ def encrypt(original_message, key):
17
17
encrypted_message = ''
18
18
19
19
if type (key ) == str :
20
- key = ALPHABET .index (key ) + 1
20
+ try :
21
+ key = ALPHABET .index (key ) + 1
22
+
23
+ except ValueError :
24
+ raise ValueError ()
21
25
22
26
# Encrypts the original message then stores in the return variable
23
27
for letter in remove_accents (original_message .lower ()):
@@ -46,7 +50,11 @@ def decrypt(encrypted_message, key):
46
50
translated = ''
47
51
48
52
if type (key ) == str :
49
- key = ALPHABET .index (key ) + 1
53
+ try :
54
+ key = ALPHABET .index (key ) + 1
55
+
56
+ except ValueError :
57
+ raise ValueError ()
50
58
51
59
for letter in remove_accents (encrypted_message .lower ()):
52
60
if letter in ALPHABET :
Original file line number Diff line number Diff line change @@ -33,6 +33,8 @@ def encrypt(file, key):
33
33
34
34
except FileNotFoundError :
35
35
print (f'The file { file } does not exists' )
36
+ except ValueError :
37
+ print ('The selected key does not exists in the alphabet' )
36
38
37
39
38
40
@@ -41,14 +43,16 @@ def decrypt(file, key):
41
43
file_content = get_file_content (file )
42
44
43
45
if file_content :
44
- new_file = store_file_content (caesar_cipher .decrypt (file_content , key ), 'decriptado .txt' )
46
+ new_file = store_file_content (caesar_cipher .decrypt (file_content , key ), 'decripted .txt' )
45
47
print (f'Content stored on { new_file } ' )
46
48
47
49
else :
48
50
print (f'The file { file } is empty' )
49
51
50
52
except FileNotFoundError :
51
53
print (f'The file { file } does not exists' )
54
+ except ValueError :
55
+ print ('The selected key does not exists in the alphabet' )
52
56
53
57
54
58
if __name__ == "__main__" :
You can’t perform that action at this time.
0 commit comments