00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004
00005 #include "nixsys.h"
00006 #include "blowfish.h"
00007
00008 using namespace n2nc;
00009
00010 int main(int argc, char *argv[]){
00011 void *buf = malloc(264);
00012 void *buf2 = malloc(264);
00013
00014 char *str = "AncripteDncripteFncriptA" ;
00015 char *str1= "BncripteDncripteFncriptB" ;
00016 char *str2= "CncripteDncripteFncriptC" ;
00017 security::BlowFish::key_t key ;
00018 strncpy((char*)key.key,"0123456789012345",16) ;
00019 int fd = open("examples/out",0);
00020 int outw,n, written, c ,i;
00021 std::cerr << "strlen:" << strlen(str) << std::endl;
00022 security::BlowFish bf(&key), bf2(&key) ;
00023 char ivnull[8];
00024 bzero (ivnull,8);
00025
00026 if (argc < 2){
00027 std::cerr << "encripting" << std::endl ;
00028 outw = 0 ;
00029 while(n = ::read(0,buf,256)){
00030 bf.reinit();
00031 outw = bf.encrypt(buf, buf2,n);
00032 ::write(1,buf2,outw);
00033 std::cerr << "written: " << outw << std::endl ;
00034 }
00035 }else{
00036 outw = 0 ;
00037 std::cerr << "decripting" << std::endl ;
00038
00039 while(n = ::read(0,buf,264)){
00040 bf.reinit();
00041 outw = bf.decrypt(buf, buf2,n);
00042 if (outw< 0) exit(1);
00043 ::write(1,buf2,outw);
00044 std::cerr << "written: " << outw << std::endl ;
00045 }
00046 }
00047 return EXIT_SUCCESS;
00048
00049
00050
00051
00052
00053
00054
00055 for(i=0 ; i<100 ; i++){
00056 written = bf.encrypt((void*)str,buf,strlen(str));
00057 c = bf2.decrypt( (void*) ((uint)buf + 0),buf2,written);
00058 std::cerr << (char*)buf2 +8 << "\twlen:" << written << " desize:" << c << std::endl ;
00059 }
00060
00061 written = bf.encrypt((void*)str,buf,strlen(str));
00062 c = bf2.decrypt( (void*) ((uint)buf + 0),buf2,written);
00063 std::cerr << (char*)buf2 << "\twlen:" << written << " desize:" << c << std::endl ;
00064
00065
00066
00067
00068
00069 written = bf.encrypt((void*)str1,buf,strlen(str));
00070 c = bf2.decrypt( (void*) ((uint)buf + 0),buf2,written);
00071 std::cerr << (char*)buf2 << "\twlen:" << written << " desize:" << c << std::endl ;
00072
00073 written = bf.encrypt((void*)str2,buf,strlen(str));
00074 c = bf2.decrypt( (void*) ((uint)buf + 0),buf2,written);
00075 std::cerr << (char*)buf2 << "\twlen:" << written << " desize:" << c << std::endl ;
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088 return EXIT_SUCCESS;
00089 }
00090