-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaesar.py
More file actions
32 lines (25 loc) · 1.02 KB
/
caesar.py
File metadata and controls
32 lines (25 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python3
from argparse import ArgumentParser
def caeser_cipher(ciphertext: str, shift: int = 13):
"""Shifts the ciphertext by shift amount"""
print(f'[=] Text shifted by {shift}:')
for letter in ciphertext:
BASE = 0 # Starting character for
if letter.isupper():
BASE = ord('A') # ascii value of a
elif letter.islower():
BASE = ord('a') # ascii value of A
print( chr( (ord(letter) + shift - BASE) % 26 + BASE ), end='' ) #chr((ord(val[i])-rot - 65) % 26 + 65)
print()
if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument('ciphertext', type=str)
parser.add_argument('--shift', '-s', type=int, default=13)
args = parser.parse_args()
#TODO add range of shift for bruteforcing
if '..' in args.shift:
s, f = args.shift.split('..')
for i in range(s, f+1):
caeser_cipher(args.ciphertext, i)
else:
caeser_cipher(args.ciphertext, args.shift)