They asked to write a program that encrypts and decrypts text using the Vigenere table. Please help with writing the code.
- fourEnter the following line in the Google search: Vigeneur c # algorithm Get a full page of results, including an archive with ready-made code, a description of the algorithm, and even a video instruction. - mantigatos
- one@ _Win_32, According to the rules of the forum, questions should not be limited to solving or completing student assignments. Please clarify what you have done yourself and what did not work out. And those who are still responsible - ban a little :). For they also indirectly violate the rules of the forum. - Baran
- @Darix, and the code from @Spectre is really good (I'm afraid not for beginners). If a student (about the tasks for which you are so worried) really understands how he works , then he will benefit more from self-crafted program. - avp
|
1 answer
Found among the old lab, encryption method:
_alph = "abcdefghijklmnopqrstuvwxyz"; private static int IndexNormalizer(int count, int index) { return index >= 0 ? index - count * (index / count) // + : count + index + count * (-(index + 1) / count);//+ } //шифр Виженера string VigenereEncrypt(string text, string key, bool flag) { return new string(text.Select((ch, idx) => _alph[IndexNormalizer(_alph.Length, _alph.IndexOf(ch) + _alph.IndexOf(key[IndexNormalizer(key.Length, idx)])*(flag ? 1 : -1))]).ToArray()); }
UPD: I'm just amazed at the “compactness” of the code I was once striving for.
- ch idx what do they mean - user9441
- the character and its index in the string - Specter
|