def matchWithMethod(method, text, pattern): if (method == 'bm'): return (BM.bmAlgorithm(text, pattern)) elif (method == 'kmp'): return (KMP.kmpAlgorithm(text, pattern)) else: return (regexp.regex(text, pattern))
def encrypt_ui(shift, change): print("What is the message that you want to encode?") message = input() buffer = "" for i in message: if regEx.regex("!@#$%^&*()<>,.?/';:\"\| []\{\}`~1234567890+-_=", i) == True: shift += change if shift > 25: shift -= 26 buffer += en.char_encode(i, shift) print(buffer)
def decrypt_ui(shift, change): print("What is the message thet you want to decrypt") message = input() buffer = "" for i in message: if regEx.regex("!@#$%^&*()<>,.?/';:\"\| []\{\}`~1234567890+-_=", i) == True: shift += change if shift > 25: shift -= 26 buffer += dec.decryption(shift, i) print(buffer)
def decryption(shift, letter_char): char_ref = [ "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" ] upper = False if regEX.regex("!@#$%^&*()<>,.?/';:\"\| []\{\}`~1234567890+-_=", letter_char) == True: if letter_char.isupper() == True: upper = True shift_num = char_ref.index(letter_char.lower()) - shift if shift_num < 0: shift_num += 26 if upper == True: return char_ref[shift_num].upper() else: return char_ref[shift_num] else: return letter_char
def char_encode(char, shift): char_ref = [ "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" ] upper = False # Check to eliminate all non alphabetic charicters and pass them imdediatly back if regEx.regex("!@#$%^&*()<>,.?/';:\"\| []\{\}`~1234567890+-_=", char) == True: # Check if it is upper case if char.isupper() == True: upper = True # Get the location of the letter in the array letter_shifted_num = char_ref.index(char.lower()) + shift if letter_shifted_num > 25: letter_shifted_num = letter_shifted_num - 26 con_char = char_ref[letter_shifted_num] # Pass back if the item is upper case or not if upper == True: return con_char.upper() else: return con_char else: return char