Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Transposition Cipher Issues
#1
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 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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Cesar Cipher ForsakenDusk 5 479 Apr-07-2024, 04:30 PM
Last Post: Pedroski55
Question Rsa Cipher Paragoon2 3 650 Nov-27-2023, 12:30 PM
Last Post: snippsat
  RSA Cipher with blocks Paragoon2 0 494 Nov-26-2023, 04:35 PM
Last Post: Paragoon2
  Caesar Cipher Help pbrowne 2 2,187 Jun-30-2021, 02:36 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020