 #include <stdlib.h>
 #include <cuda_runtime.h>
 
-#define ASCII 128
-
-__global__ void mtxEncrypt(float *secretKey, float *msg, float *result, int matrix_size) {
+#define ASCII_CHARS 128
+
+__global__ void mtxEncrypt(float *secretKey, float *msg, float *result, int matrix_dims) {
     int tx = threadIdx.x;
     int ty = threadIdx.y;
     float Pvalue = 0;
-
-    for (int k = 0; k < matrix_size; ++k) {
-        float secretElement = secretKey[ty * matrix_size + k];
-        float msgElement = msg[k * matrix_size + tx];
+  
+  //  printf("secretKey: %3.1f, *secretKey: %3.1f, &secretKey: %3.1f, *msg: %3.1f\n", secretKey, *secretKey, &secretKey, *msg);
+    for (int k = 0; k < matrix_dims; ++k) {
+   //     printf("secretkey[k]: %    
+        float secretElement = secretKey[ty * matrix_dims + k];
+        float msgElement = msg[k * matrix_dims + tx];
+        
+  //      printf("\nMultiplying %f by %f: \n", secretElement, msgElement);
         Pvalue  += secretElement * msgElement;
     }
-    result[ty * matrix_size + tx] = Pvalue;
-}
-
-void secretKey(int **SKey, int **invSKey, int matrix_dims) {
+    
+//    printf("PValue: %d", (int)Pvalue%ASCII_CHARS);
+    result[ty * matrix_dims + tx] = (int)Pvalue%ASCII_CHARS;
+}
+
+void secretKey(float **SKey, float **invSKey, int matrix_dims) {
     int k,z;
     //*SKey = malloc((matrix_dims*sizeof(*SKey)) + matrix_dims*matrix_dims*sizeof(int **));
     //*invSKey = malloc(matrix_dims*matrix_dims*sizeof(int *));
 
-    int xSKey[4][4] = {{8, 6, 9, 5},
+    float xSKey[4][4] = {{8, 6, 9, 5},
                 {6, 9, 5, 10},
                 {5, 8, 4, 9},
                 {10, 6, 11, 4}};
-    int xinvSKey[4][4] = {{-3, 20, -21, 1},
+    float xinvSKey[4][4] = {{-3, 20, -21, 1},
                     {2, -41, 44, 1},
                     {2, -6, 6, -1},
                     {-1, 28, -30, -1}};

    strcat(msg, space);
}

void encode_msg(char *msg, int *msg_vector, int matrix_dims) {
    int matrix_size = matrix_dims * matrix_dims;
    int i = 0, j;


        for (j = 0; j < 4; j++) {
            SKey[0][i*matrix_dims + j] = xSKey[i][j];
            invSKey[0][i*matrix_dims + j] = xinvSKey[i][j];
            printf("%f :  %f \n", i*matrix_dims + j, SKey[0][i*matrix_dims + j]);
        }
    }
}
