-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEncryption.java
59 lines (51 loc) · 2.03 KB
/
Encryption.java
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
package pkg;
//AlpNumAlp Class For Alpabate to Numaric ANd Num To Alp
public class Encryption {
public int AtoN(char pText) {
int Index = 404;
char AZ[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
char az[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
't', 'u', 'v', 'w', 'x', 'y', 'z' };
for (int i = 0; i <= 25; i++) {
if (pText == AZ[i] || pText == az[i])
Index = i;
}
return Index;
}
public char NtoA(int Index) {
char AZ[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
// char az[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
// 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
char ptext;
ptext = AZ[Index];
return ptext;
}
public int CaesarCipherEnc(int PlaneNumber, int key) {
int EnX = (PlaneNumber + key) % 26;
return EnX;
}
public int CaesarCipherDcp(int PlaneNumber, int key) {
int EnX = (PlaneNumber - key) % 26;
return EnX;
}
public String ccEnc(String PlaneText, int key) {
char demo;
String EncText = "";
for (int i = 0; i <= PlaneText.length() - 1; i++) {
demo = this.NtoA(this.CaesarCipherEnc(this.AtoN(PlaneText.charAt(i)), key));
EncText = EncText + demo;
}
return EncText;
}
public String ccDcp(String PlaneText, int key) {
char demo;
String EncText = "";
for (int i = 0; i <= PlaneText.length() - 1; i++) {
demo = this.NtoA(this.CaesarCipherDcp(this.AtoN(PlaneText.charAt(i)), key));
EncText = EncText + demo;
}
return EncText;
}
}