-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaser_cipher.py
More file actions
45 lines (30 loc) · 976 Bytes
/
caser_cipher.py
File metadata and controls
45 lines (30 loc) · 976 Bytes
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
33
34
35
36
37
38
39
40
41
42
43
44
45
#from bram credits to him
#uncomment some lines for it to work!!
LAST_CHAR_CODE=ord("Z")
FIRST_CHAR_CODE=ord("A")
CHAR_RANGE=LAST_CHAR_CODE-FIRST_CHAR_CODE+1
# import sys
def caeser_text(message,shift):
#result
result=""
#looping
for char in message.upper():
#ascii code
if char.isalpha():
char_code=ord(char)
new_char_code=char_code+shift
if new_char_code>LAST_CHAR_CODE:
new_char_code-=CHAR_RANGE
if new_char_code<FIRST_CHAR_CODE:
new_char_code+=CHAR_RANGE
new_char=chr(new_char_code)
result+=new_char
else:
result+=char
return(result)
#user input
# user_message=input("Message to Encrpyt: ")
# user_shift_key=int(input("Shift Key(integer): "))
# caeser_text(user_message,user_shift_key)
# caeser_text()
# sys.modules[__'ceaser_text'__]=caeser_text