From: iceman1001 <iceman@iuse.se>
Date: Mon, 27 Oct 2014 18:46:21 +0000 (+0100)
Subject: Inital test for the "lf em4x 410xsim / lf em4x 410xwatch" which I try to verify that... 
X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/commitdiff_plain/2ae8a312e058f71d0f02be4f2f9cc6f284ebbf34?ds=inline;hp=1010aacca01ea823e5265babefa0d325863a2ba3

Inital test for the "lf em4x 410xsim / lf em4x 410xwatch" which I try to verify that the sim works.
Something about speed,  the clock detection is not so good.  should be 64,  usually 67..
---

diff --git a/armsrc/appmain.c b/armsrc/appmain.c
index b9ad1abd..d239ceb0 100644
--- a/armsrc/appmain.c
+++ b/armsrc/appmain.c
@@ -949,7 +949,6 @@ void UsbPacketReceived(uint8_t *packet, int len)
 		case CMD_DOWNLOADED_SIM_SAMPLES_125K: {
 			uint8_t *b = (uint8_t *)BigBuf;
 			memcpy(b+c->arg[0], c->d.asBytes, 48);
-			//Dbprintf("copied 48 bytes to %i",b+c->arg[0]);
 			cmd_send(CMD_ACK,0,0,0,0,0);
 			break;
 		}	
diff --git a/armsrc/lfops.c b/armsrc/lfops.c
index bf743c24..025314a0 100644
--- a/armsrc/lfops.c
+++ b/armsrc/lfops.c
@@ -450,13 +450,17 @@ void WriteTItag(uint32_t idhi, uint32_t idlo, uint16_t crc)
 void SimulateTagLowFrequency(int period, int gap, int ledcontrol)
 {
 	int i;
-	uint8_t *tab = (uint8_t *)BigBuf;
+	uint8_t *buff = (uint8_t *)BigBuf;
     
 	FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
+	FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 95); //125Khz
 	FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_EDGE_DETECT);
-    
-	AT91C_BASE_PIOA->PIO_PER = GPIO_SSC_DOUT | GPIO_SSC_CLK;
-    
+	SetAdcMuxFor(GPIO_MUXSEL_LOPKD);
+	
+	// Give it a bit of time for the resonant antenna to settle.
+	SpinDelay(150);
+	
+	AT91C_BASE_PIOA->PIO_PER = GPIO_SSC_DOUT | GPIO_SSC_CLK;    
 	AT91C_BASE_PIOA->PIO_OER = GPIO_SSC_DOUT;
 	AT91C_BASE_PIOA->PIO_ODR = GPIO_SSC_CLK;
     
@@ -476,7 +480,7 @@ void SimulateTagLowFrequency(int period, int gap, int ledcontrol)
 		if (ledcontrol)
 			LED_D_ON();
         
-		if(tab[i])
+		if(buff[i])
 			OPEN_COIL();
 		else
 			SHORT_COIL();
diff --git a/client/cmdlfem4x.c b/client/cmdlfem4x.c
index 1ce937d9..aa87132e 100644
--- a/client/cmdlfem4x.c
+++ b/client/cmdlfem4x.c
@@ -1,4 +1,4 @@
-//-----------------------------------------------------------------------------
+ //-----------------------------------------------------------------------------
 // Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
 //
 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
@@ -195,9 +195,27 @@ retest:
  *   0                     <-- stop bit, end of tag
  */
 int CmdEM410xSim(const char *Cmd)
