-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathROT_Encryptor_and_Decryptor.cs
131 lines (109 loc) · 3.61 KB
/
ROT_Encryptor_and_Decryptor.cs
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ROT_Encryptor_and_Decryptor
{
class input
{
static int method=0;
public static int opt = 0;
string usertxt;
int[] arr;
public input(int op, int o)
{
// checking for ROT version 1 - 25 (validation)
if (op >= 1 && op <= 25)
{
opt = op;
method = o;
}
else
{
Console.WriteLine("Please choose number between 1 to 25");
}
}
// Text from user for encryt / decrypt
public input(string text)
{
// Size of text
int size = text.Count();
arr = new int[size];
// Seperating each char of text in form of ASCII
for (int i = 0; i < text.Length; i++)
{
arr[i] = (text[i]);
}
// Converting for encrypt
if (method == 1)
{
//int temp;
//int less;
for (int i = 0; i < arr.Length; i++)
{
// accepting only a-z or A-Z skip other characters
if (arr[i] >= 65 && arr[i] <= 90 || arr[i] >= 97 && arr[i] <= 122)
{
//temp = arr[i];
arr[i] += opt;
//if(arr[i] > 90 )
//{
// less = arr[i]-25;
// Console.WriteLine("agay "+less);
//}
}
}
}
// Converting for decrypt
else if (method == 2)
{
for (int i = 0; i < arr.Length; i++)
{
// accepting only a-z or A-Z skip other characters
if (arr[i] >= 65 && arr[i] <= 90 || arr[i] >= 97 && arr[i] <= 122)
{
arr[i] -= opt;
}
}
}
// Out put in form of encrpt / decrypt
Console.WriteLine("Output \n\n");
for (int i = 0; i < arr.Length; i++)
{
Console.Write((char)arr[i]);
}
Console.WriteLine("\n");
}
}
class Program
{
static void Main(string[] args)
{
try
{
Console.WriteLine("Press 1 for Encrypt\nPress 2 for Decrypt\n\n");
int o = int.Parse(Console.ReadLine());
Console.Clear();
Console.WriteLine("Choose ROT 1 to 25\n pick a number");
int option = Convert.ToInt32(Console.ReadLine());
Console.Clear();
// var option holds ROT version 1-25
// var o holds Choise encrypt / decrypt
input obj = new input(option, o);
// Checking point if use select wrong version of ROT
if (input.opt != 0)
{
// text input
Console.WriteLine("Enter your text");
string usr = Console.ReadLine();
input user = new input(usr);
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}