Skip to content

Commit a030383

Browse files
authored
Intitial Files
All this program can do currently is encrypt with an Ceaser Cypher. More encryption techniques and decryption will needs to be added in later.
1 parent 5f06d3e commit a030383

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed

Encrypter.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package base;
2+
3+
// Encrypts the data using ceaser cypher. This will have to be updated to PGP later down the road for better encryption.
4+
// The encryption code is from https://rosettacode.org/wiki/Caesar_cipher#Java
5+
public class Encrypter {
6+
7+
public static String decode(String enc, int offset) {
8+
return encode(enc, 26-offset);
9+
}
10+
11+
public static String encode(String enc, int offset) {
12+
offset = offset % 26 + 26;
13+
StringBuilder encoded = new StringBuilder();
14+
for (char i : enc.toCharArray()) {
15+
if (Character.isLetter(i)) {
16+
if (Character.isUpperCase(i)) {
17+
encoded.append((char) ('A' + (i - 'A' + offset) % 26 ));
18+
} else {
19+
encoded.append((char) ('a' + (i - 'a' + offset) % 26 ));
20+
}
21+
} else {
22+
encoded.append(i);
23+
}
24+
}
25+
return encoded.toString();
26+
}
27+
28+
}

Main.java

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package base;
2+
import java.util.Scanner;
3+
import java.util.Random;
4+
5+
public class Main {
6+
7+
8+
public static void main(String[] args) {
9+
10+
// create a new scanner with the specified String Object
11+
Scanner scanner = new Scanner(System.in);
12+
13+
//Welcome Text and makes an line with no text to seperate the actual encryption/decryption
14+
System.out.println("SafeFile 2018 Java Version");
15+
System.out.println("Liscenced with Apache Liscence, Version 2.0");
16+
System.out.println();
17+
18+
//Check if user wants to encrypt or decrypt
19+
//DECRYPT HAS NOT BEEN ADDED IN SO CODE IS COMMENTED OUT
20+
//System.out.println("Would you like to Encrypt or Decrypt (Select one in the same spelling)");
21+
// String EorD = scanner.next();
22+
23+
//if (EorD.equals("Encrypt")) {
24+
25+
Scanner scanner1 = new Scanner(System.in);
26+
27+
//Check how the user wants to encrypt
28+
System.out.println("How Would You Like to Encrypt? - Available Currently: Ceaser Cypher");
29+
System.out.println("For Ceaser Cypher, enter Ceaser"); //More would be added in as more encryption ways are added into the program
30+
31+
String howE = scanner.next();
32+
33+
if (howE.equals("Ceaser")) {
34+
35+
System.out.println("What is the text you would like to encrypt?");
36+
String textE = scanner1.next();
37+
38+
System.out.println("What is the offset for the Ceaser Cypher?");
39+
String numE = scanner1.next();
40+
41+
int numEi = Integer.parseInt(numE);
42+
43+
String encrypted = Encrypter.encode(textE, numEi);
44+
45+
System.out.println("Below is encrypted Text with Ceaser Cypher, offset of " + numE);
46+
System.out.println(encrypted);
47+
48+
// close the scanner
49+
scanner1.close();
50+
scanner.close();
51+
52+
}
53+
//}
54+
55+
}
56+
//else if (EorD.equals("Decrypt")){
57+
58+
//Asks the user how they want to decrypt
59+
//System.out.println("How Would You Like to Decrypt? - Available Currently: Ceaser Cypher");
60+
//String howD = scanner.next();
61+
62+
//if(howD.equals("Ceaser Cypher")) {
63+
64+
//Asks user the text and offset they want to use to decrypt the ceaser cypher
65+
//System.out.println("What is the text you would like to decrypt?");
66+
// String textD = scanner.next();
67+
68+
//System.out.println("What is the offset for the Ceaser Cypher?");
69+
//String numD = scanner.next();
70+
71+
//int numDi = Integer.parseInt(numD);
72+
73+
//String decrypted = Encrypter.encode(textD, numDi);
74+
75+
//System.out.println(decrypted);
76+
77+
//System.out.println("please close and open the application again if you want to do another calculation");
78+
79+
80+
//}
81+
82+
83+
84+
//}
85+
86+
}

0 commit comments

Comments
 (0)