Skip to content

Commit 5a94998

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent c898f60 commit 5a94998

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

ciphers/gronsfeld_cipher.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
https://www.dcode.fr/gronsfeld-cipher
88
"""
99

10+
1011
def gronsfeld(text: str, key: str) -> str:
1112
"""
1213
Encrypt plaintext with the Gronsfeld cipher
@@ -16,22 +17,24 @@ def gronsfeld(text: str, key: str) -> str:
1617
>>> gronsfeld('', '123')
1718
''
1819
"""
19-
alphabets = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
20+
alphabets = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
2021
keys = [int(i) for i in key]
2122
encrypted_text = ""
2223
upper_case_text = text.upper()
2324

2425
for i, char in enumerate(upper_case_text):
2526
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+
)
2830
shifted_letter = alphabets[new_position]
2931
encrypted_text += shifted_letter
3032
else:
3133
encrypted_text += char
3234

3335
return encrypted_text
3436

37+
3538
if __name__ == "__main__":
3639
import doctest
3740

0 commit comments

Comments
 (0)