E
E
ElShikari2015-10-01 05:24:13
Python
ElShikari, 2015-10-01 05:24:13

How to implement the double permutation algorithm?

It is necessary to implement the input of the original text and the output of the encrypted, and vice versa for decryption.
Briefly about the algorithm:
The key to the double permutation cipher is the sequence of column numbers and row numbers of the source table (in our example, the sequences are 4132 and 3142, respectively).
a47d36e5dee24e54b937b216254275b9.gif
I'm starting to program, so I'll be glad to explain.

s = [list(map(str,input().split())) for i in range (4)]
s[0], s[1] = s[1], s[0]
s[1], s[3] = s[3], s[1]
s[2], s[3] = s[3], s[2]

' '.join(str(x) for x in s)

s[0][0], s[0][1] = s[0][1], s[0][0]
s[0][1], s[0][3] = s[0][3], s[0][1]

s[1][0], s[1][1] = s[1][1], s[1][0]
s[1][1], s[1][3] = s[1][3], s[1][1]

s[2][0], s[2][1] = s[2][1], s[2][0]
s[2][1], s[2][3] = s[2][3], s[2][1]

s[3][0], s[3][1] = s[3][1], s[3][0]
s[3][1], s[3][3] = s[3][3], s[3][1]


print (' '.join(str(x) for x in s))
input ("Press Enter")

The deadlines were running out and I did it in haste, so to speak, using the "brute force" method, which bears little resemblance to normal code. I would like to hear comments.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Dugin, 2016-01-05
@ElShikari

def decode(text, xkeys, ykeys):
    return ''.join(text[4*(y-1)+(x-1)] for y in ykeys for x in xkeys)

print decode(u'ТЮАЕООГМРЛИПОЬСВ', (4,1,3,2), (3,1,4,2))

For coding - by analogy.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question