Repository navigation
Expand file tree
/
Copy pathMonoalphabetic.cs
More file actions
51 lines (49 loc) · 1.83 KB
/
Copy pathMonoalphabetic.cs
File metadata and controls
51 lines (49 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lib_SC
{
public class Monoalphabetic
{
private static string Eng_Char = "abcdefghijklmnopqrstuvwxyz";
//Main Function
public static string MainFunctionMonoalphabetic(string OldText, string Key, bool T)
=> ChoseType(T).Invoke(OldText, Key);
//Chose Type Encryption or Decryption
private static Func<string, string, string> ChoseType(bool T)
=> T ? MonoalphabeticEncryption : MonoalphabeticDecryption;
//Take Char From Eng_Char And Covert To KEY
// EngChars:'abc' ,Key:'DFG',OldText:'fg'
//newText='fg'
private static string MonoalphabeticEncryption(string OldText, string Key)
{
string NewString = "";
OldText.ToList().ForEach(
x =>
{
int index = Eng_Char.IndexOf(x >= 97 && x <= 122 ? x : CovertCharFromCaptialToSmall(x));
NewString = $"{NewString}{Key[index]}";
});
return NewString;
}
//Take Char From Key And Covert To Eng_Char
// EngChars:'abc' ,Key:'DFG',OldText:'fg'
//newText='bc'
private static string MonoalphabeticDecryption(string OldText, string Key)
{
string NewString = "";
OldText.ToList().ForEach(
x =>
{
Key = Key.ToLower();
int index = Key.IndexOf(x >= 97 && x <= 122 ? x : CovertCharFromCaptialToSmall(x));
NewString = $"{NewString}{Eng_Char[index]}";
});
return NewString;
}
private static char CovertCharFromCaptialToSmall(char c)//A - a
=> (char)(c + 32);
}
}