Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0c28705

Browse files
Columnar Algorithm added
1 parent 02b38b0 commit 0c28705

File tree

12 files changed

+34
-12
lines changed

12 files changed

+34
-12
lines changed

‎SecurityLibrary/MainAlgorithms/Columnar.cs

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,49 @@ public List<int> Analyse(string plainText, string cipherText)
1414
throw new NotImplementedException();
1515
}
1616

17+
18+
19+
1720
public string Decrypt(string cipherText, List<int> key)
1821
{
19-
List<List<char>> table = new List<List<char>>();
20-
Dictionary<int, string> cip = new Dictionary<int, string>();
21-
string PT = "";
22-
cipherText = cipherText.ToLower();
23-
int columns = key.Count;
24-
int rows = (int)Math.Ceiling((double)cipherText.Length / columns);
25-
for (int i = 0; i < rows; i++)
22+
cipherText = cipherText.ToUpper();
23+
int x = cipherText.Length;
24+
if (x % key.Count == 0)
2625
{
27-
table.Add(new List<char>());
2826
}
29-
for(inti=0;i<columns;i++)
27+
else
3028
{
31-
for (int j = 0; j < rows; j++)
29+
x += key.Count;
30+
}
31+
double col = x / key.Count;
32+
int c = (int)(col);
33+
string finalll = "";
34+
char[,] enc = new char[c, key.Count];
35+
int k = 0;
36+
int tmp = 0;
37+
for (int i = 0; i < key.Count; i++)
38+
{
39+
k = key.IndexOf(i + 1);
40+
41+
for (int j = 0; j < col; j++)
42+
{
43+
if (tmp < cipherText.Length)
44+
{
45+
enc[j, k] = cipherText[tmp];
46+
tmp++;
47+
}
48+
}
49+
}
50+
for (int i = 0; i < col; i++)
51+
{
52+
for (int j = 0; j < key.Count; j++)
3253
{
33-
54+
finalll=finalll+enc[i,j];
3455
}
3556
}
3657

37-
return "";
58+
59+
return finalll.ToUpper();
3860
}
3961

4062
public string Encrypt(string plainText, List<int> key)
0 Bytes
Binary file not shown.
2 KB
Binary file not shown.
0 Bytes
Binary file not shown.
2 KB
Binary file not shown.
0 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /