0

I am trying to make a playfair cipher but I am having trouble getting my variables into the right spot.

I have a function that encodes 2 plaintext letters at a time and return the encoded equivalent but it only accepts 2 args of the single letter(in string). I need help getting seperating my list then encoding the pair.

This is what I have

def function(plaintext):
    temp_hold = ''
    encode_out = ''

    sendout = ''

    #breaks into pairs of 2 (list within a list)
    temp_hold = [plaintext[i:i+2] for i in range(0, len(plaintext), 2)]

    for i in range(len(temp_hold)):
        for j in range(len(temp_hold)):
            encode_out = encode_pair(temp_hold[i][j], temp_hold[i][j])
    print encode_out
    # encode pair takes (a,b) and returns its encoded value

print function("abcd") # should print HSCI
Mike McKerns
  • 33,715
  • 8
  • 119
  • 139
xPlasmos
  • 1
  • 2
  • possible duplicate of [appending to a nested list in python](http://stackoverflow.com/questions/13763157/appending-to-a-nested-list-in-python) – lurker Oct 31 '14 at 13:03

1 Answers1

0

Should you really have a nested loop? Shouldn't it be ...

for letter1, letter2 in temp_hold:
    encode_out = encode_pair(letter1, letter2)
    print encode_out
jcfollower
  • 3,103
  • 19
  • 25