 #define ASCII_CHARS 128
 
 
+int mod(int a, int b) {
+    
+    return (a%b+b)%b;
+}
 
 void printrow(float *msg_v_list) {
     int i;

        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;
    }
    
    printf("PValue: %f\n", Pvalue);
    result[ty * matrix_dims + tx] = (int)Pvalue%ASCII_CHARS;
    printf("result: %f\n", result[ty * matrix_dims + tx]);
}

void secretKey(float **SKey, float **invSKey, int matrix_dims) {


    cudaMemcpy(secretGpu, *invSKey, nBytes, cudaMemcpyHostToDevice);
    for (i = 0; i < msg_parts; i++) {
        cudaMemcpy(msgGpu, results[i], nBytes, cudaMemcpyHostToDevice);
        mtxEncrypt<<<grid, block>>>(secretGpu, msgGpu, resultGpu, matrix_dims);
        cudaMemcpy(unEncrypted[i], resultGpu, nBytes, cudaMemcpyDeviceToHost);
        cudaDeviceSynchronize();
    }
    for (i = 0; i < msg_parts; i++) {
        for (j = 0; j < matrix_size; j++) {
            printf("%c", (int)unEncrypted[i][j], char((int)unEncrypted[i][j]));
        }
    }
    free(results);
