-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChange.java
More file actions
76 lines (66 loc) · 2 KB
/
Copy pathChange.java
File metadata and controls
76 lines (66 loc) · 2 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
public class Change{
private String orgNum;
private String encNum;
private String dycNum;
private int changeO;
private int changeT;
private int [] num = new int[4];
//Change constructor
public Change(){
//creates the change object
}
//method that takes the number and encrypts it
/*public String encrypt(String number){
// checks the length is 4
if (number.length() == 4){
// for loop that separates each digit, turns into a integer, and does the encryption.
for(int i =0; i <= 3; i++){
num[i] = ((Integer.parseInt(Character.toString(number.charAt(i)))) +7)%10 ;
}
//Switches the first digit and thrid digit;
changeO = num[2];
num[2]=num[0];
num[0]= changeO;
//Switches the second and fouth digit
changeT = num[3];
num[3]=num[1];
num[1]=changeT;
encNum = new String();
//turns the digits to String and adds them together
for(int j =0; j <= 3; j++){
encNum = encNum + (Integer.toString(num[j]));
}
}
// returns the encrypted number
return encNum ;
}*/
//method that takes the number and decrypts it
public String decrypt(String given){
// checks the length is 4
if( given.length() == 4){
// for loop that separates each digit, turns into a integer
for(int i =0; i <= 3; i++){
num[i] = Integer.parseInt(Character.toString(given.charAt(i)));
}
//Switches the first digit and thrid digit;
changeO = num[2];
num[2]=num[0];
num[0]= changeO;
//Switches the second and fouth digit
changeT = num[3];
num[3]=num[1];
num[1]=changeT;
// reverses the encryption
for(int i =0; i <= 3; i++){
num[i] = (num[i]+3)%10 ;
}
//turns the digits to String and adds them together
dycNum = new String();
for(int j =0; j <= 3; j++){
dycNum = dycNum + (Integer.toString(num[j]));
}
}
// returns the decrypted number
return dycNum ;
}
}