Skip to content

Commit 9483b0a

Browse files
committed
RepeatingkeyVigenere Algorithm added
1 parent 0c28705 commit 9483b0a

13 files changed

+57
-3
lines changed

β€ŽSecurityLibrary/MainAlgorithms/RepeatingKeyVigenere.cs

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,71 @@ public class RepeatingkeyVigenere : ICryptographicTechnique<string, string>
1010
{
1111
public string Analyse(string plainText, string cipherText)
1212
{
13-
throw new NotImplementedException();
13+
cipherText = cipherText.ToLower();
14+
int clength = cipherText.Length;
15+
string alphabet = "abcdefghijklmnopqrstuvwxyz";
16+
string key = "";
17+
string temp = "";
18+
for (int i = 0; i < clength; i++)
19+
{
20+
key = key + alphabet[((alphabet.IndexOf(cipherText[i]) - alphabet.IndexOf(plainText[i])) + 26) % 26];
21+
}
22+
temp = temp + key[0];
23+
int klength = key.Length;
24+
for (int i = 1; i < klength; i++)
25+
{
26+
if (cipherText.Equals(Encrypt(plainText, temp)))
27+
{
28+
return temp;
29+
}
30+
temp = temp + key[i];
31+
}
32+
return key;
33+
//throw new NotImplementedException();
1434
}
1535

1636
public string Decrypt(string cipherText, string key)
1737
{
18-
throw new NotImplementedException();
38+
cipherText = cipherText.ToLower();
39+
int clength = cipherText.Length;
40+
string plaintext = "";
41+
string alphabet = "abcdefghijklmnopqrstuvwxyz";
42+
int temp = 0;
43+
while (key.Length != clength)
44+
{
45+
key += key[temp];
46+
temp++;
47+
}
48+
for (int i = 0; i < clength; i++)
49+
{
50+
plaintext = plaintext + alphabet[((alphabet.IndexOf(cipherText[i]) - alphabet.IndexOf(key[i])) + 26) % 26];
51+
52+
}
53+
54+
return plaintext;
55+
//throw new NotImplementedException();
56+
1957
}
2058

59+
2160
public string Encrypt(string plainText, string key)
2261
{
23-
throw new NotImplementedException();
62+
int temp = 0;
63+
int plength = plainText.Length;
64+
string ciphertext = "";
65+
string alphabet = "abcdefghijklmnopqrstuvwxyz";
66+
while (key.Length != plainText.Length)
67+
{
68+
key = key + key[temp];
69+
temp++;
70+
}
71+
for (int i = 0; i < plength; i++)
72+
{
73+
ciphertext = ciphertext + alphabet[((alphabet.IndexOf(plainText[i]) + alphabet.IndexOf(key[i]))) % 26];
74+
75+
}
76+
return ciphertext;
77+
//throw new NotImplementedException();
2478
}
2579
}
2680
}
Binary file not shown.
0 Bytes
Binary file not shown.
Binary file not shown.
0 Bytes
Binary file not shown.

β€ŽSecurityPackage.v12.suo

5.5 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)