-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlabs1_1.java
More file actions
104 lines (87 loc) · 2.5 KB
/
labs1_1.java
File metadata and controls
104 lines (87 loc) · 2.5 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
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
public class labs1_1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String LowText = "abcdefghijklmnopqrstuvwxyz";
String HightText = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char LowMas[] = LowText.toCharArray();
char HightMas[] = HightText.toCharArray();
char OffsetLowMas[] = new char[LowMas.length];
char OffsetHightMas[] = new char[HightMas.length];
for (int j = 0; j < LowMas.length; j++) {
char c = (char)LowMas[j];
char first = 'a';
int key = 3;
if (first != 0)
c = (char)(first + (c - first + key + 26) % 26);
OffsetLowMas[j] = c;
}
for (int j = 0; j < HightMas.length; j++) {
char c = (char)HightMas[j];
char first = 'A';
int Hightkey = 5;
if (first != 0)
c = (char)(first + (c - first + Hightkey + 26) % 26);
OffsetHightMas[j] = c;
}
System.out.print("Offset for upper case\n");
for (int j = 0; j < HightMas.length; j++) {
System.out.print(HightMas[j] + "\t");
}
System.out.print("\n");
for (int j = 0; j < OffsetHightMas.length; j++) {
System.out.print(OffsetHightMas[j] + "\t");
}
System.out.print("\n");
System.out.print("Offset for lower case\n");
for (int j = 0; j < LowMas.length; j++) {
System.out.print(LowMas[j] + "\t");
}
System.out.print("\n");
for (int j = 0; j < OffsetLowMas.length; j++) {
System.out.print(OffsetLowMas[j] + "\t");
}
System.out.print("\n");
String inputText = "Hello World!";
byte inputMas[] = inputText.getBytes();
char outputMas[] = new char[inputMas.length];
char DeShifrMas[] = new char[inputMas.length];
int key = 3;
for (int j = 0; j < inputMas.length; j++) {
char c = (char)inputMas[j];
char first = 0;
if (c >= 'a' && c <= 'z') {
first = 'a';
key = 3;
}
else if (c >= 'A' && c <= 'Z') {
first = 'A';
key = 5;
}
if (first != 0)
c = (char)(first + (c - first + key + 26) % 26);
outputMas[j] = c;
}
String outputText = new String(outputMas);
System.out.println("Encryption message:\n" + outputText);
for (int j = 0; j < outputMas.length; j++) {
char c = (char)outputMas[j];
char first = 0;
if (c >= 'a' && c <= 'z') {
first = 'a';
key = 3;
}
else if (c >= 'A' && c <= 'Z') {
first = 'A';
key = 5;
}
if (first != 0)
c = (char)(first + (c - first - key + 26) % 26);
DeShifrMas[j] = c;
}
String DeShifrText = new String(DeShifrMas);
System.out.println("Decryption message:\n" + DeShifrText);
}
}