diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..838aa8eded147d0efa9f6f65ec5b2386b63a6534
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+*.o
+playunfair
+*.out
diff --git a/include/playfair.h b/include/playfair.h
index d3fb0666978888ee867fe737bdce6e16d9c04357..51675d44d53931cfc77a9cbdccfb4962c74ef914 100644
--- a/include/playfair.h
+++ b/include/playfair.h
@@ -3,5 +3,5 @@
 #include <vector>
 #include <iterator>
 
-std::vector< std::vector<char> > createKM ( const std::string key);
+std::vector< char > createKM ( const std::string key);
 std::string playfair(std::string text , const std::string key );
diff --git a/playfair.cpp b/playfair.cpp
index ec049112ac7847cb53de2c29b842ba4fea418d22..3bed308329bd8eaf1e144b4407d52d08f6ecb33e 100644
--- a/playfair.cpp
+++ b/playfair.cpp
@@ -3,9 +3,10 @@
 
 #define _charbit(X) (1 << (X - 'a'))
 
-
-std::vector< std::vector<char> > createKM ( const std::string key){
-	std::vector< std::vector<char> > mKey(5, std::vector<char>(5));
+//Base idea is to use an 32-bit int as mask to detect which char
+// is already on the matrix
+std::vector< char > createKM ( const std::string key){
+	std::vector< char > mKey(25);
 	std::string abc(key + "abcdefghijklmnopqrstuvxwyz");
 	int mask =0;
 	//mask with 32 bits for the 25 letter alfabet
@@ -20,21 +21,42 @@ std::vector< std::vector<char> > createKM ( const std::string key){
 				mask = mask | (_charbit('j') | _charbit('i'));
 			}
 
-			mKey[i][j] = abc[si];
+			mKey[i*5 + j] = abc[si];
 		}
 	}
 	return mKey;
 }
 
 std::string playfair(std::string text, const std::string key){
-	std::vector< std::vector <char> > mKey(createKM(key));
+	std::ostringstream ret;
+	std::vector< char > mKey(createKM(key));
 	for (int i=0; i<5; ++i){
 		for (int j=0; j<5; ++j){
-			std::cout << mKey[i][j] << ' ';
+			std::cout << mKey[i*5 + j] << ' ';
 		}
 		std::cout << std::endl;
 	}
 
+	int indexT = -1;
+	char fst = text[++indexT];
+	char snd = text[++indexT];
+	if (fst == snd && snd != 'x'){
+		snd = 'x';
+		--indexT;
+	}
+
+	int iFst, iSnd;
+
+	for (int i=0; i<25; ++i){
+		if(mKey[i] == fst){
+			iFst=i;
+		}
+		if(mKey[i] == snd){
+			iSnd=i;
+		}
+	}
+	char retfst,retsnd;
+	retfst = mKey[iFst/5 + iSnd%5]
 
 	//TODO:change
 	return text;
diff --git a/playfair.o b/playfair.o
deleted file mode 100644
index bd96c5f689a85f39d9613e64fa6e361a62a73fe1..0000000000000000000000000000000000000000
Binary files a/playfair.o and /dev/null differ
diff --git a/playunfair b/playunfair
deleted file mode 100755
index 25214f30dda0255c6fca59324b72bb581049e10a..0000000000000000000000000000000000000000
Binary files a/playunfair and /dev/null differ
diff --git a/playunfair.o b/playunfair.o
deleted file mode 100644
index 060fc99a4b5e7b17bbf29b8304eccd926094093d..0000000000000000000000000000000000000000
Binary files a/playunfair.o and /dev/null differ