Skip to content

Commit ce6f492

Browse files
committed
playfair needs fixes
1 parent dd648aa commit ce6f492

File tree

51 files changed

+1489
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1489
-0
lines changed

SecurityLibrary/AES/AES.cs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SecurityLibrary.AES
8+
{
9+
/// <summary>
10+
/// If the string starts with 0x.... then it's Hexadecimal not string
11+
/// </summary>
12+
public class AES : CryptographicTechnique
13+
{
14+
public override string Decrypt(string cipherText, string key)
15+
{
16+
throw new NotImplementedException();
17+
}
18+
19+
public override string Encrypt(string plainText, string key)
20+
{
21+
throw new NotImplementedException();
22+
}
23+
}
24+
}

SecurityLibrary/AES/ExtendedEuclid.cs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SecurityLibrary.AES
8+
{
9+
public class ExtendedEuclid
10+
{
11+
/// <summary>
12+
///
13+
/// </summary>
14+
/// <param name="number"></param>
15+
/// <param name="baseN"></param>
16+
/// <returns>Mul inverse, -1 if no inv</returns>
17+
public int GetMultiplicativeInverse(int number, int baseN)
18+
{
19+
throw new NotImplementedException();
20+
}
21+
}
22+
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SecurityLibrary
8+
{
9+
public abstract class CryptographicTechnique : ICryptographicTechnique<string, string>
10+
{
11+
public string Analyse(string plainText, string cipherText)
12+
{
13+
throw new NotSupportedException();
14+
}
15+
16+
public abstract string Decrypt(string cipherText, string key);
17+
18+
public abstract string Encrypt(string plainText, string key);
19+
}
20+
}

SecurityLibrary/DES/DES.cs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SecurityLibrary.DES
8+
{
9+
/// <summary>
10+
/// If the string starts with 0x.... then it's Hexadecimal not string
11+
/// </summary>
12+
public class DES : CryptographicTechnique
13+
{
14+
public override string Decrypt(string cipherText, string key)
15+
{
16+
throw new NotImplementedException();
17+
}
18+
19+
public override string Encrypt(string plainText, string key)
20+
{
21+
throw new NotImplementedException();
22+
}
23+
}
24+
}

SecurityLibrary/DES/TripleDES.cs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SecurityLibrary.DES
8+
{
9+
/// <summary>
10+
/// If the string starts with 0x.... then it's Hexadecimal not string
11+
/// </summary>
12+
public class TripleDES : ICryptographicTechnique<string, List<string>>
13+
{
14+
public string Decrypt(string cipherText, List<string> key)
15+
{
16+
throw new NotImplementedException();
17+
}
18+
19+
public string Encrypt(string plainText, List<string> key)
20+
{
21+
throw new NotImplementedException();
22+
}
23+
24+
public List<string> Analyse(string plainText,string cipherText)
25+
{
26+
throw new NotSupportedException();
27+
}
28+
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SecurityLibrary.DiffieHellman
8+
{
9+
public class DiffieHellman
10+
{
11+
public List<int> GetKeys(int q, int alpha, int xa, int xb)
12+
{
13+
throw new NotImplementedException();
14+
}
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SecurityLibrary
8+
{
9+
public class InvalidAnlysisException : Exception
10+
{
11+
}
12+
}
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SecurityLibrary
8+
{
9+
public interface ICryptographicTechnique<T, K>
10+
{
11+
/// <summary>
12+
/// This encrypts the given plain text with the given key.
13+
/// </summary>
14+
/// <param name="plainText">The plain text.</param>
15+
/// <param name="key">The key.</param>
16+
/// <returns>The cipher text.</returns>
17+
T Encrypt(T plainText, K key);
18+
19+
/// <summary>
20+
/// This decrypts the given cipher text with the given key.
21+
/// </summary>
22+
/// <param name="plainText">The plain text.</param>
23+
/// <param name="key">The key.</param>
24+
/// <returns>The plain text.</returns>
25+
T Decrypt(T cipherText, K key);
26+
27+
/// <summary>
28+
/// Finds the key of the given Plain text and cipher text.
29+
/// </summary>
30+
/// <param name="plainText">The plain text.</param>
31+
/// <param name="cipherText">The cipher text.</param>
32+
/// <returns>The key text.</returns>
33+
/// Throws InvalidAnlysisException if key cannot be found with the given data.
34+
K Analyse(T plainText, T cipherText);
35+
}
36+
}

SecurityLibrary/MD5/MD5.cs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SecurityLibrary.MD5
8+
{
9+
public class MD5
10+
{
11+
public string GetHash(string text)
12+
{
13+
throw new NotImplementedException();
14+
}
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SecurityLibrary
8+
{
9+
public class AutokeyVigenere : ICryptographicTechnique<string, string>
10+
{
11+
public string Analyse(string plainText, string cipherText)
12+
{
13+
throw new NotImplementedException();
14+
}
15+
16+
public string Decrypt(string cipherText, string key)
17+
{
18+
throw new NotImplementedException();
19+
}
20+
21+
public string Encrypt(string plainText, string key)
22+
{
23+
throw new NotImplementedException();
24+
}
25+
}
26+
}
+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SecurityLibrary
8+
{
9+
public class Ceaser : ICryptographicTechnique<string, int>
10+
{
11+
public string alphabet = "abcdefghijklmnopqrstuvwxyz";
12+
13+
public int letterNum(char letter) // O(1)
14+
{
15+
for (int i = 0; i < 26; i++)
16+
{
17+
if (letter == alphabet[i]) return i;
18+
}
19+
20+
return -1;
21+
}
22+
public string Encrypt(string plainText, int key)
23+
{
24+
int PTLength = plainText.Length;
25+
string CT = "";
26+
for (int i = 0; i < PTLength; i++) // O(N)
27+
{
28+
if (char.IsLetter(plainText[i]))
29+
{
30+
int letterIndx = ((key + letterNum(plainText[i]))%26);
31+
CT += char.ToUpper(alphabet[letterIndx]);
32+
}
33+
else
34+
{
35+
CT += plainText[i];
36+
}
37+
}
38+
39+
return CT;
40+
41+
}
42+
43+
public string Decrypt(string cipherText, int key)
44+
{
45+
cipherText = cipherText.ToLower();
46+
int CTLength = cipherText.Length;
47+
string PT = "";
48+
for (int i = 0; i < CTLength; i++) // O(N)
49+
{
50+
if (char.IsLetter(cipherText[i]))
51+
{
52+
int letterIndx = ((letterNum(cipherText[i]) - key) % 26);
53+
if(letterIndx < 0) letterIndx += 26;
54+
PT += alphabet[letterIndx];
55+
}
56+
else
57+
{
58+
PT += cipherText[i];
59+
}
60+
}
61+
62+
return PT;
63+
}
64+
65+
public int Analyse(string plainText, string cipherText) // O(1)
66+
{
67+
if (plainText.Length != cipherText.Length) return -1;
68+
int letterPN = letterNum(plainText[0]);
69+
int letterCN = letterNum(char.ToLower(cipherText[0]));
70+
71+
return ((letterCN - letterPN) < 0) ? (letterCN - letterPN) + 26 : (letterCN - letterPN) % 26;
72+
}
73+
}
74+
}
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SecurityLibrary
8+
{
9+
public class Columnar : ICryptographicTechnique<string, List<int>>
10+
{
11+
public List<int> Analyse(string plainText, string cipherText)
12+
{
13+
throw new NotImplementedException();
14+
}
15+
16+
public string Decrypt(string cipherText, List<int> key)
17+
{
18+
throw new NotImplementedException();
19+
}
20+
21+
public string Encrypt(string plainText, List<int> key)
22+
{
23+
throw new NotImplementedException();
24+
}
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SecurityLibrary
8+
{
9+
/// <summary>
10+
/// The List<int> is row based. Which means that the key is given in row based manner.
11+
/// </summary>
12+
public class HillCipher : ICryptographicTechnique<string, string>, ICryptographicTechnique<List<int>, List<int>>
13+
{
14+
public List<int> Analyse(List<int> plainText, List<int> cipherText)
15+
{
16+
throw new NotImplementedException();
17+
}
18+
19+
public string Analyse(string plainText, string cipherText)
20+
{
21+
throw new NotImplementedException();
22+
}
23+
24+
public List<int> Decrypt(List<int> cipherText, List<int> key)
25+
{
26+
throw new NotImplementedException();
27+
}
28+
29+
public string Decrypt(string cipherText, string key)
30+
{
31+
throw new NotImplementedException();
32+
}
33+
34+
public List<int> Encrypt(List<int> plainText, List<int> key)
35+
{
36+
throw new NotImplementedException();
37+
}
38+
39+
public string Encrypt(string plainText, string key)
40+
{
41+
throw new NotImplementedException();
42+
}
43+
44+
public List<int> Analyse3By3Key(List<int> plain3, List<int> cipher3)
45+
{
46+
throw new NotImplementedException();
47+
}
48+
49+
public string Analyse3By3Key(string plain3, string cipher3)
50+
{
51+
throw new NotImplementedException();
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)