-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathporta.java
58 lines (49 loc) · 1.94 KB
/
porta.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package willcrack;
import java.util.Scanner;
import java.lang.Math;
public class porta {
String[] letters = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
String letterIndividual = "";
int value;
public porta(String msg, String key) {
// Iterate through the message
for (int i = 0; i < msg.length(); i++) {
letterIndividual = msg.substring(i, i+1);
// Extract the corresponding key letter
char keyLetter = key.charAt(i % key.length());
// Find the corresponding value for the key letter
for (int j = 0; j < letters.length; j++) {
if (keyLetter == letters[j].charAt(0)) {
value = j;
break;
}
}
// Find the corresponding letter for the message letter
for (int j = 0; j < letters.length; j++) {
if (letterIndividual.equals(letters[j])) {
if (j<13) {
System.out.print(letters[(int) (j+Math.floor(value/2)) %13 +13]);
}
if (j>=13) {
System.out.print(letters[(int) (j-Math.floor(value/2)) %13]);
}
break;
}
}
}
System.out.println("");
}
public static void main(String[] args) {
Scanner myObj = new Scanner(System.in);
System.out.println("Enter cipher/plaintext");
System.out.print("Cipher/plaintext: ");
String cipher = myObj.nextLine();
Scanner myObj2 = new Scanner(System.in);
System.out.println("Enter key");
System.out.print("Key: ");
String key = myObj2.nextLine();
// test: olrph, momen
System.out.print("Decoded/Encoded message: ");
porta decode = new porta(cipher, key);
}
}