-
Notifications
You must be signed in to change notification settings - Fork 0
/
bufftest.c
65 lines (57 loc) · 1.93 KB
/
bufftest.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/********* bufftest.cc **********/
// From Schnier's blog. Author unknown.
// to compile and link this version, use
//g++ -Wall bufftest.c Blowfish.c -Wwrite-strings -o bufftest
//
// compile and link with base64 utility code
// g++ -Wall bufftest.c Blowfish.c -Wwrite-strings -fpermissive -o bufftest
// note: minimalist version.
//
// base64 code from:
// http://web.mit.edu/freebsd/head/contrib/wpa/src/utils/
//... some minor adaptations.
//
// Some other useful information:
// https://stackoverflow.com/questions/342409/how-do-i-base64-encode-decode-in-c
//
//
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include "Blowfish.h"
#include "base64.c"
#include <time.h>
using namespace std;
int main()
{
Blowfish BF;
double speed;
time_t begin,end;
char *buff;
buff = new char[48]; // encryption routine requires buffer to be created and allocated like this.
char *plain = (char*)"The rain on the plane falls mainly on my brain!!";
for (int incr = 0; incr < 48; incr++){ // the encryption routine does not tolerate any other way (segfaults)
buff[incr] = plain[incr];
} // for
begin = time(NULL);
printf("Before: %s\n", buff);
BF.Set_Passwd((char*)"xxxxxxxxxxxxxxxx");
printf("now going to encrypt and base64 encode for transport....\n");
BF.Encrypt((void *)buff,48);
size_t encodedlen;
//printf("encrypted... %s\n", buff);
unsigned char* encoded;
encoded = base64_encode((const unsigned char*)buff, 48, &encodedlen);
printf("encoded %i bytes\n", encodedlen);
printf("after encrypt and encode %s\n Now going to base64 decode and then decrypt...\n", encoded);
size_t decodedlen;
unsigned char* decoded;
decoded = base64_decode((const unsigned char*)encoded, encodedlen, &decodedlen);
printf("decoded %i bytes\n", decodedlen);
BF.Decrypt((void *)decoded,48);
printf("decrypted.... %s\n", decoded);
end = time(NULL);
speed = end-begin;
printf("Total time %i\n", speed);
return 1;
}