Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #---------------------------------
- # Q3: Xshift #
- #---------------------------------
- #-----------------------------------------
- # Parametes: plaintext (str)
- # key: (shiftString,shifts)
- # Return: ciphertext (str)
- # Description: Encryption using Xshift Cipher
- #-----------------------------------------
- def e_xshift(plaintext, key):
- # your code here
- modified_key = utilities.shift_string(key[0],int(key[1]),'l')
- ciphertext = ''
- for char in plaintext:
- if char in modified_key:
- index_key = key[0].index(char)
- ciphertext += modified_key[index_key]
- else:
- ciphertext+=char
- return ciphertext
- #-----------------------------------------
- # Parametes: ciphertext (str)
- # key: (shiftString,shifts)
- # Return: plaintext (str)
- # Description: Decryption using Xshift Cipher
- #-----------------------------------------
- def d_xshift(ciphertext, key):
- # your code here
- modified_key = utilities.shift_string(key[0],int(key[1]),'l')
- plaintext = ''
- for char in ciphertext:
- if char in modified_key:
- index_modifed_key = modified_key.index(char)
- plaintext += key[0][index_modifed_key]
- else:
- plaintext+=char
- return plaintext
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement