Hello, there were problems when writing the program permutation cipher on c #, in which you need to change the word order. The key is a permutation of numbers from 0 to n. By default, I set the order to 3,2,5,7,4,6,1, which corresponds to the source text. With this piece of code, I changed the word order to 1,2,3,4,5,6,7. The word order has changed correctly. Each letter corresponds to one digit of the keyword, if there are more letters, then the keyword is repeated. And the task also says: Decryption is done in the same way, but a different key is used. To get the decryption key you need to encrypt the string "1234567"; at the same time we get "7215364". And how to get exactly this order of the key: "7215364", and then from it back 3,2,5,7,4,6,1, to get the source code? Can someone come across tell me.

private string get_abc(string key) // Сортировать буквы ключа по алфавиту { int i, j, x; string sw; for (j = 0; j < key.Length; j++) abc[j] = j; for (i = 0; i < key.Length - 1; i++) for (j = 0; j < key.Length - i - 1; j++) if (key[j] > key[j + 1]) { sw = key; key = key.Remove(j, 2).Insert(j, sw.Substring(j + 1, 1)).Insert(j + 1, sw.Substring(j, 1)); } return key; } 
  • The source text can only correspond to a single permutation, leaving everything in place. What does your default key mean? From your question it is not clear where it is necessary to change the order of words: in the program or in the shifting cipher? In the program, you usually cannot change words, and a swap cipher is either an algorithm or a ciphertext. It is difficult to change the words in the ciphertext, because there are usually just bytes and it is not clear what the word is, and the permutation leads to a superposition with another encryption. If the cipher is permutable, then the decryption key should be the reverse permutation - yapycoder

2 answers 2

um The question is not entirely clear. But if you need to get the source key knowing the decryption key - just encrypt the decryption key with the 1234567 sequence ... As they say, everything is simple ... the encryption key is inverse to the decryption key and vice versa. Those. if you take the key 7215364 for encryption, then you will use your original 3,2,5,7,4,6,1 to decrypt ...

    After reading the question, indeed, it seems that the author does not quite understand what he is asking.
    Maybe you should clarify the question.
    Or at least write what you mean by the words "By default, I set the order to 3,2,5,7,4,6,1, which corresponds to the source text.". It is assumed that if you had a sequence of letters ABWGDEZ you get VBJGEA? (I think you assume this under the cipher) But then again, "Each letter corresponds to one digit of the keyword, if there are more letters, then the keyword repeats.", What's what? (It means that if there are more than 7 letters in the coded word, then the next ones are encoded with the same key again?)

    Well, let me say that I correctly deciphered the beginning of your question.
    Those you got the key 7.2,1,5,3,6,4. And now you want to encrypt the already encrypted text so that it would turn out as if you encrypted it once with the key 3,2,5,7,4,6,1.
    Yes, then you need to look at how to convert 7215364 to 3257461. For this, obviously, you need to encrypt it again with the key 5,2,4,1,7,6,3.

    And you get the text, which can be decrypted as if it was encrypted in the order of 3,2,5,7,4,6,1.

    I think you asked exactly that. (reread it 4 times)

    • um ....... silently keep quiet .... (off-topic, of course, it’s easy to trace the thread who, what, and what has encrypted and what needs to be done with this something .... :) - gote