#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0

    Help - 3 rail Decryption is beating me up, and stealing my lunch money


    Help - 3 rail Decryption is beating me up, and stealing my lunch money

    So, I'm encrypting by tossing letters onto 3 different rails, then
    smooshing them together
    like rail1 + rail2 + rail3 (forget the putting it backwards crap)

    ANYHOW, so, with the default string ("HELLO")
    I get

    rail1:HL
    rail2:EO
    rail3:L

    and rail1 + rail2 + rail3 = myEncryptedString = "HLEOL"

    -----------

    I'm totally lost - how do I

    1) Split up the myEncryptedString into the proper rails.

    2) Read 1 character from each rail, in sequence.

    Thoughts???
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0

    My encryption/decryption works for 4,5, and 6 letter strings


    My encryption/decryption works for 4,5, and 6 letter strings. Beyond that - it fails to work properly.

    Would anyone be kind enough to look, and tell me where I'm failing?

    Thank you!

    Code:
    #EXTRA CREDIT ATTEMPTED: menu and main function per directions + 10 pts.
    #SummersSProgram3
    #Author: Scott Summers scottsummers@gmail.com
    #Date: 10/26/2012
    
    '''
    displayMainMenu
        @input: user selected key press
        @output: returns keyInput
    '''
    def displayMainMenu(currentString):
        keyInput = '9'
        while keyInput !='5' and keyInput !='4' and keyInput !='3' and keyInput !='2' and keyInput !='1':
            print ("\nSecret Agent - Choose the necessary function to perform:\n\n"
                "The current string is: ",currentString,"\n\n"  # I WANT the current string to be visable in the menu
                "Select 0 to CLEAR the Current String\n"    #clearString()
                "Select 1 to CHANGE the Current String\n"    #changeString()
                "Select 2 to ENCRYPT the Current String\n"   #encryptString()
                "Select 3 to DECRYPT the Current String\n"   #decryptString() 
                "Select 4 to QUIT\n")
            keyInput = input ("Select an option, and then strike the 'ENTER' key: ")
            return keyInput
    '''
    clearString
        @input = the current string
        @output = the current string as ""
    '''
    def clearString():
        clearThisString = ""
        return clearThisString
    
    '''
    changeString
        @input: string from user #currentString initially defined as "HELLO" in main will rcv new value from user
        @output: return string   #currentString now updated to contain the users input
    '''
    def changeString(changeThisString):
        print ("______________________________________________________________________")
        print ("\nYou selected 1 to CHANGE the Current String from ",changeThisString)
        changeThisString = input("\nInput your new string: ")
        print ("\nThe current string is now: ",changeThisString,"\n")
        print ("______________________________________________________________________")
        return changeThisString
    
    '''
    encryptString
        @input: string of currentString
        @output: string of cipherText
    '''
    def encryptString(toBeEncryptedString):
        print ("______________________________________________________________________")
        print ("\nYou selected 2 to ENCRYPT the Current String: ",toBeEncryptedString,"\n")
        string1=""
        string2=""
        string3=""
        counter=0
    
        for character in toBeEncryptedString:
            if counter % 3 == 0:
                string1 = string1 + character
    
            elif counter % 3 == 1:
                string2 = string2 + character
    
            elif counter % 3 == 2:
                string3 = string3 + character
    
            counter = counter + 1
            
        encryptedText = string1 + string2 + string3
        print ("\nThe ENCRYPTED string is now: ",encryptedText,"\n")
        print ("______________________________________________________________________")
        return encryptedText
    
    '''
    decryptString
        @input: string of cipherText
        @output: string of plainText
    '''
    def decryptString(toBeDecryptedString):
        print ("______________________________________________________________________")
        print ("\nYou selected 3 to DECRYPT the Current String: ",toBeDecryptedString,"\n")
        decryptedText=""
        decryptedText1=""
        decryptedText2=""
        decryptedText3=""
        i=0
    
        railLength = (len(toBeDecryptedString))
    
        for i in range (0,railLength,2):
            decryptedText1 = decryptedText1 + toBeDecryptedString[i]
            
        for i in range (1,railLength,2):
            decryptedText2 = decryptedText2 + toBeDecryptedString[i]
    
        for i in range (2,railLength,2):
            decryptedText3 = decryptedText3 + toBeDecryptedString[i]
    
        decryptedText = decryptedText1 + decryptedText2 + decryptedText3
        decryptedText = decryptedText[0:railLength]
    
        print ("\nThe DECRYPTED string is now: ",decryptedText,"\n")
        print ("______________________________________________________________________")
        return decryptedText
    
    '''
    main
        @input: returned keyInput from displayMainMenu()
        @output:
    '''
    def main():
        currentString = "HELLO"     #setting the currentString to "HELLO" for the first and only time (outside loop)
        myChoice = displayMainMenu(currentString) #passing "HELLO" so it shows up on displayMainMenu
    
        while myChoice != '4':
            if myChoice == '0':
                currentString = clearString() # sending (currentString) to function changeString
            elif myChoice == '1':
                currentString = changeString(currentString) # sending (currentString) to function changeString
            elif myChoice == '2':
                currentString = encryptString(currentString)# sending (currentString) to function encryptString
            elif myChoice == '3':
                currentString = decryptString(currentString)# sending (currentString) to function decryptString
    
            myChoice = displayMainMenu(currentString)       # passing ANY currentString to displayMainMenu
    
    main()
  4. #3
  5. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,851
    Rep Power
    481
    In this experiment we learn that decryption and encryption use the same algorithm. The trick? For decryption choose the number of rails as follows: divide the message length by the number of encryption rails, rounding up to the nearest integer.

    If I had to use python I'd use scipy since it has transposition. Hmm, actually, the python zip(*list_of_lists) performs transposition.
    Code:
    >>> a=('abc','def','ghi','jkl','mno','pqr','stu','vwx','yz ',)
    >>> list(zip(*a))
    [('a', 'd', 'g', 'j', 'm', 'p', 's', 'v', 'y'), ('b', 'e', 'h', 'k', 'n', 'q', 't', 'w', 'z'), ('c', 'f', 'i', 'l', 'o', 'r', 'u', 'x', ' ')]
    >>>
    Anyway, the experiment follows in executable Iverson notation
    Code:
       S         NB. our message
    abcdefghijklmnopqrstuvwxyz
    
       _3[\ S    NB. write the text into matrix having as many columns as there are "rails", filling with space character.
    abc
    def
    ghi
    jkl
    mno
    pqr
    stu
    vwx
    yz 
    
       |: _3[\ S    NB. Transpose that matrix
    adgjmpsvy
    behknqtwz
    cfilorux 
    
       , |: _3[\ S  NB. ravel the previous thing.
    adgjmpsvybehknqtwzcfilorux 
       
    
    
       NB. now let's decrypt the message
    
       T=: , |: _3[\ S
    
       T    NB. our encrypted message
    adgjmpsvybehknqtwzcfilorux 
       
    
       # T   NB. how long is it?  (tally includes the fill character)
    27
       
    
       (# T) % 3   NB. how many rails do we need for decryption?
    9
       
    
       _9[\ T    NB. write the text onto a matrix with 9 columns
    adgjmpsvy
    behknqtwz
    cfilorux 
       
    
       |: _9[\ T    NB. transpose that matrix
    abc
    def
    ghi
    jkl
    mno
    pqr
    stu
    vwx
    yz 
       
    
       , |: _9[\ T    NB. ravel all that stuff
    abcdefghijklmnopqrstuvwxyz
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo