2016-04-14 14:47:11 +00:00
|
|
|
|
2016-04-14 15:27:11 +00:00
|
|
|
#include <stdio.h>
|
2016-04-15 20:30:41 +00:00
|
|
|
#include <string.h>
|
2016-04-14 15:27:11 +00:00
|
|
|
#include "constants.h"
|
|
|
|
#include "cipher.h"
|
|
|
|
|
2016-04-15 20:30:41 +00:00
|
|
|
void encrypt_file(char * filename, u8 * password) {
|
|
|
|
FILE * in = fopen(filename, "rb");
|
|
|
|
FILE * out = fopen("encrypted.speck", "wb");
|
|
|
|
|
|
|
|
if ( !in ) {
|
|
|
|
perror("Error opening file.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void decrypt_file(char * filename, u8 * password) {
|
|
|
|
FILE * in = fopen(filename, "rb");
|
|
|
|
FILE * out = fopen("decrypted.speck", "wb");
|
|
|
|
|
|
|
|
|
|
|
|
if ( !in ) {
|
|
|
|
perror("Error opening file.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main (int argc, char *argv[]) {
|
|
|
|
|
|
|
|
if ( argc != 4) {
|
|
|
|
printf("Invalid usage! Correct usage %s filname password [1/0 which represent"\
|
|
|
|
"encrypt or decrypt]\n", argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
char * password = argv[2];
|
|
|
|
u8 inputKey[strlen(password) - 1];
|
|
|
|
int i = 0;
|
|
|
|
for (; password[i]; i++) {
|
|
|
|
inputKey[i] = password[i];
|
|
|
|
}
|
|
|
|
u8 keys[SPECK_BLOCK_SIZE/16*SPECK_ROUNDS];
|
|
|
|
encryptKeySchedule(inputKey, keys);
|
|
|
|
|
|
|
|
u8 plainText[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// printf("PlainText: %c, %c, %c, %c, %c, %c, %c, %c\n",
|
|
|
|
// plainText[0], plainText[1], plainText[2], plainText[3],
|
|
|
|
// plainText[4], plainText[5], plainText[6], plainText[7]);
|
|
|
|
//
|
|
|
|
// encrypt(plainText, keys);
|
|
|
|
//
|
|
|
|
// printf("After encryption: %c, %c, %c, %c, %c, %c, %c, %c\n",
|
|
|
|
// plainText[0], plainText[1], plainText[2], plainText[3],
|
|
|
|
// plainText[4], plainText[5], plainText[6], plainText[7]);
|
|
|
|
//
|
|
|
|
// decrypt(plainText, keys);
|
|
|
|
// printf("After decryption: %c, %c, %c, %c, %c, %c, %c, %c\n",
|
|
|
|
// plainText[0], plainText[1], plainText[2], plainText[3],
|
|
|
|
// plainText[4], plainText[5], plainText[6], plainText[7]);
|
|
|
|
|
2016-04-14 15:27:11 +00:00
|
|
|
return 0;
|
2016-04-14 14:47:11 +00:00
|
|
|
}
|