Vigenere Square Lookup (using string arrays)

Vigenere ciphers are supposedly easy to use (well, to some extent), but converting it directly to program code is a completely different story. Apparently.

Here is the Vigenere square: Vigenere Square from Wikipedia

Let's say I have a method that can encrypt text using the Vigenere Square cipher, while preserving whitespace and special characters (or most of them).

static string EncryptedText(string plaintext, string keyword)
{
    string tempStore = "";
    string KeyToUse = ExpandKey(RemoveAllNonAlpha(plaintext), keyword);
    string[] tempList;
    int iSelector = 0;

    for (int ii = 0; ii < RemoveAllNonAlpha(plaintext).Length; ii++)
    {
        tempList = GetNewAlphaList(KeyToUse[ii].ToString());
        if (RemoveAllNonAlpha(plaintext)[ii].ToString() != " ")
        {
            iSelector = NeverOver26(GetNumericFromLetter(RemoveAllNonAlpha(plaintext)[ii].ToString())) - 1;

            tempStore += tempList[iSelector].ToLower();
        }
        else
        {
            tempStore += " ";
        }
    }

    return ReplaceAllNonAlpha(tempStore, plaintext);
}

If we assume that for the above, the following functions are such as ...

string ExpandKey (line input) => Extend the key until it matches plain text.

string RemoveAllNonAlpha (line input) => Basically remove everything that is not an alphabet. Uses Regex Replace.

int GetNumericFromLetter ( char) = > A = 1 Z = 26. .

string ReplaceAllNonAlpha ( , ) = > , . , , .

int NeverOver26 (int input) = > 26 , 26.

string [] GetNewAlphaList ( char) = > vigenere , . , "L", { "L", "M", "N", "O", "P", "Q", "R", "S", "T" "," U "," V "," W "," X "," Y "," Z "," A "," B "," C "," D "," E "," F "," G "," H "," I "," J "," K"}.

, , , Vigenere Square.

, , , :

static string DecryptedText(string ciphertext, string keyword)
{
    //Broken, non deciphering
    string tempStore = "";
    string KeyToUse = ExpandKey(RemoveAllNonAlpha(ciphertext), keyword);
    string[] tempList;

    for (int ii = 0; ii < RemoveAllNonAlpha(ciphertext).Length; ii++)
    {
        tempList = GetNewAlphaList(RemoveAllNonAlpha(ciphertext)[ii].ToString());

        for (int iii = 0; iii < tempList.Length; iii++)
        {
            if (tempList[iii].ToString().ToLower() == KeyToUse[ii].ToString().ToLower())
            {
                tempStore+= GetAlphaFromNumber(iii).ToLower();
                break;
            }
        }
    }

    return ReplaceAllNonAlpha(tempStore, ciphertext);
}

( ) , , , ...

string GetAlphaFromNumber (int input) = > GetNumericFromLetter() .

, . , , / Vigenere Square.

- - ? , , , Vigenere Square table (, , )

, , , , , :

, , , :


...

: ATTACK ON DAWN. LOL

: LEMON

: lxfopv ef rnhr. XCY


...

: lxfopv ef rnhr. XCY

: LEMON

: ahhayq ah xaen. PMP

: http://planetcalc.com/2468/

+4
1

, . , . , , , , , . , :

internal static string DecryptedText(string ciphertext, string keyword)
{
    string tempStore = "";
    string KeyToUse = ExpandKey(RemoveAllNonAlpha(ciphertext), keyword);
    string[] tempList;
    int iSelector = 0;

    for (int ii = 0; ii < RemoveAllNonAlpha(ciphertext).Length; ii++)
    {
        tempList = GetNewAlphaList(KeyToUse[ii].ToString());

        for (int iii = 0; iii < tempList.Length; iii++)
        {
            ////seperated the two to verify they were not returning the wrong values
            //string FromList = tempList[iii].ToString().ToLower();
            //string FromCipher = RemoveAllNonAlpha(ciphertext)[ii].ToString().ToLower();

            if (tempList[iii].ToString().ToLower() ==  RemoveAllNonAlpha(ciphertext)[ii].ToString().ToLower())//if (FromList == FromCipher)
            {
                tempStore += GetAlphaFromNumber(iii).ToLower();
                break;
            }
        }
    }

    return ReplaceAllNonAlpha(tempStore, ciphertext);
}

...

: . , wohoo!

: stackoverflowisthebest

: laiu sg eyjy l geuhel xfwl. vgfpnohz azys dqvumbeumggk zanyfz, afmzc!


...

: laiu sg eyjy l geuhel xfwl. vgfpnohz azys dqvumbeumggk zanyfz, afmzc!

: stackoverflowisthebest

: . , wohoo!


, .

+2

Source: https://habr.com/ru/post/1616573/


All Articles