Skip to content

Commit aca4d20

Browse files
committed
v2.0
1 parent 91b80bc commit aca4d20

File tree

6 files changed

+276
-140
lines changed

6 files changed

+276
-140
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@ hs_err_pid*
2525
target
2626
.idea
2727
dependency-reduced-pom.xml
28+
input
29+
start.bat
30+
encrypt
31+
output

README.md

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,33 @@ Simple lightweight java program that encrypt and decrypt text file using XOR enc
44
## Table of Contents
55

66
1. [Download & Instalation](#download--instalation)
7-
2. [XOR explenation](#what-is-xor)
8-
3. [Contributing](#contributing)
9-
4. [To Do](#to-do)
10-
5. [License](#license)
7+
2. [Usage](#how-to-use-this-app)
8+
3. [XOR explenation](#what-is-xor)
9+
4. [Contributing](#contributing)
10+
5. [To Do](#to-do)
11+
6. [License](#license)
1112

1213

1314
## Download & Instalation
1415
1. Download java 16 [here](https://adoptium.net/temurin/releases/?version=16).
1516
2. Download latest version in [releases](https://github.com/BoyBACKS/XOREncrypt/releases) tab.
16-
3. Open command prompt in folder and run command.
17+
3. Open command prompt in folder and run command below or use `start.bat` file included in zip folder.
1718
```bach
1819
java -jar XOREncrypt-1.0.jar
1920
```
20-
4. Enjoy the encryption program. 😎
21+
4. Put files in folders.
22+
5. Enjoy the encryption program. 😎
23+
24+
## How to use this app
25+
Program will automatically create 3 folders `input`, `encrypt`, `output`.
26+
After starting you can put files inside folders, for encryption put files in `input` folder and encrypted file will pop up in
27+
`encrypt` folder, for decryption put files ex. `fileExtension-xOrƎ-fileName.XORe` in `encrypt` folder and
28+
decrypted file will pop up in `output` folder.
29+
30+
All encryption and decryption processes requiring encryption key word which you can enter or use file `key.properties`,
31+
program will also ask you if you want to save key word in to a file.
32+
33+
For all functions to work correctly you will need a key word that can be stored in `key.properties` file or manually on piece of paper.
2134

2235
## What is XOR
2336
XOR is one of the best encryption that use special key word. The XOR encryption algorithm is an example of symmetric encryption where the same key is used to both encrypt and decrypt a message.
@@ -29,6 +42,8 @@ Pull requests are always welcome. For bigger changes, please open an issue first
2942

3043
## To Do
3144
- [ ] Add gui using JFrame where you can manage everything
45+
- [ ] Multithreading
46+
- [ ] Calculating encryption process
3247

3348
## License
34-
[GNU GPLv3](https://choosealicense.com/licenses/gpl-3.0/)
49+
[GNU GPLv3](https://choosealicense.com/licenses/gpl-3.0/)

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>net.boybacks</groupId>
88
<artifactId>XOREncrypt</artifactId>
9-
<version>1.0</version>
9+
<version>2.0</version>
1010

1111
<properties>
1212
<maven.compiler.source>16</maven.compiler.source>
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package net.boybacks.main;
2+
3+
import java.io.File;
4+
import java.io.FileInputStream;
5+
import java.io.FileOutputStream;
6+
import java.io.IOException;
7+
8+
import static net.boybacks.main.Main.*;
9+
10+
public class Decrypt {
11+
12+
public static void encryptToOutput() throws InterruptedException {
13+
File actual = new File("encrypt\\");
14+
int i = 0;
15+
for( File f : actual.listFiles()){
16+
fileList.add(new File(f.getName()));
17+
System.out.println(f.getName());
18+
fileEncryptNameChanger(i);
19+
i++;
20+
}
21+
if (fileList.isEmpty()) {
22+
System.out.println("[Console Error (Missing Files)] Folder is empty! Put some files to in folder \"encrypt\" to decrypt them \n");
23+
return;
24+
}
25+
i--;
26+
27+
System.out.println("[Console Log (Decryption Start)] Decryption process is about to begin");
28+
Thread.sleep(1000);
29+
decrypt(i);
30+
System.out.println("[Console Log (Decryption Completed)] Decryption process completed");
31+
}
32+
33+
public static void fileEncryptNameChanger(int i) {
34+
String nonsplitedFile = String.valueOf(fileList.get(i));
35+
String[] splitedFile = nonsplitedFile.split("\\.");
36+
String[] splitedFile1 = splitedFile[0].split("(-xOrƎ-)");
37+
String finalsplitedFile = splitedFile1[1] + "." + splitedFile1[0];
38+
splitedFileList.add(new File(finalsplitedFile));
39+
}
40+
41+
public static void decrypt(int i) {
42+
FileInputStream in = null;
43+
FileOutputStream out = null;
44+
for (int a = 0; a <= i; a++) {
45+
try {
46+
in = new FileInputStream("encrypt\\" + fileList.get(a));
47+
out = new FileOutputStream("output\\" + splitedFileList.get(a));
48+
int data = 0;
49+
while ((data = in.read()) != -1) {
50+
out.write(data ^ Main.word.length());
51+
}
52+
} catch (Exception e) {
53+
e.printStackTrace();
54+
} finally {
55+
if (in != null) {
56+
try {
57+
in.close();
58+
} catch (IOException e) {
59+
e.printStackTrace();
60+
}
61+
}
62+
if (out != null) {
63+
try {
64+
out.close();
65+
} catch (IOException e) {
66+
e.printStackTrace();
67+
}
68+
}
69+
}
70+
System.out.println("[Console Log (Decrypted files)] File named \"" + fileList.get(a).getName() + "\" has been decrypted. Progress: " + (a + 1) + "/" + (i + 1));
71+
}
72+
}
73+
74+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package net.boybacks.main;
2+
3+
import java.io.File;
4+
import java.io.FileInputStream;
5+
import java.io.FileOutputStream;
6+
import java.io.IOException;
7+
8+
import static net.boybacks.main.Main.*;
9+
10+
public class Encrypt {
11+
12+
public static void inputToEncrypt() throws InterruptedException {
13+
File actual = new File("input\\");
14+
int i = 0;
15+
for( File f : actual.listFiles()){
16+
fileList.add(new File(f.getName()));
17+
System.out.println(f.getName());
18+
fileInputNameChanger(i);
19+
i++;
20+
}
21+
if (fileList.isEmpty()) {
22+
System.out.println("[Console Error (Missing Files)] Folder is empty! Put some files to in folder \"input\" to encrypt them \n");
23+
return;
24+
}
25+
i--;
26+
27+
System.out.println("[Console Log (Encryption Start)] Encryption process is about to begin");
28+
Thread.sleep(2500);
29+
encrypt(i);
30+
System.out.println("[Console Log (Encryption Completed)] Encryption process completed");
31+
32+
//System.exit(0);
33+
}
34+
35+
public static void fileInputNameChanger(int i) {
36+
String nonsplitedFile = String.valueOf(fileList.get(i));
37+
String[] splitedFile = nonsplitedFile.split("\\.");
38+
String finalsplitedFile = splitedFile[1] + "-xOrƎ-" + splitedFile[0] + ".XORe";
39+
splitedFileList.add(new File(finalsplitedFile));
40+
}
41+
42+
public static void encrypt(int i) {
43+
FileInputStream in = null;
44+
FileOutputStream out = null;
45+
for (int a = 0; a <= i; a++) {
46+
try {
47+
in = new FileInputStream("input\\" + fileList.get(a));
48+
out = new FileOutputStream("encrypt\\" + splitedFileList.get(a));
49+
int data = 0;
50+
while ((data = in.read()) != -1) {
51+
out.write(data ^ Main.word.length());
52+
}
53+
} catch (Exception e) {
54+
e.printStackTrace();
55+
} finally {
56+
if (in != null) {
57+
try {
58+
in.close();
59+
} catch (IOException e) {
60+
e.printStackTrace();
61+
}
62+
}
63+
if (out != null) {
64+
try {
65+
out.close();
66+
} catch (IOException e) {
67+
e.printStackTrace();
68+
}
69+
}
70+
}
71+
System.out.println("[Console Log (Encrypted files)] File named \"" + fileList.get(a).getName() + "\" has been encrypted. Progress: " + (a + 1) + "/" + (i + 1));
72+
}
73+
}
74+
}

0 commit comments

Comments
 (0)