Michael-UT / SoftwareLab-FinalProject

0 stars 2 forks source link

Today- apply encryption methodology to data #18

Open Michael-UT opened 1 year ago

ashwin-ram03 commented 1 year ago

def encrypt(inputText, N, D):

we need a reverse function

rev_string = reverse(inputText)
if(D==1):
    answer = shift_right(N, rev_string)
    return answer
elif(D==-1):
    answer = shift_left(N, rev_string)
    return answer
else:
    return "-1"

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