-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogicEncode.java
More file actions
79 lines (72 loc) · 1.68 KB
/
LogicEncode.java
File metadata and controls
79 lines (72 loc) · 1.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
/**
* This class encodes the message that is passed in
*
*/
public class LogicEncode {
// String message that is passed in
private String string;
// Password that is passed in
private int password;
/**
* Constructor
*
* @param stringPut
* @param pass
*/
public LogicEncode(String stringPut, int pass) {
this.string = stringPut;
password = pass;
}
/**
* Transfers the string message to a char array
*
* @param str
* @return
*/
private char[] stringToChar(String str) {
char[] c = str.toCharArray();
return c;
}
/**
* Transfers the char array to an integer array of decimals
*
* @param charA
* @return
*/
private int[] charToDecimal(char[] charA) {
int[] decimal = new int[charA.length];
// int[] decimal = new int[charA.length];
for (int i = 0; i < charA.length; i++) {
decimal[i] = Character.codePointAt(charA, i);
// System.out.println(decimal[i]);
}
// System.out.println(Arrays.toString(decimal));
return decimal;
}
/**
* Use an algorithm to change the decimal array
*
* @param originalDecimal
* @param pass
* @return
*/
private int[] convertDecimal(int[] originalDecimal, int pass) {
int newpass = pass % 50;
int[] newDecimal = originalDecimal;
for (int i = 0; i < originalDecimal.length; i++) {
newDecimal[i] = newDecimal[i] + 10 * newpass;
}
// System.out.println(Arrays.toString(newDecimal));
return newDecimal;
}
/**
* Use the new decimal array to get codes
*
* @return
*/
public int[] getEmoji() {
char[] a = stringToChar(string);
int[] b = charToDecimal(a);
return convertDecimal(b, password);
}
}