Code Duplication    Length = 16-16 lines in 2 locations

checkio/PyCon TW/Playfair Cipher/playfair_cipher.py 2 locations

@@ 78-93 (lines=16) @@
75
        col0 = KeyMatrix.index(i[0]) % 6
76
        row1 = KeyMatrix.index(i[1]) // 6
77
        col1 = KeyMatrix.index(i[1]) % 6
78
        if row0 == row1:
79
            col0 -= 1
80
            col1 -= 1
81
            if col0 < 0:
82
                col0 += 6
83
            if col1 < 0:
84
                col1 += 6
85
        elif col0 == col1:
86
            row0 -= 1
87
            row1 -= 1
88
            if row0 < 0:
89
                row0 += 6
90
            if row1 < 0:
91
                row1 += 6
92
        else:
93
            col0, col1 = col1, col0
94
        message.append(KeyMatrix[row0 * 6 + col0] + KeyMatrix[row1 * 6 + col1])
95
    return ''.join(message)
96
@@ 45-60 (lines=16) @@
42
        col0 = KeyMatrix.index(i[0]) % 6
43
        row1 = KeyMatrix.index(i[1]) // 6
44
        col1 = KeyMatrix.index(i[1]) % 6
45
        if row0 == row1:
46
            col0 += 1
47
            col1 += 1
48
            if col0 > 5:
49
                col0 -= 6
50
            if col1 > 5:
51
                col1 -= 6
52
        elif col0 == col1:
53
            row0 += 1
54
            row1 += 1
55
            if row0 > 5:
56
                row0 -= 6
57
            if row1 > 5:
58
                row1 -= 6
59
        else:
60
            col0, col1 = col1, col0
61
        EncryptedText.append(KeyMatrix[row0 * 6 + col0] + KeyMatrix[row1 * 6 + col1])
62
    return ''.join(EncryptedText)
63