def reverse(s):
array=[]
i=len(s)-1
reversed_string = ""
while(i>=0):
array.append(s[i])
i-=1
for letter in array:
reversed_string+=letter
return reversed_string
def shift_right(digits, string):
char_array = []
for letter in string:
char_array.append(letter)
i=0
while(i<len(char_array)):
element = char_array[i]
element = ord(element)
ele=(element+digits)
if(ele>126):
ele=ele%127
ele+=34
ele = chr(ele)
char_array[i]=ele
i+=1
shifted =""
for letter in char_array:
shifted+=letter
return shifted
def shift_left(digits, string):
char_array = []
for letter in string:
char_array.append(letter)
i=0
while(i<len(char_array)):
element = char_array[i]
element = ord(element)
ele=(element-digits)
if(ele<34):
ele+=93
ele = chr(ele)
char_array[i]=ele
i+=1
shifted =""
for letter in char_array:
shifted+=letter
return shifted
def encrypt(inputText, N, D):
we need a reverse function
def decrypt(inputText, N, D): new_D="" new_N="" shifted="" if(D==-1): new_D=1 elif(D==1): new_D=-1 if(new_D==1): shifted = shift_right(N, inputText) elif(new_D==-1): shifted = shift_left(N, inputText) reversed_str = reverse(shifted) return reversed_str
def reverse(s): array=[] i=len(s)-1 reversed_string = "" while(i>=0): array.append(s[i]) i-=1 for letter in array: reversed_string+=letter return reversed_string def shift_right(digits, string): char_array = [] for letter in string: char_array.append(letter) i=0 while(i<len(char_array)): element = char_array[i] element = ord(element) ele=(element+digits) if(ele>126): ele=ele%127 ele+=34 ele = chr(ele) char_array[i]=ele i+=1 shifted ="" for letter in char_array: shifted+=letter return shifted def shift_left(digits, string): char_array = [] for letter in string: char_array.append(letter) i=0 while(i<len(char_array)): element = char_array[i] element = ord(element) ele=(element-digits) if(ele<34): ele+=93 ele = chr(ele) char_array[i]=ele i+=1 shifted ="" for letter in char_array: shifted+=letter return shifted