-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenc.java
43 lines (38 loc) · 782 Bytes
/
enc.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
import java.io.*;
import java.lang.*;
class enc
{
public static void main(String args[]) throws IOException
{
String str;
int i,n;
double[] rnd;
double[] a;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter String:");
str=br.readLine();
rnd = new double[str.length()];
a=new double[str.length()];
for(i=0;i<str.length();i++)
{
char ch=str.charAt(i);
rnd[i]=(Math.round(Math.random()*10));
a[i]=(int)ch+rnd[i];
}
System.out.print("Encrypted string:");
for(i=0;i<str.length();i++)
{
System.out.print( (char)a[i]);
}
System.out.print("\n");
for(i=0;i<str.length();i++)
{
a[i]=a[i]-rnd[i];
}
System.out.print("Decrypted String:");
for(i=0;i<str.length();i++)
{
System.out.print((char)a[i]);
}
}
}