This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
kse-02/instrumented/caesar_cipher.py

23 lines
615 B
Python
Raw Normal View History

2023-11-13 15:33:20 +00:00
def encrypt_instrumented(strng: str, key: int) -> str:
2023-11-13 15:33:20 +00:00
assert (0 < key <= 94)
encrypted = ''
for x in strng:
indx = ((ord(x) + key) % 256)
if evaluate_condition(1, 'Gt', indx, 126):
indx = (indx - 95)
encrypted = (encrypted + chr(indx))
return encrypted
def decrypt_instrumented(strng: str, key: int) -> str:
2023-11-13 15:33:20 +00:00
assert (0 < key <= 94)
decrypted = ''
for x in strng:
indx = ((ord(x) - key) % 256)
if evaluate_condition(2, 'Lt', indx, 32):
indx = (indx + 95)
decrypted = (decrypted + chr(indx))
return decrypted