-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshift.py
More file actions
21 lines (20 loc) · 694 Bytes
/
shift.py
File metadata and controls
21 lines (20 loc) · 694 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
aplhabets=["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
#Shifting Function
def ceaser_shift(sti,shift,cond="encode"):
st=[]
for j in sti:
st.append(j.lower())
st="".join(st)
if(cond=="decode"):
shift=(-shift)
newwrd=[]
for i in st:
if(i==" "):
newwrd.append(i)
else:
if(aplhabets.index(i)+shift>len(aplhabets)):
ind=aplhabets.index(i)+shift-len(aplhabets)
else:
ind=aplhabets.index(i)+shift
newwrd.append(aplhabets[ind])
return("".join(newwrd))