-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencryptpin2.java
More file actions
103 lines (96 loc) · 2.68 KB
/
encryptpin2.java
File metadata and controls
103 lines (96 loc) · 2.68 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
/* Ankit Raj Biswal
1941012238
@_head_hunter25*/
package project;
import java.util.*;
public class encryptpin2 {
public static void main(String[] args) {
/*Variables
pin1= 1st generated pin
pin2= 2nd generated pin
pin3= 3rd generated pin
pin4= 4th generated pin
PIN= Number of digits of PIN
newpin= Auto Generated Pin
'd' string = digits(here d is used for extracting the digits out of random numbers)
msg= The message inputed by the user for encryption
emsg= Encrypted message which came as result
c=counter*/
Scanner sc = new Scanner(System.in);
String pin1,pin2,pin3,pin4;
System.out.print("Enter the Value of Digits of PIN you want to Create :");
int PIN=sc.nextInt();
String d="";
for(int i=0; i<PIN; i++)
{
d=d+(int)(Math.random()*10);
}
pin1=d;
System.out.println(pin1);
d="";
for(int i=0; i<PIN; i++)
{
d=d+(int)(Math.random()*10);
}
pin2=d;
System.out.println(pin2);
d="";
for(int i=0; i<PIN; i++)
{
d=d+(int)(Math.random()*10);
}
pin3=d;
System.out.println(pin3);
d="";
for(int i=0; i<PIN; i++)
{
d=d+(int)(Math.random()*10);
}
pin4=d;
System.out.println(pin3);
d="";
for(int i=0; i<PIN; i++)
{
d=d+(char)Math.min(Math.min(pin1.charAt(i),pin2.charAt(i)),Math.min(pin3.charAt(i),pin4.charAt(i)));
}
String newpin=d;
System.out.println("The New Pin Generated By the system is : " +newpin);
sc.nextLine();
System.out.print("Enter The Message you want to encrypt :");
String msg=sc.nextLine();
msg=msg.toLowerCase();
//System.out.println(msg);
msg=msg.replaceAll(" ","");
//System.out.println(msg);
int c=0;
String emsg="";
d="";
for(int i=0; i<msg.length(); i++)
{
char ch=msg.charAt(i);
if(ch!=' ')
{
d=d+ch;
}
}
msg=d;
for(int i=0; i<msg.length(); i++,c++)
{
if(c==(newpin.length()-1))
c=0;
char ch1=msg.charAt(i);
char ch2=newpin.charAt(c);
int tmp=(int)ch2;
tmp=tmp-48;
ch1=(char)((int)ch1+tmp);
if(ch1>122)
{
ch1=(char)((int)ch1-122);
ch1=(char)((int)ch1+96);
}
emsg=emsg+ch1;
}
emsg=emsg.toUpperCase();
System.out.println("Encrypted Message is :"+emsg);
}
}