Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.35 KB | None | 0 0
  1. #---------------------------------
  2. #           Q3: Xshift           #
  3. #---------------------------------
  4.  
  5. #-----------------------------------------
  6. # Parametes:    plaintext (str)
  7. #               key: (shiftString,shifts)
  8. # Return:       ciphertext (str)
  9. # Description:  Encryption using Xshift Cipher
  10. #-----------------------------------------
  11. def e_xshift(plaintext, key):
  12.     # your code here
  13.  
  14.     modified_key = utilities.shift_string(key[0],int(key[1]),'l')
  15.     ciphertext = ''
  16.  
  17.     for char in plaintext:
  18.         if char in modified_key:
  19.             index_key = key[0].index(char)
  20.             ciphertext += modified_key[index_key]
  21.  
  22.         else:
  23.             ciphertext+=char
  24.            
  25.     return ciphertext
  26.  
  27. #-----------------------------------------
  28. # Parametes:    ciphertext (str)
  29. #               key: (shiftString,shifts)
  30. # Return:       plaintext (str)
  31. # Description:  Decryption using Xshift Cipher
  32. #-----------------------------------------
  33. def d_xshift(ciphertext, key):
  34.     # your code here
  35.  
  36.     modified_key = utilities.shift_string(key[0],int(key[1]),'l')
  37.     plaintext = ''
  38.  
  39.     for char in ciphertext:
  40.         if char in modified_key:
  41.             index_modifed_key = modified_key.index(char)
  42.             plaintext += key[0][index_modifed_key]
  43.  
  44.         else:
  45.             plaintext+=char
  46.    
  47.     return plaintext
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement