diff --git a/src/avatartranslator/toproverif/AVATAR2ProVerif.java b/src/avatartranslator/toproverif/AVATAR2ProVerif.java
index e9e98331e531787b6eec0ba0d26d85553002a013..d72fd45335f8df19168b0397fc7570ba90d0e407 100755
--- a/src/avatartranslator/toproverif/AVATAR2ProVerif.java
+++ b/src/avatartranslator/toproverif/AVATAR2ProVerif.java
@@ -638,7 +638,7 @@ public class AVATAR2ProVerif implements AvatarTranslator {
                     // ignore if the attribute was already declared
                     if (systemKnowledge.contains (arg)) {
                         CheckingError ce = new CheckingError(CheckingError.BEHAVIOR_ERROR, "Attribute " + arg.getBlock ().getName () + "." + arg.getName () + " already appears in another initial knowledge pragma or is a constant (ignored).");
-                        ce.setTDiagramPanel(((AvatarDesignPanel)(avspec.getReferenceObject())).getAvatarBDPanel());
+                       // ce.setTDiagramPanel(((AvatarDesignPanel)(avspec.getReferenceObject())).getAvatarBDPanel());
                         ce.setTGComponent((TGComponent)pragma.getReferenceObject());
                         warnings.add(ce);
                         continue;
diff --git a/src/dseengine/DSEConfiguration.java b/src/dseengine/DSEConfiguration.java
index ec0ce4b2fe17217cb04975587f1ff70706a30a88..c7ab0144cfeae65fa4f9a67853dbef2d4e14996e 100755
--- a/src/dseengine/DSEConfiguration.java
+++ b/src/dseengine/DSEConfiguration.java
@@ -61,6 +61,8 @@ import dseengine.*;
 
 import myutil.*;
 
+import ui.*;
+import ui.tmldd.*;
 
 //import uppaaldesc.*;
 
@@ -100,10 +102,14 @@ public class DSEConfiguration implements Runnable  {
 	
 	private boolean showSimulatorRawOutput = false;
 	
+	public TMLComponentDesignPanel tmlcdp;
+	public TMLArchiPanel tmlap;
 	
 	private TMLMapping tmap;
 	private TMLModeling tmlm;
 	
+	private TMLModeling stmlm;
+	
 	private boolean optionChanged = true;
 	
 	private int simulationID = 0;
@@ -113,10 +119,18 @@ public class DSEConfiguration implements Runnable  {
 	private int simulationExplorationMinimumCommand = 100;
 	private int simulationExplorationMinimumBranch = 100;
 	
+
 	private int simulationMaxCycles = -1;
 	
 	private int nbOfSimulationThreads = 1;
 	
+	//Security
+	public boolean addSecurity=false;
+	public String encComp="100";
+	public String decComp="100";
+	public String overhead="0";
+	public String nonceSize="0";
+
 	// DSE
 	private int minNbOfCPUs = 1;
 	private int maxNbOfCPUs = 2;
@@ -124,10 +138,11 @@ public class DSEConfiguration implements Runnable  {
 	private int maxNbOfCoresPerCPU = 2;
 	private int nbOfSimulationsPerMapping = 1;
 	private TMLModeling taskModel = null;
+	private TMLModeling secModel = null;
 	private Vector<TMLMapping> mappings;
 	private DSEMappingSimulationResults dsemapresults;
-	
-	
+
+	public MainGUI mainGUI;
 	// Taps
 	private static String[] taps = {"MinSimulationDuration",  "AverageSimulationDuration", 
 	"MaxSimulationDuration", 
@@ -504,7 +519,6 @@ public class DSEConfiguration implements Runnable  {
 		if (ret) {
 			//System.out.println("Format OK");
 			taskModel = tmlts.getTMLModeling();
-			
 			//System.out.println("\n\n*** TML Modeling *** \n");
 			//TMLTextSpecification textspec = new TMLTextSpecification("toto");
 			//String s = textspec.toTextFormat(tmlm);
@@ -656,7 +670,9 @@ public class DSEConfiguration implements Runnable  {
 		}
 		return 0;
 	}
-	
+	public int generateSecMapping(){
+		return 0;
+	}
 	public int generateAndCompileMappingCode(TMLMapping _tmlmap, boolean _debug, boolean _optimize) {
 		
 		// Generating code
@@ -666,7 +682,7 @@ public class DSEConfiguration implements Runnable  {
 			map.generateSystemC(_debug, _optimize);
 			map.saveFile(pathToSimulator, "appmodel");
 		} catch (Exception e) {
-			TraceManager.addDev("SystemC generation failed: " + e + " msg=" + e.getMessage());
+			System.out.println("SystemC generation failed: " + e + " msg=" + e.getMessage());
 			e.printStackTrace();
 			return -1;
 		}
@@ -1295,10 +1311,108 @@ public class DSEConfiguration implements Runnable  {
 			} else {
 				return -1;
 			}
+
+		 if (addSecurity){
+		     System.out.println("ADDING SECURITY TO MAPPING " +(cpt-1));
+		     tmla.tmlap = tmlap;
+		     tmla.setTMLDesignPanel(tmlcdp);
+		     TMLArchiPanel newArch = drawMapping(tmla, "securedMapping"+(cpt-1));
+
+		     //Repeat for secured mapping
+		     TMLMapping secMapping = mainGUI.gtm.autoSecure(mainGUI, "mapping" +(cpt-1),tmla, newArch, encComp, overhead, decComp,true,false);
+
+		     //Run simulations on this mapping
+		     if (generateAndCompileMappingCode(secMapping, _debug, _optimize)  >= 0) {
+			     System.out.println("GENERATING>>>");
+				if (recordResults) {
+					results = new DSESimulationResult();
+					resultsID ++;
+				}
+				
+				//System.out.println("After Current TML Mapping: " + tmla.getSummaryTaskMapping());
+				
+				dsemapresults.addElement("Secured Mapping #" + (cpt-1), results, secMapping);
+				nbOfSimulations = nbOfSimulationsPerMapping;
+				// Executing the simulation
+				String cmd = prepareCommand();
+				String tmp;
+				
+				long t0 = System.currentTimeMillis();
+				
+				while(nbOfSimulations >0) {
+					tmp = putSimulationNbInCommand(cmd, simulationID);
+					TraceManager.addDev("Executing: " + tmp);
+					makeCommand(tmp);
+					
+					if (recordResults) {
+						if (loadSimulationResult(simulationID) <0) {
+							return -1;
+						}
+					}
+					simulationID ++;
+					nbOfSimulations --;
+				}
+			} else {
+				return -1;
+			}
+		    }
 		}	
 		return 0;
 	}
-	
+    public TMLArchiPanel drawMapping(TMLMapping map, String name){
+	Map<HwNode, TGConnectingPoint> connectMap; 
+	Map<HwNode, TMLArchiNode> objMap = new HashMap<HwNode, TMLArchiNode>();
+	int index = mainGUI.createTMLArchitecture(name);
+	TMLArchiPanel archPanel = (TMLArchiPanel) mainGUI.tabs.get(mainGUI.tabs.size()-1);
+	TMLArchiDiagramPanel ap = archPanel.tmlap;
+	TMLArchitecture arch = map.getArch();
+	ArrayList<HwNode> hwnodes = arch.getHwNodes();
+	ArrayList<HwLink> hwlinks = arch.getHwLinks();
+	int x=10;
+	int y=10;
+	for (HwNode node: hwnodes){
+	    if (node instanceof HwCPU){
+		TMLArchiCPUNode cpu = new TMLArchiCPUNode(x, y, ap.getMinX(), ap.getMaxX(), ap.getMinY(), ap.getMaxY(), false, null, ap);
+		x+=300;
+		cpu.setName(node.getName());
+		ap.addComponent(cpu, x, y, false, true);
+		objMap.put(node, cpu);
+	    }
+	    else if (node instanceof HwMemory){
+		TMLArchiMemoryNode mem = new TMLArchiMemoryNode(x, y, ap.getMinX(), ap.getMaxX(), ap.getMinY(), ap.getMaxY(), false, null, ap);
+		x+=300;
+		mem.setName(node.getName());
+		ap.addComponent(mem, x, y, false, true);
+		objMap.put(node, mem);
+	    }
+
+	}
+	y = 400;
+	x=10;
+	for (HwNode node:hwnodes){
+	   if (node instanceof HwBus){
+		TMLArchiBUSNode bus = new TMLArchiBUSNode(x, y, ap.getMinX(), ap.getMaxX(), ap.getMinY(), ap.getMaxY(), false, null, ap);
+		x+=300;
+		bus.setName(node.getName());
+		ap.addComponent(bus,x,y,false,true);
+		objMap.put(node,bus);
+	   }
+	}
+	for (HwLink link: hwlinks){
+	    TMLArchiNode n1 = objMap.get(link.bus);
+	    TMLArchiNode n2 = objMap.get(link.hwnode);	
+	    TMLArchiConnectorNode conn = new TMLArchiConnectorNode(x, y, ap.getMinX(), ap.getMaxX(), ap.getMinY(), ap.getMaxY(), false, null, ap, n1.getTGConnectingPointAtIndex(0), n2.getTGConnectingPointAtIndex(0), new Vector());
+	    ap.addComponent(conn,x,y,false,true);
+	}
+	for (TMLTask task:map.getTMLModeling().getTasks()){
+	   HwNode node = map.getHwNodeOf(task);
+	   TMLArchiArtifact art = new TMLArchiArtifact(objMap.get(node).getX(), objMap.get(node).getY(), ap.getMinX(), ap.getMaxX(), ap.getMinY(), ap.getMaxY(), false, objMap.get(node), ap);
+	   ap.addComponent(art,objMap.get(node).getX(),objMap.get(node).getY(),true,true);
+	   art.setFullName(task.getName().split("__")[1], task.getName().split("__")[0]);
+	}
+	ap.repaint();
+	return archPanel;
+    }
 	public void makeCommand(String cmd) {
 		String str = null;
 		BufferedReader proc_in, proc_err;
@@ -1431,7 +1545,7 @@ public class DSEConfiguration implements Runnable  {
 		
 		Vector<TMLMapping> maps = new  Vector<TMLMapping>();
 		
-		for(int cpt=min; cpt<max; cpt++) {
+		for(int cpt=min; cpt<=max; cpt++) {
 			dseID = 0;
 			TraceManager.addDev("Generating mapping for nb of cpu = " + cpt);
 			generateMappings(_tmlm, maps, cpt);
@@ -1546,6 +1660,7 @@ public class DSEConfiguration implements Runnable  {
 		dseID ++;
 		
 		maps.add(tmap);
+		
 	}
 	
 	private int nbOfFreeCPUs(CPUWithTasks[] cpus_tasks) {
diff --git a/src/dseengine/DSEMappingSimulationResults.java b/src/dseengine/DSEMappingSimulationResults.java
index f66dfd481af4680c533ad18fccaa25474c85f2b8..488f5bc63bbefa9118357b59051c4b1ff1a5c22e 100755
--- a/src/dseengine/DSEMappingSimulationResults.java
+++ b/src/dseengine/DSEMappingSimulationResults.java
@@ -122,6 +122,9 @@ public class DSEMappingSimulationResults  {
 		int cpt = 0;
 		
 		for(TMLMapping map: maps) {
+			if (comments.get(cpt).contains("Secured")){
+			    sb.append("secured ");
+			}
 			sb.append("#" + cpt + ": " + map.getSummaryTaskMapping() + "\n");
 			cpt ++;
 		}
@@ -587,6 +590,7 @@ public class DSEMappingSimulationResults  {
 		
 		for(DSESimulationResult dserr: results) {
 			valuetmp = dserr.getMinSimulationDuration();
+			System.out.println("MIN SIMULATION DURATION " + valuetmp);
 			if (valuetmp > value) {
 				value = valuetmp;
 				index = currentIndex;
@@ -679,6 +683,7 @@ public class DSEMappingSimulationResults  {
 		
 		for(DSESimulationResult dserr: results) {
 			valuetmp = dserr.getMaxSimulationDuration();
+			System.out.println("MAX SIMULATION DURATION " + valuetmp);
 			if (valuetmp > value) {
 				value = valuetmp;
 				index = currentIndex;
diff --git a/src/tmltranslator/SecurityPattern.java b/src/tmltranslator/SecurityPattern.java
index bad485c3056db2e6847922f1527ca748cac3b685..557d3f5fa0958bac4ce66725ce35c32e1b2d4e57 100644
--- a/src/tmltranslator/SecurityPattern.java
+++ b/src/tmltranslator/SecurityPattern.java
@@ -7,23 +7,31 @@ public String name;
 public String type;
 public int overhead=0;
 public int size=0;
-public int time=0;
+public int encTime=0;
+public int decTime=0;
 public String originTask;
 public AvatarState state1;
 public AvatarState state2;
 public String nonce;
-public SecurityPattern(String _name, String _type, String _overhead, String _size, String _time, String _nonce){
+public String formula;
+public String key;
+public SecurityPattern(String _name, String _type, String _overhead, String _size, String _enctime, String _dectime, String _nonce, String _formula, String _key){
     this.name=_name; 
     this.type=_type;
     this.nonce=_nonce;
+    this.formula=_formula;
+    this.key=_key;
     if (!_overhead.equals("")){
 	this.overhead = Integer.valueOf(_overhead);
     }
     if (!_size.equals("")){
 	this.size = Integer.valueOf(_size);
     }
-    if (!_time.equals("")){
-	this.time=Integer.valueOf(_time);
+    if (!_dectime.equals("")){
+	this.decTime=Integer.valueOf(_dectime);
+    }
+    if (!_enctime.equals("")){
+	this.encTime=Integer.valueOf(_enctime);
     }
 }
 
diff --git a/src/tmltranslator/TMLMapping.java b/src/tmltranslator/TMLMapping.java
index 063039fd7540a20c36ee4e5121e97e9038e66321..356fedbe1194c5cf0c5ff98b094f84e3510b2d12 100755
--- a/src/tmltranslator/TMLMapping.java
+++ b/src/tmltranslator/TMLMapping.java
@@ -385,6 +385,9 @@ public List<String> securityPatterns = new ArrayList<String>();
     public TMLModeling getTMLModeling() {
         return tmlm;
     }
+    public void setTMLModeling(TMLModeling _tmlm){
+	tmlm=_tmlm;
+    }
     public TMLArchitecture getTMLArchitecture() {
         return tmla;
     }
@@ -465,6 +468,13 @@ public List<String> securityPatterns = new ArrayList<String>();
         return onnodes.get(index);
     }
 
+    public void removeTask(TMLTask _task){
+	int index = mappedtasks.indexOf(_task);
+	if (index >-1){
+	    onnodes.remove(index);
+	    mappedtasks.remove(index);
+	}
+    }
     public boolean isAUsedHwNode(HwNode _node) {
         return (onnodes.contains(_node));
     }
diff --git a/src/tmltranslator/toavatar/TML2Avatar.java b/src/tmltranslator/toavatar/TML2Avatar.java
index 919944c48d2d7409a486cae86908d4e53ae7ff49..a48bf82f2a039cd840d7becfed14d9858fd09a39 100644
--- a/src/tmltranslator/toavatar/TML2Avatar.java
+++ b/src/tmltranslator/toavatar/TML2Avatar.java
@@ -656,7 +656,10 @@ public class TML2Avatar {
 		secPatterns.add(ae.securityPattern);
 		block.addAttribute(new AvatarAttribute(ae.securityPattern.name, AvatarType.INTEGER, block, null));
 	    	block.addAttribute(new AvatarAttribute(ae.securityPattern.name+"_encrypted", AvatarType.INTEGER, block, null));
-		if (ae.securityPattern.type.equals("Symmetric Encryption")){
+		if (ae.securityPattern.type.equals("Advanced")){
+		    tran.addAction(ae.securityPattern.formula);
+		}
+		else if (ae.securityPattern.type.equals("Symmetric Encryption")){
 		    if (!ae.securityPattern.nonce.isEmpty()){
 			block.addAttribute(new AvatarAttribute("nonce_"+ae.securityPattern.nonce, AvatarType.INTEGER, block, null));
 			AvatarMethod concat2 = new AvatarMethod("concat2",ae);
@@ -667,30 +670,64 @@ public class TML2Avatar {
 			}
 			tran.addAction(ae.securityPattern.name+"=concat2("+ae.securityPattern.name + ",nonce_"+ae.securityPattern.nonce+")");
 		    }
+		    //Securing a key instead of data
+		    if (!ae.securityPattern.key.isEmpty()){
+			AvatarMethod sencrypt = new AvatarMethod("sencrypt", ae);
+		    	sencrypt.addParameter(block.getAvatarAttributeWithName(ae.securityPattern.key));
+		    	sencrypt.addParameter(block.getAvatarAttributeWithName("key_"+ae.securityPattern.name));
+		    	if (block.getAvatarAttributeWithName(ae.securityPattern.name)!=null && block.getAvatarAttributeWithName("key_"+ae.securityPattern.name)!=null){
+		    	    block.addMethod(sencrypt);
+		    	}
+		    	tran.addAction("encryptedKey_"+ ae.securityPattern.key + " = sencrypt("+ae.securityPattern.key+", key_"+ae.securityPattern.name+")");
 
-		    
-
-		    AvatarMethod sencrypt = new AvatarMethod("sencrypt", ae);
-		    sencrypt.addParameter(block.getAvatarAttributeWithName(ae.securityPattern.name));
-		    sencrypt.addParameter(block.getAvatarAttributeWithName("key_"+ae.securityPattern.name));
-		    if (block.getAvatarAttributeWithName(ae.securityPattern.name)!=null && block.getAvatarAttributeWithName("key_"+ae.securityPattern.name)!=null){
-		    	block.addMethod(sencrypt);
 		    }
-		    tran.addAction(ae.securityPattern.name+"_encrypted = sencrypt("+ae.securityPattern.name+", key_"+ae.securityPattern.name+")");
+		    else {
+		    	AvatarMethod sencrypt = new AvatarMethod("sencrypt", ae);
+		    	sencrypt.addParameter(block.getAvatarAttributeWithName(ae.securityPattern.name));
+		    	sencrypt.addParameter(block.getAvatarAttributeWithName("key_"+ae.securityPattern.name));
+		    	if (block.getAvatarAttributeWithName(ae.securityPattern.name)!=null && block.getAvatarAttributeWithName("key_"+ae.securityPattern.name)!=null){
+		    	    block.addMethod(sencrypt);
+		    	}
+		    	tran.addAction(ae.securityPattern.name+"_encrypted = sencrypt("+ae.securityPattern.name+", key_"+ae.securityPattern.name+")");
+			
 
+		    }
 		    ae.securityPattern.originTask=block.getName();
 		    ae.securityPattern.state1=as;
 		}
 		else if (ae.securityPattern.type.equals("Asymmetric Encryption")){
-
-		    AvatarMethod aencrypt = new AvatarMethod("aencrypt", ae);
-		    aencrypt.addParameter(block.getAvatarAttributeWithName(ae.securityPattern.name));
-		    aencrypt.addParameter(block.getAvatarAttributeWithName("pubKey_"+ae.securityPattern.name));
-		    if (block.getAvatarAttributeWithName("pubKey_"+ae.securityPattern.name)!=null && block.getAvatarAttributeWithName(ae.securityPattern.name)!=null){
-		    	block.addMethod(aencrypt);
+		    System.out.println("AENCRYPT " + ae.securityPattern.name + " " + ae.securityPattern.key);
+		    if (!ae.securityPattern.nonce.isEmpty()){
+			block.addAttribute(new AvatarAttribute("nonce_"+ae.securityPattern.nonce, AvatarType.INTEGER, block, null));
+			AvatarMethod concat2 = new AvatarMethod("concat2",ae);
+			concat2.addParameter(block.getAvatarAttributeWithName(ae.securityPattern.name));
+			concat2.addParameter(block.getAvatarAttributeWithName("nonce_"+ae.securityPattern.nonce));
+			if (block.getAvatarAttributeWithName(ae.securityPattern.name) !=null && block.getAvatarAttributeWithName("nonce_"+ae.securityPattern.nonce)!=null){
+			    block.addMethod(concat2);
+			}
+			tran.addAction(ae.securityPattern.name+"=concat2("+ae.securityPattern.name + ",nonce_"+ae.securityPattern.nonce+")");
 		    }
-		    tran.addAction(ae.securityPattern.name+"_encrypted = aencrypt("+ae.securityPattern.name+", pubKey_"+ae.securityPattern.name+")");
+		    //Securing a key instead of data
+		    if (!ae.securityPattern.key.isEmpty()){
+			AvatarMethod aencrypt = new AvatarMethod("aencrypt", ae);
+			block.addAttribute(new AvatarAttribute("encryptedKey_"+ae.securityPattern.key, AvatarType.INTEGER, block,null));
+		    	aencrypt.addParameter(block.getAvatarAttributeWithName(ae.securityPattern.key));
+		    	aencrypt.addParameter(block.getAvatarAttributeWithName("pubKey_"+ae.securityPattern.name));
+		    	if (block.getAvatarAttributeWithName(ae.securityPattern.key)!=null && block.getAvatarAttributeWithName("key_"+ae.securityPattern.name)!=null){
+		    	    block.addMethod(aencrypt);
+		    	}
+		    	tran.addAction("encryptedKey_"+ ae.securityPattern.key + " = aencrypt("+ae.securityPattern.key+", pubKey_"+ae.securityPattern.name+")");
 
+		    }
+		    else {
+		    	AvatarMethod aencrypt = new AvatarMethod("aencrypt", ae);
+		    	aencrypt.addParameter(block.getAvatarAttributeWithName(ae.securityPattern.name));
+		    	aencrypt.addParameter(block.getAvatarAttributeWithName("pubKey_"+ae.securityPattern.name));
+		    	if (block.getAvatarAttributeWithName("pubKey_"+ae.securityPattern.name)!=null && block.getAvatarAttributeWithName(ae.securityPattern.name)!=null){
+		     	    block.addMethod(aencrypt);
+		    	}
+		    	tran.addAction(ae.securityPattern.name+"_encrypted = aencrypt("+ae.securityPattern.name+", pubKey_"+ae.securityPattern.name+")");
+		    }
 		    ae.securityPattern.originTask=block.getName();
 		    ae.securityPattern.state1=as;
 		}
@@ -726,14 +763,28 @@ public class TML2Avatar {
 		block.addAttribute(new AvatarAttribute(ae.securityPattern.name+"_encrypted", AvatarType.INTEGER, block, null));
 		if (ae.securityPattern.type.equals("Symmetric Encryption")){
 
+		    if (ae.securityPattern.key.isEmpty()){
+		    	AvatarMethod sdecrypt = new AvatarMethod("sdecrypt", ae);
+		    	sdecrypt.addParameter(block.getAvatarAttributeWithName(ae.securityPattern.name+"_encrypted"));
+		    	sdecrypt.addParameter(block.getAvatarAttributeWithName("key_"+ae.securityPattern.name));
+		    	if (block.getAvatarAttributeWithName(ae.securityPattern.name+"_encrypted")!=null && block.getAvatarAttributeWithName("key_"+ae.securityPattern.name)!=null){
+		            block.addMethod(sdecrypt);
+		    	}
+		    	tran.addAction(ae.securityPattern.name+" = sdecrypt("+ae.securityPattern.name+"_encrypted, key_"+ae.securityPattern.name+")");
+
+		    }
+		    else {
+		    	AvatarMethod sdecrypt = new AvatarMethod("sdecrypt", ae);
+		    	sdecrypt.addParameter(block.getAvatarAttributeWithName("encryptedKey_"+ae.securityPattern.key));
+			block.addAttribute(new AvatarAttribute("key_"+ae.securityPattern.key, AvatarType.INTEGER, block,null));
+		    	sdecrypt.addParameter(block.getAvatarAttributeWithName("key_"+ae.securityPattern.key));
+		    	if (block.getAvatarAttributeWithName("encryptedKey_"+ae.securityPattern.key)!=null && block.getAvatarAttributeWithName("key_"+ae.securityPattern.name)!=null){
+		            block.addMethod(sdecrypt);
+		    	}
+		    	tran.addAction(ae.securityPattern.key+" = sdecrypt(encryptedKey_"+ae.securityPattern.key+", key_"+ae.securityPattern.name+")");
 
-		    AvatarMethod sdecrypt = new AvatarMethod("sdecrypt", ae);
-		    sdecrypt.addParameter(block.getAvatarAttributeWithName(ae.securityPattern.name+"_encrypted"));
-		    sdecrypt.addParameter(block.getAvatarAttributeWithName("key_"+ae.securityPattern.name));
-		    if (block.getAvatarAttributeWithName(ae.securityPattern.name+"_encrypted")!=null && block.getAvatarAttributeWithName("key_"+ae.securityPattern.name)!=null){
-		        block.addMethod(sdecrypt);
 		    }
-		    tran.addAction(ae.securityPattern.name+" = sdecrypt("+ae.securityPattern.name+"_encrypted, key_"+ae.securityPattern.name+")");
+		
 		    elementList.add(as);
 	    	    elementList.add(tran);
 		    as.addNext(tran);
@@ -780,17 +831,49 @@ public class TML2Avatar {
 		else if (ae.securityPattern.type.equals("Asymmetric Encryption")){
 
 		    AvatarMethod adecrypt = new AvatarMethod("adecrypt", ae);
-		    adecrypt.addParameter(block.getAvatarAttributeWithName(ae.securityPattern.name+"_encrypted"));
 
-		//    avspec.addPragma(new AvatarPragmaPrivatePublicKey("PrivPubKey" + block.getName(), null, privKey, pubKey));
-		    adecrypt.addParameter(block.getAvatarAttributeWithName("privKey_"+ae.securityPattern.name));
-		    if (block.getAvatarAttributeWithName(ae.securityPattern.name+"_encrypted")!=null && block.getAvatarAttributeWithName("privKey_"+ae.securityPattern.name)!= null){
-		    	block.addMethod(adecrypt);
+		    if (ae.securityPattern.key.isEmpty()){
+			block.addAttribute(new AvatarAttribute(ae.securityPattern.name+"_encrypted",AvatarType.INTEGER,block,null));
+			block.addAttribute(new AvatarAttribute(ae.securityPattern.name,AvatarType.INTEGER,block,null));
+		    	adecrypt.addParameter(block.getAvatarAttributeWithName(ae.securityPattern.name+"_encrypted"));
+		    	adecrypt.addParameter(block.getAvatarAttributeWithName("privKey_"+ae.securityPattern.name));
+		    	if (block.getAvatarAttributeWithName(ae.securityPattern.name+"_encrypted")!=null && block.getAvatarAttributeWithName("privKey_"+ae.securityPattern.name)!= null){
+		    	    block.addMethod(adecrypt);
+		    	}
+		    	tran.addAction(ae.securityPattern.name+" = adecrypt("+ae.securityPattern.name+"_encrypted, privKey_"+ae.securityPattern.name+")");
+		    }
+		    else {
+			block.addAttribute(new AvatarAttribute("encryptedKey_"+ae.securityPattern.key,AvatarType.INTEGER,block,null));
+			adecrypt.addParameter(block.getAvatarAttributeWithName("encryptedKey_"+ae.securityPattern.key));
+		    	adecrypt.addParameter(block.getAvatarAttributeWithName("privKey_"+ae.securityPattern.name));
+			block.addAttribute(new AvatarAttribute("key_"+ae.securityPattern.key, AvatarType.INTEGER, block,null));
+		    	if (block.getAvatarAttributeWithName("encryptedKey_"+ae.securityPattern.key)!=null && block.getAvatarAttributeWithName("privKey_"+ae.securityPattern.name)!= null){
+		    	    block.addMethod(adecrypt);
+		    	}
+		    	tran.addAction("key_"+ae.securityPattern.key+" = adecrypt(encryptedKey_"+ae.securityPattern.key+", privKey_"+ae.securityPattern.name+")");
 		    }
-		    tran.addAction(ae.securityPattern.name+" = adecrypt("+ae.securityPattern.name+"_encrypted, privKey_"+ae.securityPattern.name+")");
 		    elementList.add(as);
 	    	    elementList.add(tran);
 		    as.addNext(tran);
+		    if (!ae.securityPattern.nonce.isEmpty()){
+			block.addAttribute(new AvatarAttribute("testnonce_"+ae.securityPattern.nonce, AvatarType.INTEGER, block, null));
+			AvatarMethod get2 = new AvatarMethod("get2",ae);
+			get2.addParameter(block.getAvatarAttributeWithName(ae.securityPattern.name));
+			get2.addParameter(block.getAvatarAttributeWithName(ae.securityPattern.name));
+			get2.addParameter(block.getAvatarAttributeWithName("testnonce_"+ae.securityPattern.nonce));
+			if (block.getAvatarAttributeWithName(ae.securityPattern.name)!=null && block.getAvatarAttributeWithName(ae.securityPattern.name)!=null && block.getAvatarAttributeWithName("testnonce_"+ae.securityPattern.nonce)!=null) {
+			    block.addMethod(get2);
+			}
+			tran.addAction("get2("+ae.securityPattern.name + ","+ae.securityPattern.name+",testnonce_"+ae.securityPattern.nonce+")");
+
+			AvatarState guardState = new AvatarState(ae.getName()+"_guarded", ae.getReferenceObject());
+			tran.addNext(guardState);
+			tran=new AvatarTransition(block, "__guard_"+ae.getName(), ae.getReferenceObject());
+			guardState.addNext(tran);
+
+			tran.setGuard("testnonce_"+ae.securityPattern.nonce+"== nonce_" + ae.securityPattern.nonce);
+		    }
+
 
 		    AvatarState dummy = new AvatarState(ae.getName()+"_dummy", ae.getReferenceObject());
 		    tran.addNext(dummy);
@@ -799,9 +882,15 @@ public class TML2Avatar {
 	    	    elementList.add(dummy);
 	    	    elementList.add(tran);		
 		    ae.securityPattern.state2=dummy;
-		    AvatarAttributeState authDest = new AvatarAttributeState(ae.securityPattern.name+"2",ae.getReferenceObject(),block.getAvatarAttributeWithName(ae.securityPattern.name), dummy);
-		    signalAuthDestMap.put(ae.securityPattern.name, authDest);
-		}
+		    if (ae.securityPattern.nonce.isEmpty()){
+			AvatarAttributeState authDest = new AvatarAttributeState(ae.securityPattern.name+"2",ae.getReferenceObject(),block.getAvatarAttributeWithName(ae.securityPattern.name), dummy);
+		    	signalAuthDestMap.put(ae.securityPattern.name, authDest);
+		    }
+		    else {	
+		    	AvatarAttributeState authDest = new AvatarAttributeState(ae.securityPattern.name+"3",ae.getReferenceObject(),block.getAvatarAttributeWithName(ae.securityPattern.name), dummy);
+		    	signalAuthDestMap.put(ae.securityPattern.name, authDest);
+		    }
+	       }
 		else if (ae.securityPattern.type.equals("MAC")){
 		    AvatarMethod verifymac = new AvatarMethod("MAC", ae);
 		    verifymac.addParameter(block.getAvatarAttributeWithName(ae.securityPattern.name+"_encrypted"));
@@ -855,6 +944,11 @@ public class TML2Avatar {
 		    if (ae.securityPattern.type.equals("Nonce")){
 			as.addValue("nonce_"+ae.securityPattern.name);
 		    }
+		    else if (!ae.securityPattern.key.isEmpty()){
+			as.addValue("encryptedKey_"+ae.securityPattern.key);
+			AvatarAttribute data= new AvatarAttribute("encryptedKey_"+ae.securityPattern.key, AvatarType.INTEGER, block, null);
+			block.addAttribute(data);
+		    }
 		    else {
 		  	secChannelMap.put(ae.securityPattern.name,ch.getName());
 		 	as.addValue(ae.securityPattern.name+"_encrypted");
@@ -927,6 +1021,11 @@ public class TML2Avatar {
 		    if (ae.securityPattern.type.equals("Nonce")){
 			as.addValue("nonce_"+ae.securityPattern.name);
 		    }
+		    else if (!ae.securityPattern.key.isEmpty()){
+			as.addValue("encryptedKey_"+ae.securityPattern.key);
+			AvatarAttribute data= new AvatarAttribute("encryptedKey_"+ae.securityPattern.key, AvatarType.INTEGER, block, null);
+			block.addAttribute(data);
+		    }
 		    else {
 		    	as.addValue(ae.securityPattern.name+"_encrypted");
 		    	AvatarAttribute data= new AvatarAttribute(ae.securityPattern.name+"_encrypted", AvatarType.INTEGER, block, null);
@@ -1346,7 +1445,7 @@ public class TML2Avatar {
 	//Add authenticity pragmas
 	for (String s: signalAuthOriginMap.keySet()){
 	    if (signalAuthDestMap.containsKey(s)){
-		AvatarPragmaAuthenticity pragma = new AvatarPragmaAuthenticity("#Authenticity ", signalAuthOriginMap.get(s).getReferenceObject(), signalAuthOriginMap.get(s), signalAuthDestMap.get(s));
+		AvatarPragmaAuthenticity pragma = new AvatarPragmaAuthenticity("#Authenticity "+s, signalAuthOriginMap.get(s).getReferenceObject(), signalAuthOriginMap.get(s), signalAuthDestMap.get(s));
 		avspec.addPragma(pragma);
 	    }
 	}
@@ -1534,13 +1633,13 @@ public class TML2Avatar {
 	}
 	//Check if we matched up all signals
 	for (SecurityPattern sp:symKeys.keySet()){
-	    if (symKeys.get(sp).size()!=0){	
-	    	avspec.addPragma(new AvatarPragmaInitialKnowledge("#InitialSystemKnowledge", null, symKeys.get(sp), true));
+	    if (symKeys.get(sp).size()>1){	
+	    	avspec.addPragma(new AvatarPragmaInitialKnowledge("#InitialSystemKnowledge "+sp.name, null, symKeys.get(sp), true));
 	    }
 	}
 	for (SecurityPattern sp:pubKeys.keySet()){
 	    if (pubKeys.get(sp).size()!=0){
-	    	avspec.addPragma(new AvatarPragmaInitialKnowledge("#InitialSystemKnowledge", null, pubKeys.get(sp),true));
+	    	avspec.addPragma(new AvatarPragmaInitialKnowledge("#InitialSystemKnowledge "+sp.name, null, pubKeys.get(sp),true));
 	    }
 	}
 	tmlmap.getTMLModeling().secChannelMap = secChannelMap;
@@ -1629,7 +1728,7 @@ public class TML2Avatar {
 		    b.addAttribute(pubkey);
 		    AvatarAttribute privkey = new AvatarAttribute("privKey_"+sp.name, AvatarType.INTEGER, b, null);
 		    b.addAttribute(privkey);
-		    avspec.addPragma(new AvatarPragmaPrivatePublicKey("PrivatePublicKey ", null, privkey, pubkey));
+		    avspec.addPragma(new AvatarPragmaPrivatePublicKey("PrivatePublicKey "+sp.name, null, privkey, pubkey));
 		    if (pubKeys.containsKey(sp)){
 			pubKeys.get(sp).add(pubkey);
 		    }
@@ -1638,6 +1737,12 @@ public class TML2Avatar {
 			tmp.add(pubkey);
 			pubKeys.put(sp, tmp);
 		    }
+		    //Distribute public key everywhere
+		    for (TMLTask task2 : tasks){
+			AvatarBlock b2 = taskBlockMap.get(task2);
+			pubkey = new AvatarAttribute("pubKey_"+sp.name, AvatarType.INTEGER, b2, null);
+		    	b2.addAttribute(pubkey);
+		    }
 		}
 
 	    }
diff --git a/src/tmltranslator/tomappingsystemc2/TML2MappingSystemC.java b/src/tmltranslator/tomappingsystemc2/TML2MappingSystemC.java
index b9906ae41b56675e9e26b232d84326d833c17d17..481e9abefb1d429c2ab46bf4550efb885fb9dff3 100755
--- a/src/tmltranslator/tomappingsystemc2/TML2MappingSystemC.java
+++ b/src/tmltranslator/tomappingsystemc2/TML2MappingSystemC.java
@@ -189,7 +189,7 @@ public class TML2MappingSystemC {
                     //tmlmapping.getTMLArchitecture().getMasterClockFrequency() * exNode.sliceTime
                     //declaration += "RRScheduler* " + exNode.getName() + "_scheduler = new RRScheduler(\"" + exNode.getName() + "_RRSched\", 0, 5, " + (int) Math.ceil(((float)exNode.execiTime)*(1+((float)exNode.branchingPredictionPenalty)/100)) + " ) " + SCCR;
                     declaration += "RRScheduler* " + exNode.getName() + "_scheduler = new RRScheduler(\"" + exNode.getName() + "_RRSched\", 0, " + (tmlmapping.getTMLArchitecture().getMasterClockFrequency() * exNode.sliceTime) + ", " + (int) Math.ceil((float)(exNode.clockRatio * Math.max(exNode.execiTime,exNode.execcTime) * (exNode.branchingPredictionPenalty * exNode.pipelineSize +100 - exNode.branchingPredictionPenalty))/100) + " ) " + SCCR;
-		System.out.println("cores " + exNode.nbOfCores);
+		TraceManager.addDev("cores " + exNode.nbOfCores);
                 for(int cores=0; cores<exNode.nbOfCores; cores++){
                 //for(int cores=0; cores<1; cores++){
                     //if (tmlmapping.isAUsedHwNode(node)) {
@@ -518,7 +518,7 @@ public class TML2MappingSystemC {
             //TraceManager.addDev("CommELem to process: " + commElem.getName());
             //String commElemName = commElem.getName();
             //if (commElem instanceof HwCPU) commElemName += "0";
-            //System.out.println("Next elem in path: " + commElem.getName());
+            //TraceManager.addDev("Next elem in path: " + commElem.getName());
             if (commElem instanceof HwMemory){
                 reverse=true;
                 slaves.str+= ",static_cast<Slave*>(" + commElem.getName() + "),static_cast<Slave*>(" + commElem.getName() + ")";
@@ -580,7 +580,7 @@ public class TML2MappingSystemC {
         }
         HwMemory memory = getMemConnectedToBusChannelMapped( commNodes, null, commElemToRoute );
         if( memory == null )    {
-            System.out.println( "no memories to map" );
+            TraceManager.addDev( "no memories to map" );
             exploreBuses( 0, commNodes, path, startNode, destNode, commElemToRoute );
         }
         else    {
@@ -663,8 +663,8 @@ public class TML2MappingSystemC {
     private HwMemory getMemConnectedToBusChannelMapped( LinkedList<HwCommunicationNode> _commNodes, HwBus _bus, TMLElement _channel )   {
         for( HwCommunicationNode commNode: _commNodes ) {
             if( commNode instanceof HwMemory )  {
-                if( _bus != null ) System.out.println(commNode.getName() + " connected to bus " + _bus.getName() + ": " + tmlmapping.getTMLArchitecture().isNodeConnectedToBus(commNode, _bus));
-                System.out.println(_channel.getName() + " is mapped onto " + commNode.getName() + ": " + tmlmapping.isCommNodeMappedOn(_channel,commNode));
+                if( _bus != null ) TraceManager.addDev(commNode.getName() + " connected to bus " + _bus.getName() + ": " + tmlmapping.getTMLArchitecture().isNodeConnectedToBus(commNode, _bus));
+                TraceManager.addDev(_channel.getName() + " is mapped onto " + commNode.getName() + ": " + tmlmapping.isCommNodeMappedOn(_channel,commNode));
                 if( ( _bus == null || tmlmapping.getTMLArchitecture().isNodeConnectedToBus( commNode, _bus ) )
                     && tmlmapping.isCommNodeMappedOn( _channel, commNode ) )    {
                     return (HwMemory)commNode;
diff --git a/src/ui/GTMLModeling.java b/src/ui/GTMLModeling.java
index f6118021cb81efb7d7f3257c6efec53ab386d402..d98e5041c0b032dd897ce21f49972c3292018054 100755
--- a/src/ui/GTMLModeling.java
+++ b/src/ui/GTMLModeling.java
@@ -1302,7 +1302,7 @@ public class GTMLModeling  {
 	while(iterator.hasNext()){
 	    tgc = (TGComponent)(iterator.next());
 	    if (tgc instanceof TMLADEncrypt) {
-		SecurityPattern securityPattern = new SecurityPattern(((TMLADEncrypt)tgc).securityContext, ((TMLADEncrypt)tgc).type, ((TMLADEncrypt)tgc).message_overhead, ((TMLADEncrypt)tgc).size, ((TMLADEncrypt)tgc).calculationTime, ((TMLADEncrypt)tgc).nonce);
+		SecurityPattern securityPattern = new SecurityPattern(((TMLADEncrypt)tgc).securityContext, ((TMLADEncrypt)tgc).type, ((TMLADEncrypt)tgc).message_overhead, ((TMLADEncrypt)tgc).size, ((TMLADEncrypt)tgc).encTime, ((TMLADEncrypt)tgc).decTime, ((TMLADEncrypt)tgc).nonce, ((TMLADEncrypt)tgc).formula, ((TMLADEncrypt)tgc).key);
 		securityPatterns.put(securityPattern.name, securityPattern);
 		tmlm.addSec(securityPattern);
 		ArrayList<TMLTask> l = new ArrayList<TMLTask>();
@@ -1516,7 +1516,7 @@ public class GTMLModeling  {
                     checkingErrors.add(ce);
 		}
 		tmlexecc.securityPattern = sp;
-                tmlexecc.setAction(Integer.toString(sp.time));
+                tmlexecc.setAction(Integer.toString(sp.encTime));
                 ((BasicErrorHighlight)tgc).setStateAction(ErrorHighlight.OK);
 		tmlm.securityTaskMap.get(sp).add(tmltask);
                 listE.addCor(tmlexecc, tgc);
@@ -1533,7 +1533,7 @@ public class GTMLModeling  {
                     checkingErrors.add(ce);
 		}
 		tmlexecc.securityPattern = sp;
-                tmlexecc.setAction(Integer.toString(sp.time));
+                tmlexecc.setAction(Integer.toString(sp.decTime));
                 ((BasicErrorHighlight)tgc).setStateAction(ErrorHighlight.OK);
                 listE.addCor(tmlexecc, tgc);
 		tmlm.securityTaskMap.get(sp).add(tmltask);
@@ -1662,6 +1662,12 @@ public class GTMLModeling  {
 		    	//NbOfSamples will increase due to extra overhead from MAC
 		    	int cur = Integer.valueOf(modifyString(((TMLADReadChannel)tgc).getSamplesValue()));
 		    	int add = Integer.valueOf(tmlreadchannel.securityPattern.overhead);
+			if (!tmlreadchannel.securityPattern.nonce.equals("")){
+			    SecurityPattern nonce = securityPatterns.get(tmlreadchannel.securityPattern.nonce);
+			    if (nonce!=null){
+			        add = Integer.valueOf(nonce.overhead);
+			    }
+			}
 		    	Double d= Math.ceil(add/4.0);
 			cur = cur+ d.intValue();
 		    	tmlreadchannel.setNbOfSamples(Integer.toString(cur));
@@ -1978,6 +1984,12 @@ public class GTMLModeling  {
 			tmlwritechannel.securityPattern= securityPatterns.get(((TMLADWriteChannel)tgc).securityContext);
 		 	int cur = Integer.valueOf(modifyString(((TMLADWriteChannel)tgc).getSamplesValue()));
 		    	int add = Integer.valueOf(tmlwritechannel.securityPattern.overhead);
+			if (!tmlwritechannel.securityPattern.nonce.equals("")){
+			    SecurityPattern nonce = securityPatterns.get(tmlwritechannel.securityPattern.nonce);
+			    if (nonce!=null){
+			        add = Integer.valueOf(nonce.overhead);
+			    }
+			}
 		    	Double d= Math.ceil(add/4.0);
 			cur = cur+ d.intValue();
 		    	tmlwritechannel.setNbOfSamples(Integer.toString(cur));
@@ -3303,6 +3315,9 @@ if (tgc instanceof TMLArchiCrossbarNode) {
 			    	map.mappedSecurity.put(sp, mems);
 			    	TraceManager.addDev("Added key of " + key.getValue());
 			    }
+			}
+			else {
+			    System.out.println("Can't map key " + key.getValue());
 			}			
 		    }
                 }
diff --git a/src/ui/GTURTLEModeling.java b/src/ui/GTURTLEModeling.java
index 508d413ab30b7a7d063cc428a086a09d483e3f6e..1d54125ac12be9aa5519da4e8993f9db135d4ab8 100755
--- a/src/ui/GTURTLEModeling.java
+++ b/src/ui/GTURTLEModeling.java
@@ -643,14 +643,57 @@ public class GTURTLEModeling {
 	//count # of insecure channels?
 	return overhead;
     }
-    public TMLMapping autoSecure(MainGUI gui){
+ 
+
+
+    public TMLMapping autoSecure(MainGUI gui, boolean autoConf, boolean autoAuth){
+	if (tmap==null){
+	    return null;
+	}
+	int arch = gui.tabs.indexOf(tmap.tmlap);
+	gui.cloneRenameTab(arch,"enc");
+	TMLArchiPanel newarch = (TMLArchiPanel) gui.tabs.get(gui.tabs.size()-1);
+	return autoSecure(gui, "enc", tmap,newarch,autoConf,autoAuth);
+    }
+    public TMLMapping autoSecure(MainGUI gui, String name, TMLMapping map, TMLArchiPanel newarch){
+	 return autoSecure(gui,name,map,newarch,"100","0","100",true,false);
+    }
+    public TMLMapping autoSecure(MainGUI gui, String name, TMLMapping map, TMLArchiPanel newarch, boolean autoConf, boolean autoAuth){
+	 return autoSecure(gui,name,map,newarch,"100","0","100",autoConf,autoAuth);
+    }
+
+    public TMLMapping autoSecure(MainGUI gui, String encComp, String overhead, String decComp){
+	if (tmap==null){
+	    return null;
+	}
+	int arch = gui.tabs.indexOf(tmap.tmlap);
+	gui.cloneRenameTab(arch,"enc");
+	TMLArchiPanel newarch = (TMLArchiPanel) gui.tabs.get(gui.tabs.size()-1);
+	return autoSecure(gui,"enc", tmap,newarch,encComp, overhead,decComp,true,false);
+    }
+
+    public TMLMapping autoSecure(MainGUI gui, String encComp, String overhead, String decComp, boolean autoConf, boolean autoAuth){
+	if (tmap==null){
+	    return null;
+	}
+	int arch = gui.tabs.indexOf(tmap.tmlap);
+	gui.cloneRenameTab(arch,"enc");
+	TMLArchiPanel newarch = (TMLArchiPanel) gui.tabs.get(gui.tabs.size()-1);
+	return autoSecure(gui,"enc", tmap,newarch,encComp, overhead,decComp,autoConf,autoAuth);
+    }
+    public TMLMapping autoSecure(MainGUI gui, String name, TMLMapping map, TMLArchiPanel newarch, String encComp, String overhead, String decComp){ 
+	return autoSecure(gui,name, tmap,newarch,encComp, overhead,decComp,true,false);
+    }
+
+
+    public TMLMapping autoSecure(MainGUI gui, String name, TMLMapping map, TMLArchiPanel newarch, String encComp, String overhead, String decComp, boolean autoConf, boolean autoAuth){ 
 	HashMap<TMLTask, java.util.List<TMLTask>> toSecure = new HashMap<TMLTask, java.util.List<TMLTask>>();
 	HashMap<TMLTask, java.util.List<String>> insecureOutChannels = new HashMap<TMLTask, java.util.List<String>>();
 	HashMap<TMLTask, java.util.List<String>> insecureInChannels = new HashMap<TMLTask, java.util.List<String>>();
-	if (tmap==null){
+	if (map==null){
 	    return null;
 	}
-	TMLModeling tmlmodel = tmap.getTMLModeling();
+	TMLModeling tmlmodel = map.getTMLModeling();
 	java.util.List<TMLChannel> channels = tmlmodel.getChannels();
 	for (TMLChannel channel: channels){
 	    for (TMLCPrimitivePort p: channel.ports){
@@ -661,20 +704,16 @@ public class GTURTLEModeling {
 
 	//Create clone of Component Diagram + Activity diagrams to secure
 
-	TMLComponentDesignPanel tmlcdp = tmap.getTMLCDesignPanel();
+	TMLComponentDesignPanel tmlcdp = map.getTMLCDesignPanel();
 	int ind = gui.tabs.indexOf(tmlcdp);
 	String tabName = gui.getTitleAt(tmlcdp);
-	gui.cloneRenameTab(ind, "enc");
-	int arch = gui.tabs.indexOf(tmap.tmlap);
-	gui.cloneRenameTab(arch,"enc");
-	TMLComponentDesignPanel t = (TMLComponentDesignPanel) gui.tabs.get(gui.tabs.size()-2);
+	gui.cloneRenameTab(ind, name);
+	TMLComponentDesignPanel t = (TMLComponentDesignPanel) gui.tabs.get(gui.tabs.size()-1);
+	map.setTMLDesignPanel(t);
 	//Create clone of architecture panel and map tasks to it		
-	TMLArchiPanel newarch = (TMLArchiPanel) gui.tabs.get(gui.tabs.size()-1);
-	newarch.renameMapping(tabName, tabName+"_enc");
-	for (TMLChannel c: tmlmodel.getChannels()){
-	    System.out.println(c.getName());
-	}
-	for (TMLTask task: tmap.getTMLModeling().getTasks()){
+	newarch.renameMapping(tabName, tabName+"_"+name);
+
+	for (TMLTask task: map.getTMLModeling().getTasks()){
 	    java.util.List<String> tmp = new ArrayList<String>();
 	    java.util.List<String> tmp2 = new ArrayList<String>();
 	    java.util.List<TMLTask> tmp3 = new ArrayList<TMLTask>();
@@ -682,18 +721,18 @@ public class GTURTLEModeling {
 	    insecureOutChannels.put(task, tmp2);
 	    toSecure.put(task,tmp3);
 	}
-	for (TMLTask task: tmap.getTMLModeling().getTasks()){   
+	for (TMLTask task: map.getTMLModeling().getTasks()){   
 	    TMLActivityDiagramPanel tad = t.getTMLActivityDiagramPanel(task.getName());
 	    for (TGComponent tg:tad.getComponentList()){
 		if (tg instanceof TMLADWriteChannel){
 		    TMLADWriteChannel writeChannel = (TMLADWriteChannel) tg;
-		    TraceManager.addDev("Inspecting channel " + writeChannel.getChannelName());
 		    if (writeChannel.securityContext.equals("")){
-			System.out.println(tabName+"__"+writeChannel.getChannelName());
 			TMLChannel chan = tmlmodel.getChannelByName(tabName+"__"+writeChannel.getChannelName());
 			if (chan!=null){
+			    chan.checkConf=true;
 			    if (chan.checkConf){
-			    	if (!securePath(chan.getOriginTask(), chan.getDestinationTask())){
+			    	if (!securePath(map, chan.getOriginTask(), chan.getDestinationTask())){
+				   
 		    		    insecureOutChannels.get(chan.getOriginTask()).add(writeChannel.getChannelName());
 		    		    insecureInChannels.get(chan.getDestinationTask()).add(writeChannel.getChannelName());
 				    toSecure.get(chan.getOriginTask()).add(chan.getDestinationTask());
@@ -704,7 +743,6 @@ public class GTURTLEModeling {
 		}
 	    }
 	}
-	System.out.println(toSecure);
 	int num=0;
 
 	for (TMLTask task:toSecure.keySet()){
@@ -731,7 +769,9 @@ public class GTURTLEModeling {
 	    	TMLADEncrypt enc = new TMLADEncrypt(xpos+5, ypos, tad.getMinX(), tad.getMaxX(), tad.getMinY(), tad.getMaxY(), false, null, tad);
 	    	enc.securityContext = "autoEncrypt_"+channel;
 	    	enc.type = "Symmetric Encryption";
-	    	enc.message_overhead = "100";
+	    	enc.message_overhead = overhead;
+		enc.encTime= encComp;
+		enc.decTime=decComp;
 	    	tad.addComponent(enc, xpos ,ypos, false, true);
 
 		fromStart.setP2(enc.getTGConnectingPointAtIndex(0));
@@ -776,7 +816,7 @@ public class GTURTLEModeling {
 				continue;
 			    }
 			    TGConnectingPoint next = conn.getTGConnectingPointP2();
-			    TMLADDecrypt dec = new TMLADDecrypt(x+40, y+40, tad2.getMinX(), tad2.getMaxX(), tad2.getMinY(), tad2.getMaxY(), false, null, tad);
+			    TMLADDecrypt dec = new TMLADDecrypt(x, y+40, tad2.getMinX(), tad2.getMaxX(), tad2.getMinY(), tad2.getMaxY(), false, null, tad);
 			    dec.securityContext = "autoEncrypt_" + readChannel.getChannelName();
 			    toadd.add(dec);
 			    conn.setP2(dec.getTGConnectingPointAtIndex(0));
@@ -795,14 +835,34 @@ public class GTURTLEModeling {
 	    }
 
 	}
-	return tmap;
+	GTMLModeling gtm = new GTMLModeling(t, false);
+	TMLModeling newmodel = gtm.translateToTMLModeling(false,false);
+	for (TMLTask task:newmodel.getTasks()){
+	    task.setName(tabName+"_"+name+"__"+task.getName());
+	}
+	for (TMLTask task: tmlmodel.getTasks()){
+	    System.out.println(task.getName());
+	    HwExecutionNode node =(HwExecutionNode) map.getHwNodeOf(task);
+	    if (newmodel.getTMLTaskByName(task.getName().replace(tabName,tabName+"_"+name))!=null){
+	        map.addTaskToHwExecutionNode(newmodel.getTMLTaskByName(task.getName().replace(tabName,tabName+"_"+name)), node);
+		map.removeTask(task);
+	    }
+	    else {
+		System.out.println("Can't find " + task.getName());
+	    }
+	}
+	//map.setTMLModeling(newmodel);
+	//System.out.println(map);
+	//TMLMapping newMap = gtm.translateToTMLMapping();
+	map.setTMLModeling(newmodel);
+	return map;
     }
-    public boolean securePath(TMLTask t1, TMLTask t2){
+    public boolean securePath(TMLMapping map, TMLTask t1, TMLTask t2){
 	//Check if a path between two tasks is secure
 	boolean secure=true;
-	java.util.List<HwLink> links = tmap.getTMLArchitecture().getHwLinks();
-	HwExecutionNode node1 = (HwExecutionNode) tmap.getHwNodeOf(t1);
-	HwExecutionNode node2 = (HwExecutionNode) tmap.getHwNodeOf(t2);
+	java.util.List<HwLink> links = map.getTMLArchitecture().getHwLinks();
+	HwExecutionNode node1 = (HwExecutionNode) map.getHwNodeOf(t1);
+	HwExecutionNode node2 = (HwExecutionNode) map.getHwNodeOf(t2);
 	java.util.List<HwNode> found = new ArrayList<HwNode>();	
 	java.util.List<HwNode> done = new ArrayList<HwNode>();
 	java.util.List<HwNode> path = new ArrayList<HwNode>();
diff --git a/src/ui/MainGUI.java b/src/ui/MainGUI.java
index f5d5fbe515553f5702c48737c620b394af53bfeb..08c901e762f04ee651a963d18c7f1647f70dbd7d 100755
--- a/src/ui/MainGUI.java
+++ b/src/ui/MainGUI.java
@@ -3810,6 +3810,22 @@ public  class MainGUI implements ActionListener, WindowListener, KeyListener, Pe
 	strlist.toArray(strarray); 
 	return strarray;
     }
+
+    public ArrayList<String> getAllKeys(){
+        TURTLEPanel tp;
+        ArrayList<String> list = new ArrayList<String>();
+
+        for(int i=0; i<tabs.size(); i++) {
+            tp = (TURTLEPanel)(tabs.elementAt(i));
+            if (tp instanceof TMLComponentDesignPanel) {
+        	for (String s:((TMLComponentDesignPanel)tp).getAllKeys()){
+		    list.add(s);
+		}
+	    }
+	}
+	return list;
+    }
+
     public String[] getAllOutRequests() {
         TURTLEPanel tp = getCurrentTURTLEPanel();
         if (tp == null) {return null;}
@@ -4122,7 +4138,7 @@ public  class MainGUI implements ActionListener, WindowListener, KeyListener, Pe
     public void dse(){
 	TraceManager.addDev("Design space exploration");
 	JDialogDSE jdse= new JDialogDSE(frame, this, "Design Space Exploration", ConfigurationTTool.SystemCCodeDirectory, ConfigurationTTool.TMLCodeDirectory);
-	jdse.setSize(500,500);
+	jdse.setSize(500,800);
         GraphicLib.centerOnParent(jdse);
         jdse.setVisible(true);
 	dtree.toBeUpdated();
@@ -7267,7 +7283,7 @@ public  class MainGUI implements ActionListener, WindowListener, KeyListener, Pe
 
     public void requestRenameTab(int index) {
         String oldName = mainTabbedPane.getTitleAt(index);
-        String s = (String)JOptionPane.showInputDialog(frame, "Name: ", "Renaming a tab=", JOptionPane.PLAIN_MESSAGE, IconManager.imgic101, null, mainTabbedPane.getTitleAt(index));
+        String s = (String)JOptionPane.showInputDialog(frame, "Name: ", "Renaming a tab", JOptionPane.PLAIN_MESSAGE, IconManager.imgic101, null, mainTabbedPane.getTitleAt(index));
         if ((s != null) && (s.length() > 0)){
             // name already in use?
             if (s.compareTo(oldName) != 0) {
diff --git a/src/ui/TMLComponentDesignPanel.java b/src/ui/TMLComponentDesignPanel.java
index 936f03648f45f2ac60da51aeaac75109629d710c..8526c56f176d24423d0190a67880d1df47a05451 100755
--- a/src/ui/TMLComponentDesignPanel.java
+++ b/src/ui/TMLComponentDesignPanel.java
@@ -229,6 +229,15 @@ public class TMLComponentDesignPanel extends TURTLEPanel {
 	return ns;
     }
 
+    public ArrayList<String> getAllKeys(){
+	ArrayList<String> ns=new ArrayList<String>();
+	TMLActivityDiagramPanel tmladp;
+        for(int i=1; i<panels.size(); i++) {
+            tmladp = (TMLActivityDiagramPanel)(panels.elementAt(i));
+            ns.addAll(tmladp.getAllKeys());
+        }
+	return ns;
+    }
 
     public String[] getAllOutEvents(String nameOfComponent) {
 	return tmlctdp.getAllOutEvents(nameOfComponent);
diff --git a/src/ui/tmlad/TMLADDecrypt.java b/src/ui/tmlad/TMLADDecrypt.java
index 9798bcd735ea7ce282f3fc908f4d0190373df2d0..a1ca5108557c3f9cd44f01902ce308fb5a38de73 100755
--- a/src/ui/tmlad/TMLADDecrypt.java
+++ b/src/ui/tmlad/TMLADDecrypt.java
@@ -62,9 +62,8 @@ public class TMLADDecrypt extends TGCWithoutInternalComponent implements Embedde
     private int textX, textY;
     private int ilength = 10;
     private int lineLength1 = 2;
-    public String securityContext="";
-	
-	protected int stateOfError = 0; // Not yet checked
+    public String securityContext="";	
+    protected int stateOfError = 0; // Not yet checked
     
     public TMLADDecrypt(int _x, int _y, int _minX, int _maxX, int _minY, int _maxY, boolean _pos, TGComponent _father, TDiagramPanel _tdp)  {
         super(_x, _y, _minX, _maxX, _minY, _maxY, _pos, _father, _tdp);
diff --git a/src/ui/tmlad/TMLADEncrypt.java b/src/ui/tmlad/TMLADEncrypt.java
index a7fc94907082f7e0c39fd62012763fab4b0c26be..afce784c48ee1580813b5e7145c063a92e1f5a5e 100755
--- a/src/ui/tmlad/TMLADEncrypt.java
+++ b/src/ui/tmlad/TMLADEncrypt.java
@@ -66,7 +66,9 @@ public class TMLADEncrypt extends TGCWithoutInternalComponent implements Embedde
     public String message_overhead="";
     public String size="";
     public String securityContext="";
-    public String calculationTime="100";
+    public String encTime="100";
+    public String decTime="100";	
+    public String key ="";
     public String nonce="";
     public String formula="";
     protected int stateOfError = 0; // Not yet checked
@@ -120,9 +122,10 @@ public class TMLADEncrypt extends TGCWithoutInternalComponent implements Embedde
 public boolean editOndoubleClick(JFrame frame) {
 
         //JDialogTwoString jdts = new JDialogTwoString(frame, "Setting channel's properties", "Channel name", channelName, "Nb of samples", nbOfSamples);]
-	String[] values=new String[]{securityContext, type, message_overhead, calculationTime, size, nonce, formula};
+	String[] values=new String[]{securityContext, type, message_overhead, encTime, size, nonce, formula, decTime, key};
 	String[] nonces=tdp.getMGUI().getAllNonce();
-	JDialogCryptographicConfiguration jdms = new JDialogCryptographicConfiguration(frame, "Setting Cryptographic Configuration properties", values, nonces);
+	String[] keys = tdp.getMGUI().getAllKeys().toArray(new String[0]);
+	JDialogCryptographicConfiguration jdms = new JDialogCryptographicConfiguration(frame, "Setting Cryptographic Configuration properties", values, nonces, keys);
         jdms.setSize(650, 300);
         GraphicLib.centerOnParent(jdms);
         jdms.show(); // blocked until dialog has been closed
@@ -131,10 +134,12 @@ public boolean editOndoubleClick(JFrame frame) {
 	    securityContext = jdms.getString(0);
 	    type=jdms.getString(1);
 	    message_overhead=jdms.getString(2);
-	    calculationTime=jdms.getString(3);
+	    encTime=jdms.getString(3);
 	    size=jdms.getString(4);
 	    nonce=jdms.getString(5);
 	    formula = jdms.getString(6);
+	    decTime = jdms.getString(7);
+	    key = jdms.getString(8);
             return true;
         }
 
@@ -168,8 +173,10 @@ public boolean editOndoubleClick(JFrame frame) {
         sb.append(message_overhead);
 	sb.append("\" size=\"");
         sb.append(size);
-	sb.append("\" calcTime=\"");
-        sb.append(calculationTime);
+	sb.append("\" encTime=\"");
+        sb.append(encTime);
+	sb.append("\" decTime=\"");
+        sb.append(decTime);
 	sb.append("\" nonce=\"");
         sb.append(nonce);
         sb.append("\" />\n");
@@ -205,7 +212,8 @@ public boolean editOndoubleClick(JFrame frame) {
 				type= elt.getAttribute("type");
 				message_overhead= elt.getAttribute("overhead");
 				size= elt.getAttribute("size");
-				calculationTime = elt.getAttribute("calcTime");
+				encTime = elt.getAttribute("encTime");
+				decTime = elt.getAttribute("decTime");
 				nonce = elt.getAttribute("nonce");
                                 //System.out.println("eventName=" +eventName + " variable=" + result);
                             }
diff --git a/src/ui/tmlad/TMLActivityDiagramPanel.java b/src/ui/tmlad/TMLActivityDiagramPanel.java
index 78d1b0d38bbf685c166dc958123b9f44e39a7b69..42cc4acb529ae84090f6a353f307db7e7d362b04 100755
--- a/src/ui/tmlad/TMLActivityDiagramPanel.java
+++ b/src/ui/tmlad/TMLActivityDiagramPanel.java
@@ -196,4 +196,19 @@ public class TMLActivityDiagramPanel extends TDiagramPanel {
 	}
 	return ns;
     }
+
+    public ArrayList<String> getAllKeys(){
+	ArrayList<String> ns=new ArrayList<String>();
+	LinkedList<TGComponent> comps= getAllComponentList();
+	for (TGComponent c: comps){
+	    if (c instanceof TMLADEncrypt){
+		TMLADEncrypt en= (TMLADEncrypt) c;
+		if (!en.securityContext.isEmpty() && (en.type.equals("Symmetric Encryption") || en.type.equals("Asymmetric Encryption") ||  en.type.equals("MAC"))){
+		    ns.add(en.securityContext);
+		}
+	    }
+	}
+	return ns;
+    }
+
 }
diff --git a/src/ui/tmldd/TMLArchiArtifact.java b/src/ui/tmldd/TMLArchiArtifact.java
index 829b67e8ad28a6824d44f020c478d1ab0ade0f47..4197ac4a74b86d9f3dce5eaf85135ee7562909f4 100755
--- a/src/ui/tmldd/TMLArchiArtifact.java
+++ b/src/ui/tmldd/TMLArchiArtifact.java
@@ -319,7 +319,11 @@ public class TMLArchiArtifact extends TGCWithoutInternalComponent implements Swa
         referenceTaskName = _referenceTaskName;
 		makeFullValue();
     }
-    
+    public void setFullName(String _taskName, String _referenceTaskName){
+	taskName= _taskName;
+	referenceTaskName=_referenceTaskName;
+	makeFullValue();
+    }
     public String getTaskName() {
         return taskName;
     }
diff --git a/src/ui/tmldd/TMLArchiKey.java b/src/ui/tmldd/TMLArchiKey.java
index 26957482dbbec6eb0b419b34b0c4e5d9d5feefb5..f36f7064b74c68c40bc019936a037fb872c7a2c7 100755
--- a/src/ui/tmldd/TMLArchiKey.java
+++ b/src/ui/tmldd/TMLArchiKey.java
@@ -190,9 +190,6 @@ public class TMLArchiKey extends TGCWithoutInternalComponent implements Swallowe
 			typeName = dialog.getTypeName();
 		}
 		
-		priority = dialog.getPriority();
-		
-		((TMLArchiDiagramPanel)tdp).setPriority(getFullValue(), priority);
 		
 			
 		if (error) {
diff --git a/src/ui/window/JDialogArchiKey.java b/src/ui/window/JDialogArchiKey.java
index fc2576e35273ccd33feaa65de6a36285a82527bd..1551d04244cb47059a106deb9a3d4e7f9b8dd2b4 100644
--- a/src/ui/window/JDialogArchiKey.java
+++ b/src/ui/window/JDialogArchiKey.java
@@ -68,7 +68,7 @@ public class JDialogArchiKey extends javax.swing.JDialog implements ActionListen
     private Frame frame;
     private TMLArchiKey artifact;
     
-	protected JComboBox referenceCommunicationName, priority;
+	protected JComboBox referenceCommunicationName;
 	
     // Main Panel
     private JButton closeButton;
@@ -95,7 +95,7 @@ public class JDialogArchiKey extends javax.swing.JDialog implements ActionListen
     }
     
     private void myInitComponents() {
-		selectPriority();
+		
     }
     
     private void initComponents() {
@@ -125,35 +125,34 @@ public class JDialogArchiKey extends javax.swing.JDialog implements ActionListen
         c1.fill = GridBagConstraints.HORIZONTAL;
         panel2.add(new JLabel("Key:"), c2);
         c1.gridwidth = GridBagConstraints.REMAINDER; //end row
-		TraceManager.addDev("Getting key");
-		Vector<String> list = artifact.getTDiagramPanel().getMGUI().getAllCryptoConfig();
-		int index = 0;
-		if (list.size() == 0) {
-			list.add("No key to map");
+	TraceManager.addDev("Getting key");
+	ArrayList<String> list = artifact.getTDiagramPanel().getMGUI().getAllKeys();
+	int index = 0;
+	/*	if (list.size() == 0) {
 			emptyList = true;
 		} else {
 			
-			index = indexOf(list, artifact.getFullValue());
+			index = list.indexOf(artifact.getFullValue());
 			//System.out.println("name=" + artifact.getFullValue() + " index=" + index);
 		}
-		
+		*/
 		TraceManager.addDev("Got keyss");
 		
-        referenceCommunicationName = new JComboBox(list);
+        referenceCommunicationName = new JComboBox(list.toArray(new String[list.size()]));
 		referenceCommunicationName.setSelectedIndex(index);
 		referenceCommunicationName.addActionListener(this);
         //referenceTaskName.setEditable(true);
         //referenceTaskName.setFont(new Font("times", Font.PLAIN, 12));
 		panel2.add(referenceCommunicationName, c1);
-		
-		list = new Vector<String>();
+		/*
+		Vector<String> list = new Vector<String>();
 		for(int i=0; i<11; i++) {
 			list.add(""+i);
 		}
 		priority = new JComboBox(list);
 		priority.setSelectedIndex(artifact.getPriority());
 		panel2.add(priority, c1);
-		
+		*/
 		/*c1.gridwidth = 1;
         c1.gridheight = 1;
         c1.weighty = 1.0;
@@ -193,9 +192,7 @@ public class JDialogArchiKey extends javax.swing.JDialog implements ActionListen
             return;
         }*/
 		
-		if (evt.getSource() == referenceCommunicationName) {
-			selectPriority();
-		}
+
         
         
         String command = evt.getActionCommand();
@@ -209,11 +206,7 @@ public class JDialogArchiKey extends javax.swing.JDialog implements ActionListen
     }
 	
 	
-	public void selectPriority() {
-		//System.out.println("Select priority");
-		int index = ((TMLArchiDiagramPanel)artifact.getTDiagramPanel()).getMaxPriority((String)(referenceCommunicationName.getSelectedItem()));
-		priority.setSelectedIndex(index);
-	}
+
     
     public void closeDialog() {
         regularClose = true;
@@ -278,8 +271,5 @@ public class JDialogArchiKey extends javax.swing.JDialog implements ActionListen
 		return 0;
 	}
 	
-	public int getPriority() {
-		return priority.getSelectedIndex();
-	}
     
 }
diff --git a/src/ui/window/JDialogCryptographicConfiguration.java b/src/ui/window/JDialogCryptographicConfiguration.java
index 511dda18571336edb8b0cc9fbfc510d77aa13972..92497ee19466d316a7c836cfae3eadda26ef4a82 100644
--- a/src/ui/window/JDialogCryptographicConfiguration.java
+++ b/src/ui/window/JDialogCryptographicConfiguration.java
@@ -74,20 +74,22 @@ public class JDialogCryptographicConfiguration extends javax.swing.JDialog imple
     private JButton closeButton;
     private JButton cancelButton;
     String[] nonces;
+    String[] keys;
     private ArrayList<String[]> possibleValues = null;
 
     GridBagConstraints c0 = new GridBagConstraints();
     Container c;
     /** Creates new form  */
     // arrayDelay: [0] -> minDelay ; [1] -> maxDelay
-    public JDialogCryptographicConfiguration(Frame f, String title, String[] _values, String[] _nonces) {
+    public JDialogCryptographicConfiguration(Frame f, String title, String[] _values, String[] _nonces, String[] _keys) {
 
         super(f, title, true);
 
-        nbString = 7;
+        nbString = 9;
 
 	values=_values;
 	nonces=_nonces;
+	keys=_keys;
         texts = new JTextField[nbString];
 
         initComponents();
@@ -217,6 +219,9 @@ public class JDialogCryptographicConfiguration extends javax.swing.JDialog imple
 	    if (evt.getSource() == inserts[5]) {
 		texts[5].setText(helps[5].getSelectedItem().toString());
 	    }
+	    if (evt.getSource() == inserts[8]) {
+		texts[8].setText(helps[8].getSelectedItem().toString());
+	    }
 	}
     }
 
@@ -274,11 +279,16 @@ public class JDialogCryptographicConfiguration extends javax.swing.JDialog imple
 	add(texts[2],c1);
 
       	c1.gridwidth = 1;
-	add(new JLabel("Computational Complexity"),c1);
+	add(new JLabel("Encryption Computational Complexity"),c1);
 	texts[3]=new JTextField(values[3],15);
 	c1.gridwidth = GridBagConstraints.REMAINDER; //end row
 	add(texts[3],c1);
 
+      	c1.gridwidth = 1;
+	add(new JLabel("Decryption Computational Complexity"),c1);
+	texts[7]=new JTextField(values[7],15);
+	c1.gridwidth = GridBagConstraints.REMAINDER; //end row
+	add(texts[7],c1);
 
       	c1.gridwidth = 1;
 	add(new JLabel("Nonce"),c1);
@@ -291,6 +301,19 @@ public class JDialogCryptographicConfiguration extends javax.swing.JDialog imple
 	add(inserts[5], c1);
 	texts[5]=new JTextField(values[5], 15);
         add(texts[5], c1);
+
+      	c1.gridwidth = 1;
+	add(new JLabel("Encrypted Key"),c1);
+	helps[8]=new JComboBox(keys);
+	helps[8].setSelectedItem(values[8]);
+	add(helps[8],c1);
+	c1.gridwidth=GridBagConstraints.REMAINDER;
+	inserts[8] = new JButton("Use");
+	inserts[8].addActionListener(j);
+	add(inserts[8], c1);
+	texts[8]=new JTextField(values[8], 15);
+        add(texts[8], c1);
+
 	}
     }
 
@@ -320,7 +343,7 @@ public class JDialogCryptographicConfiguration extends javax.swing.JDialog imple
         c1.anchor = GridBagConstraints.CENTER;
         c1.fill = GridBagConstraints.HORIZONTAL;
         c1.anchor = GridBagConstraints.CENTER;
-	String[] vals = new String[]{"Symmetric Encryption", "Asymmetric Encryption","MAC", "Hash", "Nonce"}; 
+	String[] vals = new String[]{"Symmetric Encryption", "Asymmetric Encryption","MAC", "Hash", "Nonce", "Advanced"}; 
         // String1
       	c1.gridwidth = 1;
 	add(new JLabel("Cryptographic Configuration Name"),c1);
@@ -383,7 +406,7 @@ public class advPanel extends JPanel {
         c1.anchor = GridBagConstraints.CENTER;
         c1.fill = GridBagConstraints.HORIZONTAL;
         c1.anchor = GridBagConstraints.CENTER;
-	String[] vals = new String[]{"Symmetric Encryption", "Asymmetric Encryption","MAC", "Hash", "Nonce"}; 
+	String[] vals = new String[]{"Symmetric Encryption", "Asymmetric Encryption","MAC", "Hash", "Nonce", "Advanced"}; 
 
         // String1
       	c1.gridwidth = 1;
@@ -397,6 +420,12 @@ public class advPanel extends JPanel {
 	helps[1]=new JComboBox(vals);
 	helps[1].setSelectedItem(values[1]);
 	add(helps[1],c1);
+	c1.gridwidth=GridBagConstraints.REMAINDER;
+	inserts[0] = new JButton("Use");
+	inserts[0].addActionListener(j);
+	add(inserts[0], c1);
+	texts[1]=new JTextField(values[1], 15);
+        add(texts[1], c1);
 
       	c1.gridwidth = 1;
 	add(new JLabel("Overhead"),c1);
diff --git a/src/ui/window/JDialogDSE.java b/src/ui/window/JDialogDSE.java
index 4e47207c0a13028f1a2208f085c77f567799989f..2ff238c3180961057831694a73b82d61f7b336ea 100644
--- a/src/ui/window/JDialogDSE.java
+++ b/src/ui/window/JDialogDSE.java
@@ -87,10 +87,17 @@ public class JDialogDSE extends javax.swing.JDialog implements ActionListener, R
     protected JButton close;
     String simulator;
    
-    protected JCheckBox autoSecure, autoMapKeys;
+    protected JCheckBox autoConf, autoAuth, autoMapKeys, custom;
+	
+    protected JTextField encTime, decTime, secOverhead;
+
     protected JTextField tmlDirectory, mappingFile, modelFile, simulationThreads, resultsDirectory, simulationCycles, minCPU, maxCPU, simulationsPerMapping;
     protected JTextArea outputText;
     protected String output = "";
+    protected JCheckBox secAnalysis;
+    protected JTextField encTime2, decTime2, secOverhead2;
+
+
     String tmlDir;
     String mapFile = "spec.tmap";
     String modFile = "spec.tml";
@@ -99,7 +106,11 @@ public class JDialogDSE extends javax.swing.JDialog implements ActionListener, R
     String simCycles="1000";
     String NbMinCPU ="1";
     String NbMaxCPU ="1";
-    String Nbsim ="1";
+    String Nbsim ="100";
+    String encCC="100";
+    String decCC="100";
+    String secOv = "100";
+
     protected JTabbedPane jp1;
     private Thread t;
     private boolean go = false;
@@ -154,11 +165,28 @@ public class JDialogDSE extends javax.swing.JDialog implements ActionListener, R
         c01.gridheight = 1;
 
         //genJava.addActionListener(this);
-	autoSecure= new JCheckBox("Add security");
-        jp01.add(autoSecure, c01);
+	autoConf= new JCheckBox("Add security (Confidentiality)");
+        jp01.add(autoConf, c01);
+	autoAuth= new JCheckBox("Add security (Authenticity)");
+        jp01.add(autoAuth, c01);
 	autoMapKeys= new JCheckBox("Add Keys");
 	jp01.add(autoMapKeys, c01);
 	
+	custom = new JCheckBox("Custom performance attributes");
+	jp01.add(custom,c01);
+	
+	jp01.add(new JLabel("Encryption Computational Complexity"),c01);
+	encTime = new JTextField(encCC);
+	jp01.add(encTime,c01);
+
+	jp01.add(new JLabel("Decryption Computational Complexity"),c01);
+	decTime = new JTextField(decCC);
+	jp01.add(decTime,c01);
+
+	jp01.add(new JLabel("Data Overhead (bits)"),c01);
+	secOverhead = new JTextField(secOv);
+	jp01.add(secOverhead,c01);
+	
 	jp1.add("Automated Security", jp01);
 
 	JPanel jp03 = new JPanel();
@@ -216,6 +244,21 @@ public class JDialogDSE extends javax.swing.JDialog implements ActionListener, R
 	jp03.add(simulationsPerMapping, c03);
 
 
+	secAnalysis = new JCheckBox("Security Analysis");
+	jp03.add(secAnalysis,c03);
+	
+	jp03.add(new JLabel("Encryption Computational Complexity"),c03);
+	encTime2 = new JTextField(encCC);
+	jp03.add(encTime2,c03);
+
+	jp03.add(new JLabel("Decryption Computational Complexity"),c03);
+	decTime2 = new JTextField(decCC);
+	jp03.add(decTime2,c03);
+
+	jp03.add(new JLabel("Data Overhead (bits)"),c03);
+	secOverhead2 = new JTextField(secOv);
+	jp03.add(secOverhead2,c03);
+
 	jp1.add("Mapping Exploration", jp03);
 
 	JPanel jp04 = new JPanel();
@@ -339,10 +382,16 @@ public class JDialogDSE extends javax.swing.JDialog implements ActionListener, R
         TraceManager.addDev("Thread started");
         File testFile;
 	if (jp1.getSelectedIndex() == 0){
-	    if (autoSecure.isSelected()){
-	    	TMLMapping map = mgui.gtm.autoSecure(mgui);
-		if (map!=null){
-		//drawMapping(map);
+	    encCC=encTime.getText();
+	    decCC=decTime.getText();
+	    secOv = secOverhead.getText();
+	    TMLMapping map;
+	    if (autoConf.isSelected() || autoAuth.isSelected()){
+		if (custom.isSelected()){
+		    map = mgui.gtm.autoSecure(mgui, encCC,secOv,decCC,autoConf.isSelected(), autoAuth.isSelected());
+		}
+		else {
+	    	    map = mgui.gtm.autoSecure(mgui,autoConf.isSelected(), autoAuth.isSelected());
 		}
 	    }
 	    if (autoMapKeys.isSelected()){
@@ -350,7 +399,20 @@ public class JDialogDSE extends javax.swing.JDialog implements ActionListener, R
 	    }
 	}
 	else if (jp1.getSelectedIndex()==1){
+	    encCC=encTime2.getText();
+	    decCC=decTime2.getText();
+	    secOv = secOverhead2.getText();
+
 	    DSEConfiguration config = new DSEConfiguration();
+	    config.addSecurity = secAnalysis.isSelected();
+	    config.encComp = encCC;
+	    config.overhead = secOv;
+	    config.decComp = decCC;
+
+	    config.mainGUI = mgui;
+	    TMLMapping map = mgui.gtm.getTMLMapping();
+	    config.tmlcdp = map.getTMLCDesignPanel();
+	    config.tmlap = map.tmlap;
 	    if (config.setModelPath(tmlDir) != 0) {
 		TraceManager.addDev("TML Directory file at " + tmlDir + " error");
 		checkMode();
@@ -405,8 +467,10 @@ public class JDialogDSE extends javax.swing.JDialog implements ActionListener, R
 		return;
 	    }
 	    if (config.setMinNbOfCPUs(NbMinCPU) != 0) {
+		TraceManager.addDev("Can't set Min # CPUS to " + NbMinCPU);
 	    }
 	    if (config.setMaxNbOfCPUs(NbMaxCPU) != 0) {
+		TraceManager.addDev("Can't set Max # CPUS to " + NbMaxCPU);
 	    }
 	    config.setOutputTXT("true");
 	   // config.setOutputHTML("true");
@@ -423,7 +487,7 @@ public class JDialogDSE extends javax.swing.JDialog implements ActionListener, R
 		output+="Simulation Succeeded";
 		outputText.setText(output);
 	    }
-	    if (config.runDSE("", true, true)!=0){
+	    if (config.runDSE("", false, false)!=0){
 		TraceManager.addDev("Can't run DSE");
 	    }
 	    System.out.println("DSE run");
@@ -492,33 +556,5 @@ public class JDialogDSE extends javax.swing.JDialog implements ActionListener, R
     public void setError() {
         hasError = true;
     }
-    public void drawMapping(TMLMapping map){
-	Map<HwNode, TGConnectingPoint> connectMap; 
-	int index = mgui.createTMLArchitecture("OptimalMapping");
-	TMLArchiPanel archPanel = (TMLArchiPanel) mgui.tabs.get(mgui.tabs.size()-1);
-	TMLArchiDiagramPanel ap = archPanel.tmlap;
-	TMLArchitecture arch = map.getArch();
-	ArrayList<HwNode> hwnodes = arch.getHwNodes();
-	ArrayList<HwLink> hwlinks = arch.getHwLinks();
-	int x=10;
-	int y=10;
-	for (HwNode node: hwnodes){
-	    if (node instanceof HwCPU){
-		TMLArchiCPUNode cpu = new TMLArchiCPUNode(x, y, ap.getMinX(), ap.getMaxX(), ap.getMinY(), ap.getMaxY(), false, null, ap);
-		x+=300;
-		cpu.setName(node.getName());
-		ap.addComponent(cpu, x, y, false, true);
-	    }
-	    else if (node instanceof HwMemory){
-		TMLArchiMemoryNode mem = new TMLArchiMemoryNode(x, y, ap.getMinX(), ap.getMaxX(), ap.getMinY(), ap.getMaxY(), false, null, ap);
-		x+=300;
-		mem.setName(node.getName());
-		ap.addComponent(mem, x, y, false, true);
-	    }
 
-	}
-	for (HwLink link: hwlinks){
-	    
-	}
-    }
 }