write a program that contains two functions i.e., encrypt_string() and decrypt_string()a.encrypt_string(s): Thisfunction uses the following dictionary:encrypt={'a':'1','b':'@','c':'*','d':')','e':'$','f':'#'}This function should accept a string as its parameter and return anencrypted string. To encrypt a string, use the dictionary given above. Read each character of the string(match it with the keyin the dictionary)and replace each character with the given encrypted value(valuein the dictionary)and return the encrypted string.b.decrypt_string(s)This function uses the following dictionary:decrypt={'1':'a','@':'b','*':'c',')':'d','$':'e','#':'f'}This function should accept an encrypted string as its parameter and return the decrypted/original string. To decrypt a string, use the dictionary given above. Read each character of the string(match it with the key in the dictionary) andreplace each character with the given decrypted value(value in the dictionary)and return the decrypted string.
def encrypt_string(word: str):
  res = ''
  for i in range(len(word)):
    if word[i] == 'a':
      res += '1'
    elif word[i] == 'b':
      res += '@'
    elif word[i] == 'c':
      res += '*'
    elif word[i] == 'd':
      res += ')'
    elif word[i] == 'e':
      res += '$'
    elif word[i] == 'f':
      res += '#'
    else:
      res += word[i]
  return res;
  Â
def decrypt_string(word: str):
  res = ''
  for i in range(len(word)):
    if word[i] == '1':
      res += 'a'
    elif word[i] == '@':
      res += 'b'
    elif word[i] == '*':
      res += 'c'
    elif word[i] == ')':
      res += 'd'
    elif word[i] == '$':
      res += 'e'
    elif word[i] == '#':
      res += 'f'
    else:
      res += word[i]
  return res;
  Â
if __name__ == '__main__':
  s = input('Enter some word:')
  print('---')
  s = encrypt_string(s)
  print(s)
  s = decrypt_string(s)
  print(s)
  print('---')
Comments
Leave a comment