diff options
author | Sudipto Mallick <> | 2024-01-02 03:38:10 +0000 |
---|---|---|
committer | Sudipto Mallick <> | 2024-01-02 03:38:10 +0000 |
commit | 7451edff7692e86c5238ff7bc6659825e242a84e (patch) | |
tree | 830fe25caf403869fe77df83bc44822ea6f5f11d /python/code/3/6.py | |
parent | a70e0a59817ce06a3dd23b3750ae16ee6660deaf (diff) | |
download | zadania-7451edff7692e86c5238ff7bc6659825e242a84e.tar.gz |
Quick backup, need to be rewritten
Diffstat (limited to 'python/code/3/6.py')
-rw-r--r-- | python/code/3/6.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/python/code/3/6.py b/python/code/3/6.py new file mode 100644 index 0000000..f9b4b99 --- /dev/null +++ b/python/code/3/6.py @@ -0,0 +1,27 @@ +import sys +message = input('Enter message: ') +key = None +try: + key = int(input('Enter key (1-25, -1 - -25): ')) +except ValueError: + print('Invalid key, must be an integer') + sys.exit(1) + +if key < 0: key += 26 +if not (1 <= key <= 25): + print('Invalid key, must be an integer with absolute value between 1 and 25, inclusive') + sys.exit(2) + +marr = bytearray(message, 'ascii') +for i in range(len(marr)): + c = marr[i] + if 64 < c < 64 + 27: + c = ((c - 65) + key) % 26 + 65 + elif 96 < c < 96 + 27: + c = ((c - 97) + key) % 26 + 97 + marr[i] = c + +print('Ceesar cipher with k =', key, 'applied to the given message:') +print(str(marr, encoding='ascii')) + + |