-{
-  int i, n, j, h, binary[4], parity[4];
+{	
+	int i, n, j, h, binary[4], parity[4];
 
+	char cmdp = param_getchar(Cmd, 0);
+	uint8_t uid[5] = {0x00};
+
+	if (cmdp == 'h' || cmdp == 'H') {
+		PrintAndLog("Usage:  lf em4x sim <UID>");
+		PrintAndLog("");
+		PrintAndLog("     sample: lf em4x sim 0F0368568B");
+		return 0;
+	}
+
+	if (param_gethex(Cmd, 0, uid, 10)) {
+		PrintAndLog("UID must include 10 HEX symbols");
+		return 0;
+	}
+	
+	PrintAndLog("Starting simulating with UID %02X %02X %02X %02X %02X", uid[0],uid[1],uid[2],uid[3],uid[4]);
+	
+  
   /* clock is 64 in EM410x tags */
   int clock = 64;
 
@@ -271,10 +289,16 @@ int CmdEM410xWatch(const char *Cmd)
 	int read_h = (*Cmd == 'h');
 	do
 	{
+		if (ukbhit()) {
+			printf("\naborted via keyboard!\n");
+			break;
+		}
+		
 		CmdLFRead(read_h ? "h" : "");
-		CmdSamples("16000");	
+		CmdSamples("16000");
+		
 	} while (
-		!CmdEM410xRead("") 
+		!CmdEM410xRead("64") 
 	);
 	return 0;
 }
diff --git a/client/cmdlft55xx.c b/client/cmdlft55xx.c
index b4f884fe..9eaa6463 100644
--- a/client/cmdlft55xx.c
+++ b/client/cmdlft55xx.c
@@ -316,8 +316,8 @@ int CmdDump(const char *Cmd){
 	}
 	
 	if ( hasPwd ){
-		if (param_gethex(Cmd, 0, pwd, 4)) {
-			PrintAndLog("password must include 4 HEX symbols");
+		if (param_gethex(Cmd, 0, pwd, 8)) {
+			PrintAndLog("password must include 8 HEX symbols");
 			return 0;
 		}
 	}
diff --git a/client/graph.c b/client/graph.c
index 8974f4c3..98dc8043 100644
--- a/client/graph.c
+++ b/client/graph.c
@@ -36,8 +36,10 @@ void AppendGraph(int redraw, int clock, int bit)
 int ClearGraph(int redraw)
 {
   int gtl = GraphTraceLen;
-  GraphTraceLen = 0;
+  memset(GraphBuffer, 0x00, GraphTraceLen);
 
+  GraphTraceLen = 0;
+ 
   if (redraw)
     RepaintGraphWindow();
 
diff --git a/client/loclass/cipher.c b/client/loclass/cipher.c
index 8b1a523d..9c1c2cfd 100644
--- a/client/loclass/cipher.c
+++ b/client/loclass/cipher.c
@@ -1,5 +1,17 @@
 /*****************************************************************************
- * This file is part of iClassCipher. It is a reconstructon of the cipher engine
+ * WARNING
+ *
+ * THIS CODE IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY. 
+ * 
+ * USAGE OF THIS CODE IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL 
+ * PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL, 
+ * AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES. 
+ * 
+ * THIS CODE SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS. 
+ *
+ *****************************************************************************
+ *
+ * This file is part of loclass. It is a reconstructon of the cipher engine
  * used in iClass, and RFID techology.
  *
  * The implementation is based on the work performed by
@@ -18,9 +30,13 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with IClassCipher.  If not, see <http://www.gnu.org/licenses/>.
+ * along with loclass.  If not, see <http://www.gnu.org/licenses/>.
+ * 
+ * 
+ * 
  ****************************************************************************/
 
+
 #include "cipher.h"
 #include "cipherutils.h"
 #include <stdio.h>
diff --git a/client/loclass/cipher.h b/client/loclass/cipher.h
index 4bfbe0b7..176a2976 100644
--- a/client/loclass/cipher.h
+++ b/client/loclass/cipher.h
@@ -1,5 +1,17 @@
 /*****************************************************************************
- * This file is part of iClassCipher. It is a reconstructon of the cipher engine
+ * WARNING
+ *
+ * THIS CODE IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY. 
+ * 
+ * USAGE OF THIS CODE IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL 
+ * PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL, 
+ * AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES. 
+ * 
+ * THIS CODE SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS. 
+ *
+ *****************************************************************************
+ *
+ * This file is part of loclass. It is a reconstructon of the cipher engine
  * used in iClass, and RFID techology.
  *
  * The implementation is based on the work performed by
@@ -18,9 +30,13 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with IClassCipher.  If not, see <http://www.gnu.org/licenses/>.
+ * along with loclass.  If not, see <http://www.gnu.org/licenses/>.
+ * 
+ * 
+ * 
  ****************************************************************************/
 
+
 #ifndef CIPHER_H
 #define CIPHER_H
 #include <stdint.h>
diff --git a/client/loclass/cipherutils.c b/client/loclass/cipherutils.c
index 1e08cf10..8c6a278a 100644
--- a/client/loclass/cipherutils.c
+++ b/client/loclass/cipherutils.c
@@ -1,5 +1,17 @@
 /*****************************************************************************
- * This file is part of iClassCipher. It is a reconstructon of the cipher engine
+ * WARNING
+ *
+ * THIS CODE IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY. 
+ * 
+ * USAGE OF THIS CODE IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL 
+ * PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL, 
+ * AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES. 
+ * 
+ * THIS CODE SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS. 
+ *
+ *****************************************************************************
+ *
+ * This file is part of loclass. It is a reconstructon of the cipher engine
  * used in iClass, and RFID techology.
  *
  * The implementation is based on the work performed by
@@ -18,7 +30,10 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with IClassCipher.  If not, see <http://www.gnu.org/licenses/>.
+ * along with loclass.  If not, see <http://www.gnu.org/licenses/>.
+ * 
+ * 
+ * 
  ****************************************************************************/
 
 #include <stdint.h>
diff --git a/client/loclass/cipherutils.h b/client/loclass/cipherutils.h
index acf96115..cb090f69 100644
--- a/client/loclass/cipherutils.h
+++ b/client/loclass/cipherutils.h
@@ -1,5 +1,17 @@
 /*****************************************************************************
- * This file is part of iClassCipher. It is a reconstructon of the cipher engine
+ * WARNING
+ *
+ * THIS CODE IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY. 
+ * 
+ * USAGE OF THIS CODE IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL 
+ * PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL, 
+ * AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES. 
+ * 
+ * THIS CODE SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS. 
+ *
+ *****************************************************************************
+ *
+ * This file is part of loclass. It is a reconstructon of the cipher engine
  * used in iClass, and RFID techology.
  *
  * The implementation is based on the work performed by
@@ -18,9 +30,13 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with IClassCipher.  If not, see <http://www.gnu.org/licenses/>.
+ * along with loclass.  If not, see <http://www.gnu.org/licenses/>.
+ * 
+ * 
+ * 
  ****************************************************************************/
 
+
 #ifndef CIPHERUTILS_H
 #define CIPHERUTILS_H
 #include <stdint.h>
diff --git a/client/loclass/elite_crack.c b/client/loclass/elite_crack.c
index 1a464b6c..cba31808 100644
--- a/client/loclass/elite_crack.c
+++ b/client/loclass/elite_crack.c
@@ -1,3 +1,41 @@
+/*****************************************************************************
+ * WARNING
+ *
+ * THIS CODE IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY. 
+ * 
+ * USAGE OF THIS CODE IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL 
+ * PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL, 
+ * AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES. 
+ * 
+ * THIS CODE SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS. 
+ *
+ *****************************************************************************
+ *
+ * This file is part of loclass. It is a reconstructon of the cipher engine
+ * used in iClass, and RFID techology.
+ *
+ * The implementation is based on the work performed by
+ * Flavio D. Garcia, Gerhard de Koning Gans, Roel Verdult and
+ * Milosch Meriac in the paper "Dismantling IClass".
+ *
+ * Copyright (C) 2014 Martin Holst Swende
+ *
+ * This is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ *
+ * This file is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with loclass.  If not, see <http://www.gnu.org/licenses/>.
+ * 
+ * 
+ * 
+ ****************************************************************************/
+
 #include <stdint.h>
 #include <stdbool.h>
 #include <string.h>
@@ -526,13 +564,9 @@ int bruteforceFile(const char *filename, uint16_t keytable[])
 	fseek(f, 0, SEEK_SET);
 
 	uint8_t *dump = malloc(fsize);
-    size_t bytes_read = fread(dump, fsize, 1, f);
-
+	fread(dump, fsize, 1, f);
 	fclose(f);
-    if (bytes_read < fsize)
-    {
-        prnlog("Error, could only read %d bytes (should be %d)",bytes_read, fsize );
-    }
+
 	return bruteforceDump(dump,fsize,keytable);
 }
 /**
diff --git a/client/loclass/elite_crack.h b/client/loclass/elite_crack.h
index 21004e59..fb27355f 100644
--- a/client/loclass/elite_crack.h
+++ b/client/loclass/elite_crack.h
@@ -1,3 +1,42 @@
+/*****************************************************************************
+ * WARNING
+ *
+ * THIS CODE IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY. 
+ * 
+ * USAGE OF THIS CODE IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL 
+ * PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL, 
+ * AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES. 
+ * 
+ * THIS CODE SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS. 
+ *
+ *****************************************************************************
+ *
+ * This file is part of loclass. It is a reconstructon of the cipher engine
+ * used in iClass, and RFID techology.
+ *
+ * The implementation is based on the work performed by
+ * Flavio D. Garcia, Gerhard de Koning Gans, Roel Verdult and
+ * Milosch Meriac in the paper "Dismantling IClass".
+ *
+ * Copyright (C) 2014 Martin Holst Swende
+ *
+ * This is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ *
+ * This file is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with loclass.  If not, see <http://www.gnu.org/licenses/>.
+ * 
+ * 
+ * 
+ ****************************************************************************/
+
+
 #ifndef ELITE_CRACK_H
 #define ELITE_CRACK_H
 void permutekey(uint8_t key[8], uint8_t dest[8]);
diff --git a/client/loclass/fileutils.c b/client/loclass/fileutils.c
index 08e1c1a7..6d990171 100644
--- a/client/loclass/fileutils.c
+++ b/client/loclass/fileutils.c
@@ -1,3 +1,41 @@
+/*****************************************************************************
+ * WARNING
+ *
+ * THIS CODE IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY. 
+ * 
+ * USAGE OF THIS CODE IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL 
+ * PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL, 
+ * AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES. 
+ * 
+ * THIS CODE SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS. 
+ *
+ *****************************************************************************
+ *
+ * This file is part of loclass. It is a reconstructon of the cipher engine
+ * used in iClass, and RFID techology.
+ *
+ * The implementation is based on the work performed by
+ * Flavio D. Garcia, Gerhard de Koning Gans, Roel Verdult and
+ * Milosch Meriac in the paper "Dismantling IClass".
+ *
+ * Copyright (C) 2014 Martin Holst Swende
+ *
+ * This is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ *
+ * This file is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with loclass.  If not, see <http://www.gnu.org/licenses/>.
+ * 
+ * 
+ * 
+ ****************************************************************************/
+
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
@@ -45,6 +83,17 @@ int saveFile(const char *preferredName, const char *suffix, const void* data, si
 	return 0;
 }
 
+int loadFile(const char *fileName, void* data, size_t datalen)
+{
+	FILE *filehandle = fopen(fileName, "rb");
+	if(!filehandle) {
+		prnlog("Failed to read from file '%s'", fileName);
+		return 1;
+	}
+	fread(data,datalen,1,filehandle);
+	fclose(filehandle);
+	return 0;
+}
 /**
  * Utility function to print to console. This is used consistently within the library instead
  * of printf, but it actually only calls printf (and adds a linebreak).
diff --git a/client/loclass/fileutils.h b/client/loclass/fileutils.h
index a0f5a799..02cfcef9 100644
--- a/client/loclass/fileutils.h
+++ b/client/loclass/fileutils.h
@@ -1,3 +1,41 @@
+/*****************************************************************************
+ * WARNING
+ *
+ * THIS CODE IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY. 
+ * 
+ * USAGE OF THIS CODE IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL 
+ * PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL, 
+ * AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES. 
+ * 
+ * THIS CODE SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS. 
+ *
+ *****************************************************************************
+ *
+ * This file is part of loclass. It is a reconstructon of the cipher engine
+ * used in iClass, and RFID techology.
+ *
+ * The implementation is based on the work performed by
+ * Flavio D. Garcia, Gerhard de Koning Gans, Roel Verdult and
+ * Milosch Meriac in the paper "Dismantling IClass".
+ *
+ * Copyright (C) 2014 Martin Holst Swende
+ *
+ * This is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ *
+ * This file is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with loclass.  If not, see <http://www.gnu.org/licenses/>.
+ * 
+ * 
+ * 
+ ****************************************************************************/
+
 #ifndef FILEUTILS_H
 #define FILEUTILS_H
 /**
@@ -11,13 +49,22 @@
  * @return 0 for ok, 1 for failz
  */
 int saveFile(const char *preferredName, const char *suffix, const void* data, size_t datalen);
+/**
+ * @brief Utility function to save load binary data from a a file. This method takes a filename,
+ * Should only be used for fixed-size binary files
+ * @param fileName the name of the file
+ * @param data a buffer to place data in
+ * @param datalen the length of the data/data.
+ * @return
+ */
 
+int loadFile(const char *fileName, void* data, size_t datalen);
 
 /**
  * Utility function to print to console. This is used consistently within the library instead
  * of printf, but it actually only calls printf. The reason to have this method is to
  *make it simple to plug this library into proxmark, which has this function already to
- * write also to a logfile. When doing so, just point this function to use PrintAndLog
+ * write also to a logfile. When doing so, just delete this function.
  * @param fmt
  */
 void prnlog(char *fmt, ...);
diff --git a/client/loclass/ikeys.c b/client/loclass/ikeys.c
index cd2b72ee..b0528b5c 100644
--- a/client/loclass/ikeys.c
+++ b/client/loclass/ikeys.c
@@ -1,15 +1,23 @@
 /*****************************************************************************
- * This file is part of iClassCipher. It is a reconstructon of the cipher engine
+ * WARNING
+ *
+ * THIS CODE IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY. 
+ * 
+ * USAGE OF THIS CODE IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL 
+ * PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL, 
+ * AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES. 
+ * 
+ * THIS CODE SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS. 
+ *
+ *****************************************************************************
+ *
+ * This file is part of loclass. It is a reconstructon of the cipher engine
  * used in iClass, and RFID techology.
  *
  * The implementation is based on the work performed by
  * Flavio D. Garcia, Gerhard de Koning Gans, Roel Verdult and
  * Milosch Meriac in the paper "Dismantling IClass".
  *
- * This is a reference implementation of iclass key diversification. I'm sure it can be
- * optimized heavily. It is written for ease of understanding and correctness, please take it
- * and tweak it and make a super fast version instead, using this for testing and verification.
-
  * Copyright (C) 2014 Martin Holst Swende
  *
  * This is free software: you can redistribute it and/or modify
@@ -22,8 +30,12 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with IClassCipher.  If not, see <http://www.gnu.org/licenses/>.
+ * along with loclass.  If not, see <http://www.gnu.org/licenses/>.
+ * 
+ * 
+ * 
  ****************************************************************************/
+
 /**
 
 
@@ -391,7 +403,7 @@ void diversifyKey(uint8_t csn[8], uint8_t key[8], uint8_t div_key[8])
 
 	//Calculate HASH0(DES))
     uint64_t crypt_csn = x_bytes_to_num(crypted_csn, 8);
-    //uint64_t crypted_csn_swapped = swapZvalues(crypt_csn);
+	uint64_t crypted_csn_swapped = swapZvalues(crypt_csn);
 
 	hash0(crypt_csn,div_key);
 }
diff --git a/client/loclass/ikeys.h b/client/loclass/ikeys.h
index 1de46b62..13096194 100644
--- a/client/loclass/ikeys.h
+++ b/client/loclass/ikeys.h
@@ -1,3 +1,41 @@
+/*****************************************************************************
+ * WARNING
+ *
+ * THIS CODE IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY. 
+ * 
+ * USAGE OF THIS CODE IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL 
+ * PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL, 
+ * AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES. 
+ * 
+ * THIS CODE SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS. 
+ *
+ *****************************************************************************
+ *
+ * This file is part of loclass. It is a reconstructon of the cipher engine
+ * used in iClass, and RFID techology.
+ *
+ * The implementation is based on the work performed by
+ * Flavio D. Garcia, Gerhard de Koning Gans, Roel Verdult and
+ * Milosch Meriac in the paper "Dismantling IClass".
+ *
+ * Copyright (C) 2014 Martin Holst Swende
+ *
+ * This is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ *
+ * This file is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with loclass.  If not, see <http://www.gnu.org/licenses/>.
+ * 
+ * 
+ * 
+ ****************************************************************************/
+
 #ifndef IKEYS_H
 #define IKEYS_H
 
diff --git a/client/loclass/main.c b/client/loclass/main.c
index 42019072..b7ea53e5 100644
--- a/client/loclass/main.c
+++ b/client/loclass/main.c
@@ -1,5 +1,17 @@
 /*****************************************************************************
- * This file is part of iClassCipher. It is a reconstructon of the cipher engine
+ * WARNING
+ *
+ * THIS CODE IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY. 
+ * 
+ * USAGE OF THIS CODE IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL 
+ * PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL, 
+ * AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES. 
+ * 
+ * THIS CODE SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS. 
+ *
+ *****************************************************************************
+ *
+ * This file is part of loclass. It is a reconstructon of the cipher engine
  * used in iClass, and RFID techology.
  *
  * The implementation is based on the work performed by
@@ -18,9 +30,13 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with IClassCipher.  If not, see <http://www.gnu.org/licenses/>.
+ * along with loclass.  If not, see <http://www.gnu.org/licenses/>.
+ * 
+ * 
+ * 
  ****************************************************************************/
 
+
 #include <stdio.h>
 #include <cipherutils.h>
 #include <stdint.h>
@@ -62,9 +78,22 @@ int showHelp()
 
 int main (int argc, char **argv)
 {
+
+
 	prnlog("IClass Cipher version 1.2, Copyright (C) 2014 Martin Holst Swende\n");
 	prnlog("Comes with ABSOLUTELY NO WARRANTY");
-	prnlog("This is free software, and you are welcome to use, abuse and repackage, please keep the credits\n");
+	prnlog("Released as GPLv2\n");
+	prnlog("WARNING");
+	prnlog("");
+	prnlog("THIS TOOL IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY. ");
+	prnlog("");
+	prnlog("USAGE OF THIS TOOL IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL ");
+	prnlog("PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL, ");
+	prnlog("AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES. ");
+	prnlog("");
+	prnlog("THIS TOOL SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS. ");
+
+
 	char *fileName = NULL;
 	int c;
 	while ((c = getopt (argc, argv, "thf:")) != -1)