diff --git a/DEV 3.2/TP08/Authentification/Authentification.java b/DEV 3.2/TP08/Authentification/Authentification.java new file mode 100644 index 0000000..ed7550d --- /dev/null +++ b/DEV 3.2/TP08/Authentification/Authentification.java @@ -0,0 +1,61 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.HashMap; +import java.util.Map; +import java.util.TreeMap; + +public class Authentification { + public static void main(String[] args) { + Map loginMap = new TreeMap<>(); + + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + try { + while (true) { + String command = br.readLine(); + String[] cargs = command.split(" "); + + switch (cargs[0].toLowerCase()) { + case "add": + if (loginMap.containsKey(cargs[1])) { + System.err.println("Utilisateur \"" + cargs[1] + "\" déjà existant."); + } else { + loginMap.put(cargs[1], cargs[2]); + System.out.println("Utilisateur \"" + cargs[1] + "\" ajouté."); + } + break; + + case "auth": + if (loginMap.containsKey(cargs[1])) { + if (loginMap.get(cargs[1]).compareTo(cargs[2]) == 0) { + System.out.println("Utilisateur \"" + cargs[1] + "\" reconnu."); + } else { + System.err.println("Utilisateur \"" + cargs[1] + "\" non reconnu."); + } + } else { + System.err.println("Utilisateur \"" + cargs[1] + "\" non reconnu."); + } + break; + + case "del": + if (loginMap.containsKey(cargs[1])) { + loginMap.remove(cargs[1]); + System.out.println("Utilisateur \"" + cargs[1] + "\" retiré."); + } else { + System.err.println("Utilisateur \"" + cargs[1] + "\" non reconnu."); + } + break; + + case "quit": + System.out.println("Au revoir"); + return; + + default: + System.out.println("Commande inconnue"); + } + } + } catch (IOException e) { + System.err.println(e); + } + } +} diff --git a/DEV 3.2/TP08/Authentification/StringComparator.java b/DEV 3.2/TP08/Authentification/StringComparator.java new file mode 100644 index 0000000..b270b99 --- /dev/null +++ b/DEV 3.2/TP08/Authentification/StringComparator.java @@ -0,0 +1,11 @@ +public class StringComparator implements TreeComparator { + + @Override + public int compare(String a, String b) { + int comparing = a.compareTo(b); + + if (comparing == 0) return 0; + return comparing /= Math.abs(comparing); + } + +} diff --git a/DEV 3.2/TP08/Authentification/TreeComparator.java b/DEV 3.2/TP08/Authentification/TreeComparator.java new file mode 100644 index 0000000..9d08685 --- /dev/null +++ b/DEV 3.2/TP08/Authentification/TreeComparator.java @@ -0,0 +1,4 @@ + +public interface TreeComparator { + public int compare(T a, T b); +} diff --git a/DEV 3.2/TP08/Authentification/TreeMap.java b/DEV 3.2/TP08/Authentification/TreeMap.java new file mode 100644 index 0000000..95df077 --- /dev/null +++ b/DEV 3.2/TP08/Authentification/TreeMap.java @@ -0,0 +1,96 @@ +import java.util.Collection; +import java.util.Map; +import java.util.Set; + +public class TreeMap implements Map { + + private TreeNode root; + private TreeComparator comparator; + + public TreeMap() { + + } + + public TreeComparator getComparator() { + return comparator; + } + + public void setComparator(TreeComparator comparator) { + this.comparator = comparator; + } + + @Override + public void clear() { + root = null; + } + + @Override + public boolean containsKey(Object key) { + if (root == null) return false; + else return root.containsKey((K)key); + } + + @Override + public boolean containsValue(Object value) { + return false; + } + + @Override + public Set> entrySet() { + return null; + } + + @Override + public V get(Object key) { + if (root == null) return null; + return root.get((K)key); + } + + @Override + public boolean isEmpty() { + return root == null; + } + + @Override + public Set keySet() { + return null; + } + + @Override + public V put(K key, V value) { + if (root == null) { + root = new TreeNode(this, key, value); + return null; + } + + return root.put(key, value); + } + + @Override + public void putAll(Map m) { + + } + + @Override + public V remove(Object key) { + if (root == null) return null; + else if (comparator.compare(root.getKey(), (K)key) == 0) { + V value = root.getValue(); + root = null; + return value; + } else { + return root.remove((K)key); + } + } + + @Override + public int size() { + return 0; + } + + @Override + public Collection values() { + return null; + } + +} diff --git a/DEV 3.2/TP08/Authentification/TreeNode.java b/DEV 3.2/TP08/Authentification/TreeNode.java new file mode 100644 index 0000000..63355ba --- /dev/null +++ b/DEV 3.2/TP08/Authentification/TreeNode.java @@ -0,0 +1,105 @@ +public class TreeNode { + + private K key; + private V value; + + private TreeMap tree; + private TreeNode sub; + private TreeNode top; + + public TreeNode(TreeMap tree, K key, V value) { + this.key = key; + this.value = value; + } + + public K getKey() { + return key; + } + + public V getValue() { + return value; + } + + public V put(K key, V value) { + int comparison = tree.getComparator().compare(this.key, key); + + if (comparison == -1) { + if (sub == null) sub = new TreeNode(tree, key, value); + else sub.put(key, value); + return null; + } else if (comparison == 0) { + V oldValue = this.value; + this.value = value; + return oldValue; + } else { + if (top == null) top = new TreeNode(tree, key, value); + else top.put(key, value); + return null; + } + } + + public V get(K key) { + int comparison = tree.getComparator().compare(this.key, key); + + if (comparison == -1) { + if (sub == null) return null; + else return sub.get(key); + } else if (comparison == 0) { + return value; + } else { + if (top == null) return null; + else return top.get(key); + } + } + + public boolean containsKey(K key) { + int comparison = tree.getComparator().compare(this.key, key); + + if (comparison == -1) { + if (sub == null) return false; + else return sub.containsKey(key); + } else if (comparison == 0) { + return true; + } else { + if (top == null) return false; + else return top.containsKey(key); + } + } + + public TreeNode getSub() { + return sub; + } + + public TreeNode getTop() { + return top; + } + + public V remove(K key) { + int comparison = tree.getComparator().compare(this.key, key); + + if (comparison == -1) { + if (sub == null) return null; + else { + if (tree.getComparator().compare(key, sub.getKey()) == 0) { + V value = sub.getValue(); + sub = null; + + return value; + } else { + return sub.remove(key); + } + } + } else { + if (top == null) return null; + else { + if (tree.getComparator().compare(key, top.getKey()) == 0) { + V value = top.getValue(); + top = null; + return value; + } else { + return top.remove(key); + } + } + } + } +} diff --git a/DEV 3.2/TP08/Tri/RealComparator.java b/DEV 3.2/TP08/Tri/RealComparator.java new file mode 100644 index 0000000..3abff3b --- /dev/null +++ b/DEV 3.2/TP08/Tri/RealComparator.java @@ -0,0 +1,11 @@ +public class RealComparator implements TreeComparator { + + public RealComparator() {} + + @Override + public int compare(Float a, Float b) { + if (a > b) return 1; + else if (a < b) return -1; + else return 0; + } +} diff --git a/DEV 3.2/TP08/Tri/SearchTree.java b/DEV 3.2/TP08/Tri/SearchTree.java new file mode 100644 index 0000000..919f7f8 --- /dev/null +++ b/DEV 3.2/TP08/Tri/SearchTree.java @@ -0,0 +1,23 @@ +public class SearchTree { + + private TreeNode root; + private TreeComparator comparator; + + public SearchTree(TreeComparator comparator) { + this.comparator = comparator; + } + + public void add(T object) { + if (root != null) root.add(object); + else root = new TreeNode(this, object); + } + + public TreeComparator getComparator() { + return comparator; + } + + @Override + public String toString() { + return root.toString(); + } +} diff --git a/DEV 3.2/TP08/Tri/TreeComparator.java b/DEV 3.2/TP08/Tri/TreeComparator.java new file mode 100644 index 0000000..021b4c7 --- /dev/null +++ b/DEV 3.2/TP08/Tri/TreeComparator.java @@ -0,0 +1,3 @@ +public interface TreeComparator { + public int compare(T a, T b); +} diff --git a/DEV 3.2/TP08/Tri/TreeNode.java b/DEV 3.2/TP08/Tri/TreeNode.java new file mode 100644 index 0000000..912b893 --- /dev/null +++ b/DEV 3.2/TP08/Tri/TreeNode.java @@ -0,0 +1,78 @@ +public class TreeNode { + + private T value; + private TreeNode lesser; + private TreeNode greater; + private SearchTree parentTree; + + public TreeNode(SearchTree parentTree, T object) { + this.parentTree = parentTree; + this.value = object; + } + + public void add(T object) { + switch (parentTree.getComparator().compare(value, object)) { + case -1: + if (lesser != null) lesser.add(object); + else lesser = new TreeNode(parentTree, object); + break; + case 0: + throw new IllegalArgumentException("Value already in tree"); + case 1: + if (greater != null) greater.add(object); + else greater = new TreeNode(parentTree, object); + break; + } + } + + public void remove(T object) { + if (lesser.getValue().equals(object)) { + T a = lesser.getLesser().getValue(); + T b = lesser.getGreater().getValue(); + parentTree.add(a); + parentTree.add(b); + lesser = null; + } else if (greater.getValue().equals(object)) { + T a = greater.getLesser().getValue(); + T b = greater.getGreater().getValue(); + parentTree.add(a); + parentTree.add(b); + greater = null; + } else { + switch (parentTree.getComparator().compare(value, object)) { + case -1: + if (lesser != null) lesser.remove(object); + else return; + break; + case 0: + throw new IllegalStateException("Something fucked up"); + case 1: + if (greater != null) greater.remove(object); + else return; + break; + } + } + } + + public T getValue() { + return value; + } + + public TreeNode getLesser() { + return lesser; + } + + public TreeNode getGreater() { + return greater; + } + + @Override + public String toString() { + String str = ""; + if (greater != null) str += greater.toString(); + str += value.toString() + " "; + if (lesser != null) str += lesser.toString() + " "; + + return str; + } +} diff --git a/DEV 3.2/TP08/Tri/Tri.java b/DEV 3.2/TP08/Tri/Tri.java new file mode 100644 index 0000000..1fe0e74 --- /dev/null +++ b/DEV 3.2/TP08/Tri/Tri.java @@ -0,0 +1,16 @@ +/** + * Tri + */ +public class Tri { + + public static void main(String[] args) { + SearchTree t = new SearchTree<>(new RealComparator()); + + for (String arg : args) { + Float f = Float.parseFloat(arg); + t.add(f); + } + + System.out.println(t.toString()); + } +} \ No newline at end of file diff --git a/DEV 4.4/TP01/ex1.c b/DEV 4.4/TP01/ex1.c new file mode 100644 index 0000000..17733d9 --- /dev/null +++ b/DEV 4.4/TP01/ex1.c @@ -0,0 +1,117 @@ +#include +#include +#include + +void encrypt (uint32_t* v, uint32_t* k) +{ + uint32_t v0=v[0], v1=v[1], sum=0, i; /* set up */ + uint32_t delta=0x9e3779b9; /* a key schedule constant */ + uint32_t k0=k[0], k1=k[1], k2=k[2], k3=k[3]; /* cache key */ + for (i=0; i < 32; i++) { /* basic cycle start */ + sum += delta; + v0 += ((v1<<4) + k0) ^ (v1 + sum) ^ ((v1>>5) + k1); + v1 += ((v0<<4) + k2) ^ (v0 + sum) ^ ((v0>>5) + k3); + } /* end cycle */ + v[0]=v0; v[1]=v1; +} + +void decrypt (uint32_t* v, uint32_t* k) +{ + uint32_t delta=0x9e3779b9; + uint32_t v0=v[0], v1=v[1], sum=(delta << 5), i; + uint32_t k0=k[0], k1=k[1], k2=k[2], k3=k[3]; + + for (i=0; i < 32; i++) { + v1 -= ((v0<<4) + k2) ^ (v0 + sum) ^ ((v0>>5) + k3); + v0 -= ((v1<<4) + k0) ^ (v1 + sum) ^ ((v1>>5) + k1); + sum -= delta; + } + v[0]=v0; v[1]=v1; +} + + + +int treatFile(FILE* input, FILE* output, uint32_t key[4], char method) { + + int n; + uint32_t buffer[2]; + int m; + + //TODO: Padding management + + switch (method) + { + case 'd': + while ((n = fread(buffer, 4, 2, input)) > 0) { + decrypt(buffer, key); + + if (( m = fwrite(buffer, 4, 2, output)) != 2) { + return 1; + } + } + break; + + case 'e': + while ((n = fread(buffer, 4, 2, input)) > 0) { + encrypt(buffer, key); + + if (( m = fwrite(buffer, 4, 2, output)) != 2) { + return 1; + } + } + break; + } + + return 0; +} + +int main(int argc, char const *argv[]) +{ + if (argc < 5) { + printf("Usage: %s e/d \n", argv[0]); + return 0; + } + + if (!strcmp(argv[1], "-d") && !strcmp(argv[1], "-e")) { + printf("Invalid operation, use either e(ncrypt) or d(ecrypt)."); + return 1; + } + + uint32_t key[4]; + FILE* keyFile = fopen(argv[2], "r"); + if (!keyFile) { + printf("Unable to open key file.\n"); + return 1; + } + + if (fread(key, 4, 4, keyFile) != 4) { + printf("Invalid key length.\n"); + return 1; + } + + fclose(keyFile); + + FILE* input = fopen(argv[3], "r"); + if (!input) { + printf("Unable to open input file.\n"); + return 1; + } + + FILE* output = fopen(argv[4], "w"); + if (!output) { + printf("Unable to open output file.\n"); + return 1; + } + + int failure = treatFile(input, output, key, argv[1][1]); + + fclose(input); + fclose(output); + + if (failure) { + printf("Error during processing.\n"); + return 2; + } + + return 0; +} \ No newline at end of file diff --git a/DEV 4.4/TP01/fichier.crypt b/DEV 4.4/TP01/fichier.crypt new file mode 100644 index 0000000..577288c Binary files /dev/null and b/DEV 4.4/TP01/fichier.crypt differ diff --git a/DEV 4.4/TP01/key1.k b/DEV 4.4/TP01/key1.k new file mode 100644 index 0000000..7fc6ef4 --- /dev/null +++ b/DEV 4.4/TP01/key1.k @@ -0,0 +1 @@ +÷Nà {q2‘*:¬¨œÇmfU#© `í±Å?&Q3 \ No newline at end of file diff --git a/DEV 4.4/TP01/test.txt b/DEV 4.4/TP01/test.txt new file mode 100644 index 0000000..1656f92 --- /dev/null +++ b/DEV 4.4/TP01/test.txt @@ -0,0 +1 @@ +abcdefgh \ No newline at end of file diff --git a/DEV-4.5/TP01/Chat-Relative/.gitignore b/DEV-4.5/TP01/Chat-Relative/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/DEV-4.5/TP01/Chat-Relative/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/DEV-4.5/TP01/Chat-Relative/.idea/.gitignore b/DEV-4.5/TP01/Chat-Relative/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/DEV-4.5/TP01/Chat-Relative/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/DEV-4.5/TP01/Chat-Relative/.idea/.name b/DEV-4.5/TP01/Chat-Relative/.idea/.name new file mode 100644 index 0000000..a070a24 --- /dev/null +++ b/DEV-4.5/TP01/Chat-Relative/.idea/.name @@ -0,0 +1 @@ +Chat \ No newline at end of file diff --git a/DEV-4.5/TP01/Chat-Relative/.idea/compiler.xml b/DEV-4.5/TP01/Chat-Relative/.idea/compiler.xml new file mode 100644 index 0000000..fb7f4a8 --- /dev/null +++ b/DEV-4.5/TP01/Chat-Relative/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/DEV-4.5/TP01/Chat-Relative/.idea/gradle.xml b/DEV-4.5/TP01/Chat-Relative/.idea/gradle.xml new file mode 100644 index 0000000..ad32906 --- /dev/null +++ b/DEV-4.5/TP01/Chat-Relative/.idea/gradle.xml @@ -0,0 +1,20 @@ + + + + + + + \ No newline at end of file diff --git a/DEV-4.5/TP01/Chat-Relative/.idea/misc.xml b/DEV-4.5/TP01/Chat-Relative/.idea/misc.xml new file mode 100644 index 0000000..fbdcc4d --- /dev/null +++ b/DEV-4.5/TP01/Chat-Relative/.idea/misc.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/DEV-4.5/TP01/Chat-Relative/.idea/vcs.xml b/DEV-4.5/TP01/Chat-Relative/.idea/vcs.xml new file mode 100644 index 0000000..c2365ab --- /dev/null +++ b/DEV-4.5/TP01/Chat-Relative/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/DEV-4.5/TP01/Chat-Relative/app/.gitignore b/DEV-4.5/TP01/Chat-Relative/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/DEV-4.5/TP01/Chat-Relative/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/DEV-4.5/TP01/Chat-Relative/app/build.gradle b/DEV-4.5/TP01/Chat-Relative/app/build.gradle new file mode 100644 index 0000000..6608f25 --- /dev/null +++ b/DEV-4.5/TP01/Chat-Relative/app/build.gradle @@ -0,0 +1,39 @@ +plugins { + id 'com.android.application' +} + +android { + compileSdk 32 + + defaultConfig { + applicationId "com.example.chat" + minSdk 21 + targetSdk 32 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + buildToolsVersion '33.0.0' +} + +dependencies { + + implementation 'androidx.appcompat:appcompat:1.3.0' + implementation 'com.google.android.material:material:1.4.0' + implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.3' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' +} \ No newline at end of file diff --git a/DEV-4.5/TP01/Chat-Relative/app/proguard-rules.pro b/DEV-4.5/TP01/Chat-Relative/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/DEV-4.5/TP01/Chat-Relative/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/DEV-4.5/TP01/Chat-Relative/app/src/androidTest/java/com/example/chat/ExampleInstrumentedTest.java b/DEV-4.5/TP01/Chat-Relative/app/src/androidTest/java/com/example/chat/ExampleInstrumentedTest.java new file mode 100644 index 0000000..69e9c15 --- /dev/null +++ b/DEV-4.5/TP01/Chat-Relative/app/src/androidTest/java/com/example/chat/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.chat; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.example.chat", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/DEV-4.5/TP01/Chat-Relative/app/src/main/AndroidManifest.xml b/DEV-4.5/TP01/Chat-Relative/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..a485798 --- /dev/null +++ b/DEV-4.5/TP01/Chat-Relative/app/src/main/AndroidManifest.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/DEV-4.5/TP01/Chat-Relative/app/src/main/java/com/example/chat/MainActivity.java b/DEV-4.5/TP01/Chat-Relative/app/src/main/java/com/example/chat/MainActivity.java new file mode 100644 index 0000000..6398d4b --- /dev/null +++ b/DEV-4.5/TP01/Chat-Relative/app/src/main/java/com/example/chat/MainActivity.java @@ -0,0 +1,14 @@ +package com.example.chat; + +import androidx.appcompat.app.AppCompatActivity; + +import android.os.Bundle; + +public class MainActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + } +} \ No newline at end of file diff --git a/DEV-4.5/TP01/Chat-Relative/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/DEV-4.5/TP01/Chat-Relative/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/DEV-4.5/TP01/Chat-Relative/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/DEV-4.5/TP01/Chat-Relative/app/src/main/res/drawable/ic_launcher_background.xml b/DEV-4.5/TP01/Chat-Relative/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/DEV-4.5/TP01/Chat-Relative/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DEV-4.5/TP01/Chat-Relative/app/src/main/res/layout/activity_main.xml b/DEV-4.5/TP01/Chat-Relative/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..bd4ceef --- /dev/null +++ b/DEV-4.5/TP01/Chat-Relative/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,39 @@ + + + + + +