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 1,972 Apr-07-2024, 04:30 PM
Last Post: Pedroski55
Question Rsa Cipher Paragoon2 3 1,427 Nov-27-2023, 12:30 PM
Last Post: snippsat
  RSA Cipher with blocks Paragoon2 0 1,097 Nov-26-2023, 04:35 PM
Last Post: Paragoon2
  Caesar Cipher Help pbrowne 2 3,024 Jun-30-2021, 02:36 PM
Last Post: deanhystad
  Coding caesar's cipher drewbty 3 3,965 May-16-2020, 10:05 AM
Last Post: DPaul
  cipher decryption tool nightfox82 0 1,817 Mar-25-2020, 06:36 AM
Last Post: nightfox82
  Problem with caesar cipher lucaron 2 3,659 Feb-05-2018, 05:17 PM
Last Post: lucaron
  Decrypt Caesar Cipher WantToImprove 22 22,371 Jan-30-2018, 08:43 AM
Last Post: WantToImprove
  Simple Caesar Cipher Help as1221 6 6,631 Jun-15-2017, 10:22 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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