Apr-08-2022, 07:44 PM
I am recently new to python and I have been given the task to create a function that uses transposition cipher to encrypt and decrypt a user-input message with a user-input key. However I am stuck on what to do next. I have to use my
I just need help on the encryption process.
swap()
function inside the transposition cipher and I can only call len(), ord(), and range(). I would really appreciate if someone could show me how to this so that I could do the decryption part myself.def swap(x, i, j): i, j = sorted((i, j)) if i and j in range(len(x)): return x[:i] + x[j] + x[i+1:j] + x[i] + x[j+1:] else: return None plaintext ='' keyword = '' def swap_encrypt(plaintext, keyword): alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' translated_message = "" keyword_index = 0 keyword_index = keyword_index % len(keyword) i = swap(keyword_index) for character in plaintext: if character in alphabet:If the message is ‘SLOTH POWER’, and the keyword is ‘TOP’, then the output should be something like: ‘RLOTPOHWES’
I just need help on the encryption process.