diff --git a/bin/main.out b/bin/main.out
index fc04ed99ca3cd776d3f03353cda79076af2ae29c..d031f719f330283481cb2a8d0d6887b5f778f288 100755
Binary files a/bin/main.out and b/bin/main.out differ
diff --git a/src/.main.ml.swo b/src/.main.ml.swo
deleted file mode 100644
index b1b4e60b167324d7b344cb5de77ee61e4f144260..0000000000000000000000000000000000000000
Binary files a/src/.main.ml.swo and /dev/null differ
diff --git a/src/.main.ml.swp b/src/.main.ml.swp
deleted file mode 100644
index 3d7974d031461db160c1b5f4e2efd87ccd974c68..0000000000000000000000000000000000000000
Binary files a/src/.main.ml.swp and /dev/null differ
diff --git a/src/main.cmi b/src/main.cmi
index 2db95aff844eaf7039eb18c9dbea3c5d665fd9c0..ca9d167290b5378a236827fa2383fbb97b1b0139 100644
Binary files a/src/main.cmi and b/src/main.cmi differ
diff --git a/src/main.cmx b/src/main.cmx
index 5984df0393b355fe8ff75d560c0366b7ffeb88cc..3c05d0a00ce5ef285a7a4f3898e4045d3a7c55bd 100644
Binary files a/src/main.cmx and b/src/main.cmx differ
diff --git a/src/main.ml b/src/main.ml
index 42c259a92ecd5e9dbf02f690de0e549345294515..207ed6304c44f19a9befbe44b38a521e40bf9b87 100644
--- a/src/main.ml
+++ b/src/main.ml
@@ -43,11 +43,12 @@ let rec tourner c n roue =
         else if c='P' then List.rev (tourner 'N' n (List.rev roue))
         else roue;;
 
-(*[char_to_index i a r] cherche récursivement l'indice du charactère a dans la roue r*)
-exception BadCharacter of char;;
+(*[char_to_index i a r] cherche récursivement l'indice du charactère a dans la roue r
+ * i doit être 0 pour que ça marche*)
+exception BadCharacter;;
 let rec char_to_index i a r= 
     match r with 
-        | [] -> raise (BadCharacter a)
+        | [] -> raise BadCharacter
         | e::l -> if a = e then i
                   else char_to_index (i+1) a l;;  
 
@@ -62,18 +63,77 @@ let translate c roue =
 exception InputVide;;
 let rec commande (i,l) roue = match l with
     | [] -> ""
-    | e::r -> let (c,n) = translate e roue in
-    String.concat "" (c::(commande (i,r) (tourner c.[0] n roue))::[]);;
+    | e::r -> let (s,n) = translate e roue in
+    String.concat "" (s::(commande (i,r) (tourner s.[0] n roue))::[]);;
 
+(*Résultat de la phase 1*)
+let input=parse_input();;
+let com = commande input roue;;
+print_string (com);;
 
-print_string (commande (parse_input()) roue);;
+(************************************************************Début de la phase 2************************************************************)
 
+(*[temps_lettre l] retourne le temps necessaire pour l'emission de la commmande partielle l*)
 let temps_lettre l = 
     if (l='N' || l='P') then 3
     else if l='S' then 1
     else if l='E' then 5
     else 0;;
-(*
-let temps_commande c = 
-    let liste = split_string c in 
-  *)       
+
+(*[temps_commande s] retourne le temps necessaire à l'emission de la commande complète s*)
+let temps_commande s = 
+    let liste_char = split_string s in 
+    let rec tps l = match l with 
+        | [] -> 0
+        | e::r -> temps_lettre e + tps r
+    in
+    tps liste_char;;
+
+(*test temps d'execution*)
+Printf.printf "\n %d s\n" (temps_commande com);;
+
+let liste_roues=roue::[]
+
+
+(*[make_liste_index l c] renvoie la liste des indices où se trouve le charactère c dans chaque roue de l*)
+let rec make_liste_index l c = match l with
+    | [] -> []
+    | e::r -> (char_to_index 0 c e)::(make_liste_index r c);; 
+
+
+(*[quelle_roue l c] renvoi l'indice de la roue (dans la liste de roues l) avec laquelle il est plus rapide de traduire c*)
+let quelle_roue l c =
+    (*i doit être 0 lors du premier appel*)
+    let rec index_min m n i r =  match r with
+        | [] -> n
+        | e::t -> if e < 14 then (if e < m then (index_min e i (i+1) t) else index_min m n (i+1) t)
+                  else (if 27-e < m then (index_min (27-e) i (i+1) t) else index_min m n (i+1) t)
+    in 
+    index_min (char_to_index 0 c roue) 0 (List.length l) (make_liste_index l c);;
+
+
+(*[tourner_list m c n i l] tourne n fois dans le sens de c la roue d'indice i dans la liste de roues l*)
+let rec tourner_list c n i l = 
+    if i >= (List.length l) then List.append l (roue::[])
+    else match l with
+        | [] -> []
+        | e::t -> if i = 0 then  (List.append ((tourner c n e)::[]) t)
+        else (List.append (e::[]) (tourner_list c n (i-1) t));;
+
+(*[commande_phase2 (i,l) roue] traduit le message l en commande en selectionnant pour chaque lettre la bonne antenne*)
+let rec commande_phase2 (i,l) liste_roues index_init = match l with
+    | [] -> ""
+    | e::t -> let index = quelle_roue liste_roues e in
+              let r = (if index = (List.length liste_roues) then roue else (List.nth liste_roues index)) in
+              let (s,n) = translate e r in
+              let sres = (if index = index_init then s else (String.concat "" ("S"::(string_of_int index)::s::[])) ) in
+              let new_liste = tourner_list s.[0] n index liste_roues in
+              Printf.printf "%d\n" index;
+              String.concat "" (sres::(commande_phase2 (i,t) new_liste index)::[]);;
+
+(*test commande_phase2*)
+let com2 = commande_phase2 input liste_roues 0;;
+print_string com2;;
+Printf.printf "\n %d s \n" (temps_commande com2);;
+    
+    
diff --git a/src/main.o b/src/main.o
index 2cad6bf53b82815a2b51a3b1df61243e5b7256a0..02c7adb2e5e5f878b7677d9713ceafa1c29005f7 100644
Binary files a/src/main.o and b/src/main.o differ