feat: encryption working

This commit is contained in:
citizen-VM 2020-08-24 04:09:08 +02:00
parent 8f81a583e5
commit 251303276d
Signed by: wanderer
GPG Key ID: 6391444A736EEE7E

View File

@ -185,11 +185,63 @@ namespace KRY_0x01_ng
}
int[] gimme_char_indices(char ch)
{
int[] chxy = new int[2];
int atbgl = arrayTable.GetLength(0);
for (int i = 0; i < atbgl; i++)
{
for (int j = 0; j < atbgl; j++)
{
if (arrayTable[i,j].Equals(ch))
{
chxy[0] = i;
chxy[1] = j;
}
}
}
return chxy;
}
void encrypt()
{
check_message(textBox4);
prep_message(textBox5);
string cryptmessage = "";
string msg = prep_msg_str;
int arrtb_gl = arrayTable.GetLength(0);
for (int i = 0; i < msg.Length; i+=2)
{
char ch1 = msg[i];
char ch2 = msg[i + 1];
char ech1 = new char();
char ech2 = new char();
int[] ch1xy = gimme_char_indices(ch1);
int[] ch2xy = gimme_char_indices(ch2);
if (ch1xy[0] == ch2xy[0])
{
ech1 = arrayTable[ch1xy[0], ch1xy[1] + 1 % arrtb_gl];
ech2 = arrayTable[ch2xy[0], ch2xy[1] + 1 % arrtb_gl];
}
else if (ch1xy[1] == ch2xy[1])
{
ech1 = arrayTable[ch1xy[0] + 1 % arrtb_gl, ch1xy[1]];
ech2 = arrayTable[ch2xy[0] + 1 % arrtb_gl, ch2xy[1]];
}
else
{
ech1 = arrayTable[ch1xy[0], ch2xy[1]];
ech2 = arrayTable[ch2xy[0], ch1xy[1]];
}
string resulting_digraph = ech1.ToString() + ech2.ToString();
cryptmessage += resulting_digraph;
}
textBox7.Text = cryptmessage;
return;
}