X-Git-Url: https://hackdaworld.org/gitweb/?p=my-code%2Fcrypto.git;a=blobdiff_plain;f=test.c;fp=test.c;h=a2e7067dafa894f0a3eb710e9f4d9ec5502bd0ea;hp=0000000000000000000000000000000000000000;hb=bda14e4049f762cebc83d71f23949c0ec44b1c79;hpb=967ba6ad8f3dbdf974e29e92badcd25af47baf6f diff --git a/test.c b/test.c new file mode 100644 index 0000000..a2e7067 --- /dev/null +++ b/test.c @@ -0,0 +1,60 @@ +/* + * test.c - test ciphers ... + * + * hackbard@hackdaworld.dyndns.org + * + */ + +#include +#include +#include +#include + +#include "des.h" + + +int main() { + u8 plain[64]; + u8 crypted[64]; + u8 key[8]; + int fd,i; + + if((fd=open("/dev/urandom",O_RDONLY))<0) { + puts("open urandom device failed!"); + return fd; + } + + printf("des crypt/decrypt test:\n"); + printf("- geberating random key ...\n"); + read(fd,key,8); + printf("key: "); + for(i=0;i<8;i++) printf("%02x ",key[i]); + puts(""); + + memset(plain,0,64); + strcpy(plain,"allyouratmels ... :)"); + + printf("encrypting '%s' (ecb mode) ...\n",plain); + memset(crypted,0,64); + des_encrypt(plain,crypted,key,64,MODE_ECB); + printf("crypted: "); + for(i=0;i<64;i++) printf("%c",crypted[i]); + puts(""); + printf("encrypting '%s' (cbc mode) ...\n",plain); + memset(crypted,0,64); + des_encrypt(plain,crypted,key,64,MODE_CBC); + printf("crypted: "); + for(i=0;i<64;i++) printf("%c",crypted[i]); + puts(""); + + printf("--\n"); + printf("verify:\n"); + des_decrypt(crypted,plain,key,64,MODE_CBC); + printf("plain text: "); + for(i=0;i<64;i++) printf("%c",plain[i]); + puts(""); + + puts("done :)"); + + return 1; +}