mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-01-30 14:13:44 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
da34c05919
commit
c42da95d86
|
@ -8,14 +8,14 @@ def encrypt(text, key):
|
||||||
key_index = 0
|
key_index = 0
|
||||||
|
|
||||||
for char in text:
|
for char in text:
|
||||||
if char.isalpha():
|
if char.isalpha():
|
||||||
shift = ord(key[key_index]) - ord('A')
|
shift = ord(key[key_index]) - ord('A')
|
||||||
if char.isupper():
|
if char.isupper():
|
||||||
new_char = chr((ord(char) - ord('A') + shift) % 26 + ord('A'))
|
new_char = chr((ord(char) - ord('A') + shift) % 26 + ord('A'))
|
||||||
else:
|
else:
|
||||||
new_char = chr((ord(char) - ord('a') + shift) % 26 + ord('a'))
|
new_char = chr((ord(char) - ord('a') + shift) % 26 + ord('a'))
|
||||||
encrypted_text.append(new_char)
|
encrypted_text.append(new_char)
|
||||||
key_index = (key_index + 1) % key_length
|
key_index = (key_index + 1) % key_length
|
||||||
else:
|
else:
|
||||||
encrypted_text.append(char)
|
encrypted_text.append(char)
|
||||||
|
|
||||||
|
@ -31,14 +31,14 @@ def decrypt(text, key):
|
||||||
key_index = 0
|
key_index = 0
|
||||||
|
|
||||||
for char in text:
|
for char in text:
|
||||||
if char.isalpha():
|
if char.isalpha():
|
||||||
shift = ord(key[key_index]) - ord('A')
|
shift = ord(key[key_index]) - ord('A')
|
||||||
if char.isupper():
|
if char.isupper():
|
||||||
new_char = chr((ord(char) - ord('A') - shift) % 26 + ord('A'))
|
new_char = chr((ord(char) - ord('A') - shift) % 26 + ord('A'))
|
||||||
else:
|
else:
|
||||||
new_char = chr((ord(char) - ord('a') - shift) % 26 + ord('a'))
|
new_char = chr((ord(char) - ord('a') - shift) % 26 + ord('a'))
|
||||||
decrypted_text.append(new_char)
|
decrypted_text.append(new_char)
|
||||||
key_index = (key_index + 1) % key_length
|
key_index = (key_index + 1) % key_length
|
||||||
else:
|
else:
|
||||||
decrypted_text.append(char)
|
decrypted_text.append(char)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user