diff --git a/.idea/libraries/bytedeco_javacv_platform.xml b/.idea/libraries/bytedeco_javacv_platform.xml
index 9fa3834..53085a2 100644
--- a/.idea/libraries/bytedeco_javacv_platform.xml
+++ b/.idea/libraries/bytedeco_javacv_platform.xml
@@ -19,9 +19,9 @@
-
+
-
+
diff --git a/databases.json b/databases.json
deleted file mode 100644
index 3f862b5..0000000
--- a/databases.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "esffs": "e4aebaf0f1b173cdf19ae33a5539cc4e52990f37473f6f41623e1a3a346fa713"
-}
\ No newline at end of file
diff --git a/src/Classes/AlgorithmChoice.java b/src/Classes/AlgorithmChoice.java
new file mode 100644
index 0000000..2bcd9a7
--- /dev/null
+++ b/src/Classes/AlgorithmChoice.java
@@ -0,0 +1,72 @@
+package Classes;
+
+import Classes.Enigma.Enigma; // Import the Enigma class for encryption and decryption
+
+
+public class AlgorithmChoice {
+
+ ////////////// ENCRYPTION ///////////
+ // Methods for each encryption algorithm
+
+ // Encrypts using the Enigma encryption algorithm
+ public static String encryptEnigma(String password) {
+ Enigma encryptionBox = new Enigma(); // Create an instance of the Enigma encryption box
+ // Calls the Enigma's encrypt method to encrypt the password
+ return encryptionBox.encrypt(password);
+ }
+
+ // Encrypts using the RC4 algorithm
+ public static String encryptRC4(String password) {
+ RC4 encryptionBox = new RC4(); // Create an instance of the RC4 encryption box
+ String key = "key"; // The encryption key for RC4
+ encryptionBox.init(key); // Initialize the RC4 encryption with the key
+ // Calls the RC4's encrypt method to encrypt the password
+ return encryptionBox.encrypt(password);
+ }
+
+ // Encrypts using the ROT(x) algorithm
+ public static String encryptROT(String password, int x) {
+ // Calls the ROTX's encrypt method to perform a ROT(x) shift on the password
+ return ROTX.encryptROT(password, x);
+ }
+
+ // Encrypts using the Vigenère cipher algorithm
+ public static String encryptVigenere(String password, String key) {
+ VigenereAlgo vigenere = new VigenereAlgo();
+ vigenere.setKey(key);
+ return vigenere.encrypt(password);
+ }
+
+ /////////// DECRYPTION ///////////
+ // Methods for each decryption algorithm
+
+ // Decrypts using the Enigma decryption algorithm
+ public static String decryptEnigma(String encryptedMessage) {
+ Enigma decryptionBox = new Enigma(); // Create an instance of the Enigma decryption box
+ // Calls the Enigma's decrypt method to decrypt the encrypted message
+ return decryptionBox.decrypt(encryptedMessage);
+ }
+
+ // Decrypts using the RC4 algorithm
+ public static String decryptRC4(String encryptedMessage) {
+ // Create an instance of the RC4 decryption box
+ RC4 decryptionBox = new RC4();
+ String key = "key"; // The decryption key for RC4
+ decryptionBox.init(key); // Initialize the RC4 decryption with the key
+ // Calls the RC4's decrypt method to decrypt the encrypted message
+ return decryptionBox.decrypt(encryptedMessage);
+ }
+
+ // Decrypts using the ROT(x) algorithm
+ public static String decryptROT(String input, int x) {
+ // Calls the ROTX's decrypt method to reverse the ROT(x) shift on the input
+ return ROTX.decryptROT(input, x);
+ }
+
+ // Decrypts using the Vigenère cipher algorithm
+ public static String decryptVigenere(String encryptedMessage, String key) {
+ VigenereAlgo vigenere = new VigenereAlgo();
+ vigenere.setKey(key);
+ return vigenere.decrypt(encryptedMessage);
+ }
+}
diff --git a/src/Classes/Database.java b/src/Classes/Database.java
new file mode 100644
index 0000000..acecc70
--- /dev/null
+++ b/src/Classes/Database.java
@@ -0,0 +1,18 @@
+package Classes;
+
+public class Database{
+ private final String hashedPassword;
+ private final String databaseName;
+ private final String encryptionMode;
+
+
+ public Database (String databaseName, String hashedPassword, String encryptionMode) {
+ this.databaseName = databaseName;
+ this.hashedPassword = hashedPassword;
+ this.encryptionMode = encryptionMode;
+ }
+
+
+
+
+}
diff --git a/src/Classes/DatabasesManager.java b/src/Classes/DatabasesManager.java
index 284d52f..f82c82b 100644
--- a/src/Classes/DatabasesManager.java
+++ b/src/Classes/DatabasesManager.java
@@ -13,45 +13,97 @@
import java.util.Map;
public class DatabasesManager {
- private final File databasesFile;
- private final Map databases;
- Sha256 sha256 = new Sha256();
+ private final File databasesFile; // The file where the databases and their passwords are stored
+ private final Map databases; // A map holding the database names as keys and their info as values
+ private final Sha256 sha256 = new Sha256();
+
public DatabasesManager(File databasesFile) {
this.databasesFile = databasesFile;
- this.databases = loadDatabases();
+ this.databases = new HashMap<>(); // Initialize the map before the try-catch block
+ if (!databasesFile.exists()) {
+ try {
+ databasesFile.createNewFile();
+ saveDatabases(); // Sauvegarder une base de données vide
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ } else {
+ this.databases.putAll(loadDatabases());
+ }
}
public boolean verifyDatabase(String dbName, String password) {
+ DatabaseInfo dbInfo = databases.get(dbName);
+ if (dbInfo == null) {
+ return false;
+ }
String hashedPassword = sha256.calculateHash(password);
- return databases.containsKey(dbName) && databases.get(dbName).equals(hashedPassword);
+ return hashedPassword.equals(dbInfo.getHashedPassword());
}
- public void createDatabase(String dbName, String password) {
- if (databases.containsKey(dbName)) {
- throw new IllegalArgumentException("Database already exists.");
- }
+ public void createDatabase(String dbName, String password, String algorithm) {
String hashedPassword = sha256.calculateHash(password);
- databases.put(dbName, hashedPassword);
+ DatabaseInfo dbInfo = new DatabaseInfo(hashedPassword, algorithm);
+ databases.put(dbName, dbInfo);
saveDatabases();
}
- public Map loadDatabases() {
- if (!databasesFile.exists()) return new HashMap<>();
+ public Map loadDatabases() {
+ if (!databasesFile.exists()) {
+ return new HashMap<>();
+ }
try (FileReader reader = new FileReader(databasesFile)) {
- Gson gson = new Gson();
- Type type = new TypeToken