Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cs50
- import sys
- if len(sys.argv) == 1 or len(sys.argv) > 2:
- print("Usage: python caesar.py <key>")
- exit(1)
- print("plaintext: ", end="")
- plaintext = cs50.get_string()
- key = int(sys.argv[1])
- size = len(plaintext)
- ciphertext = []
- if key >= pow(2, 31) - 26 or key <= 0:
- print("The value for the key is invalid!")
- else:
- if key > 26:
- key %= 26
- for i in range(size):
- if plaintext[i].isalpha():
- c = (ord(plaintext[i]) + key)
- if plaintext[i].upper() > 'Z':
- c -= 26
- ciphertext.append(chr(c))
- print("ciphertext: ", end="")
- print("".join(ciphertext))
- exit(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement