File tree 1 file changed +6
-3
lines changed
1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change 7
7
https://www.dcode.fr/gronsfeld-cipher
8
8
"""
9
9
10
+
10
11
def gronsfeld (text : str , key : str ) -> str :
11
12
"""
12
13
Encrypt plaintext with the Gronsfeld cipher
@@ -16,22 +17,24 @@ def gronsfeld(text: str, key: str) -> str:
16
17
>>> gronsfeld('', '123')
17
18
''
18
19
"""
19
- alphabets = ' ABCDEFGHIJKLMNOPQRSTUVWXYZ'
20
+ alphabets = " ABCDEFGHIJKLMNOPQRSTUVWXYZ"
20
21
keys = [int (i ) for i in key ]
21
22
encrypted_text = ""
22
23
upper_case_text = text .upper ()
23
24
24
25
for i , char in enumerate (upper_case_text ):
25
26
if char in alphabets :
26
- new_position = (alphabets .index (char ) +
27
- keys [i % len (keys )]) % len (alphabets )
27
+ new_position = (alphabets .index (char ) + keys [i % len (keys )]) % len (
28
+ alphabets
29
+ )
28
30
shifted_letter = alphabets [new_position ]
29
31
encrypted_text += shifted_letter
30
32
else :
31
33
encrypted_text += char
32
34
33
35
return encrypted_text
34
36
37
+
35
38
if __name__ == "__main__" :
36
39
import doctest
37
40
You can’t perform that action at this time.
0 commit comments