-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaesiro.java
More file actions
126 lines (120 loc) · 2.28 KB
/
Copy pathcaesiro.java
File metadata and controls
126 lines (120 loc) · 2.28 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package AffineChiper;
import java.util.*;
public class caesiro
{
int shift=0;
public String encrypt(String text)
{ shift=8;
if(shift>26)
{
shift%=26;
}
else if(shift<0)
{
shift=(shift%26)+26;
}
String cipher=" ";
for(int i=0;i<text.length();i++)
{
char bal=text.charAt(i);
if(Character.isLetter(bal))
{
if(Character.isLowerCase(bal))
{
char cae=(char)(bal+shift);
if(cae>'z')
{
cipher+=(char)(bal-(26-shift));
}
else
{
cipher=cipher+cae;
}
}
else if(Character.isUpperCase(bal))
{
char cae=(char)(bal+shift);
if(cae>'Z')
{
cipher+=(char)(bal-(26-shift));
}
else
{
cipher+=cae;
}
}
}
else
{
cipher=cipher+bal;
}
}
System.out.println(cipher);
return cipher;
}
public String decrypt(String text)
{ shift=8;
if(shift>26)
{
shift%=26;
}
else if(shift<0)
{
shift=(shift%26)+26;
}
String cipher=" ";
for(int i=0;i<text.length();i++)
{
char bal=text.charAt(i);
if(Character.isLetter(bal))
{
if(Character.isLowerCase(bal))
{
char cae=(char)(bal-shift);
if(cae<'a')
{
cipher+=(char)(bal+(26-shift));
}
else
{
cipher=cipher+cae;
}
}
else if(Character.isUpperCase(bal))
{
char cae=(char)(bal-shift);
if(cae<'A')
{
cipher+=(char)(bal+(26-shift));
}
else
{
cipher+=cae;
}
}
}
else
{
cipher=cipher+bal;
}
}
return cipher;
}
public static void main(String arg[])
{
/* Scanner sin=new Scanner(System.in);
System.out.println("Enter the plain text:\n");
String msg=sin.nextLine();
System.out.println("Enter the shif:\n");
// int key=sin.nextInt();
System.out.println("the encrypted Text:\n");
String cipher=encrypt(msg);
System.out.println(cipher);
System.out.println("the decrypted Text:\n");
String decode=decrypt(cipher);
System.out.println(decode);*/
String en=new caesiro().encrypt("hello 7299 nave 00%");
System.out.println(new caesiro().decrypt(en) );
ArrayList n=new ArrayList();
}
}