#include #include #include #include int linetest() { FILE *in; if((in = fopen("x", "rb")) == NULL) { fprintf(stderr, "oops, could not open file!\n"); return 1; } Pcpstream *pin = ps_new_file(in); ps_setdetermine(pin, 8); size_t got; byte data[9] = {0}; while(!ps_end(pin)) { if((got = ps_read(pin, data, 8)) > 0) { fwrite(data, 1, got, stdout); } } ps_close(pin); return 0; } int main() { /* create a file with "encrypted" data */ return linetest(); FILE *out, *in; unsigned char clear[8] = "ABCDEFGH"; unsigned char key[8] = "IxD8Lq1K"; unsigned char crypt[8] = {0}; int blocks = 8; size_t blocksize = 4; int i = 0; if((out = fopen("teststream.out", "wb+")) == NULL) { fprintf(stderr, "oops, could not open file!\n"); return 1; } /* out output stream, z85 encoded, use z85 blocksize 8 */ Pcpstream *pout = ps_new_file(out); ps_print(pout, "~~~~~ BEGIN ~~~~~\r\n"); ps_armor(pout, blocksize); /* "encrypt" a couple of times into the output stream */ for(i=0; iarmor = 0; ps_print(pout, "\r\n~~~~~ END ~~~~~\r\n"); ps_close(pout); fclose(out); /* read it in again using an input stream */ if((in = fopen("teststream.out", "rb")) == NULL) { fprintf(stderr, "oops, could not open file!\n"); return 1; } Pcpstream *pin = ps_new_file(in); /* enable autmatically encoding detection. */ ps_setdetermine(pin, blocksize); /* we'll use this stream to put the "decrypted" data in. note, that this could be a file as well. */ Pcpstream *pclear = ps_new_outbuffer(); /* read and "decrypt" */ for(i=0; i