Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <stddef.h>
- #include <stdint.h>
- #include <limits.h>
- #include <math.h>
- #include <time.h>
- /* Defines/Macros
- _____________________________________________________________*/
- #define FFE_AXES_ARGS 4
- #define FFE_SECRET_KEY_ARGS 13
- #define FFE_CMDLINE_ARGS 4
- #define FFE_JULIA_N 3
- #define FFE_BUFSZ (1024 * 1024 * 4)
- #define FFE_ERROR 0x1
- #define FFE_BYTESZ (UCHAR_MAX + 1)
- #define FFE_PREC "%.13lf"
- #define FFE_MIN(mp_n0, mp_n1) \
- ((mp_n0) < (mp_n1) ? (mp_n0) : (mp_n1))
- #define RN ffe_util_random
- /* Conversions
- _____________________________________________________________*/
- int
- ffe_cnv_uint_from_buffer(
- const char* buf,
- unsigned int* pret
- ){
- unsigned int ret = 0;
- if (sscanf(buf, "%u", &ret) == 1)
- {
- *pret = ret;
- return 0;
- }
- return FFE_ERROR;
- }
- int
- ffe_cnv_double_to_string_to_double(
- double n,
- double* pret
- ){
- char nbuf[UCHAR_MAX + 1] = { '\0' };
- if (sprintf(nbuf, FFE_PREC, n))
- {
- if (sscanf(nbuf, "%lf", pret) == 1)
- {
- return 0;
- }
- }
- return FFE_ERROR;
- }
- /* Utility
- _____________________________________________________________*/
- size_t
- ffe_util_cantor_packing(
- size_t n0,
- size_t n1
- ){
- size_t ret = (size_t)(0.5 * (n0 + n1) * (n0 + n1 + 1) + n1);
- return ret;
- }
- double
- ffe_util_random(void)
- {
- return (rand() / (RAND_MAX - 1.0));
- }
- double
- ffe_util_random_sign(double n)
- {
- return (ffe_util_random() < 0.5) ? (n) : (-n);
- }
- /* A 2d point
- _____________________________________________________________*/
- struct ffe_point
- {
- double x;
- double y;
- };
- struct ffe_point
- ffe_complex_add(
- struct ffe_point n0,
- struct ffe_point n1
- ){
- struct ffe_point ret = { n0.x + n1.x, n0.y + n1.y };
- return ret;
- }
- struct ffe_point
- ffe_complex_mul(
- struct ffe_point n0,
- struct ffe_point n1
- ){
- struct ffe_point ret = {
- n0.x * n1.x - n0.y * n1.y,
- n0.x * n1.y + n0.y * n1.x
- };
- return ret;
- }
- /* Axes describing a 2d plane
- _____________________________________________________________*/
- struct ffe_axes
- {
- double xmin;
- double xmax;
- double ymin;
- double ymax;
- };
- /* The Secret Key
- _____________________________________________________________*/
- struct ffe_secret_key
- {
- unsigned int iters;
- struct ffe_point scale;
- struct ffe_point julia[FFE_JULIA_N];
- struct ffe_axes axes;
- };
- int
- ffe_secret_key_output_status(
- struct ffe_secret_key const* const self,
- FILE* out_file
- ){
- if (fprintf(out_file,
- "Secret Key:\r\n"
- "____________________________________________\r\n"
- "iters: %u\r\n"
- "scale: (" FFE_PREC ", " FFE_PREC ")\r\n"
- "julia0: (" FFE_PREC ", " FFE_PREC ")\r\n"
- "julia1: (" FFE_PREC ", " FFE_PREC ")\r\n"
- "julia2: (" FFE_PREC ", " FFE_PREC ")\r\n"
- "axes: (" FFE_PREC ", " FFE_PREC "\r\n "
- FFE_PREC ", " FFE_PREC ")\r\n"
- "____________________________________________\r\n\r\n",
- self->iters,
- self->scale.x, self->scale.y,
- self->julia[0].x, self->julia[0].y,
- self->julia[1].x, self->julia[1].y,
- self->julia[2].x, self->julia[2].y,
- self->axes.xmin, self->axes.xmax,
- self->axes.ymin, self->axes.ymax
- ) > 0)
- {
- return 0;
- }
- return FFE_ERROR;
- }
- int
- ffe_secret_key_parse_from_file(
- struct ffe_secret_key* const self,
- FILE* in_file
- ){
- int ret = fscanf(
- in_file,
- "iters:%u\r\n"
- "scale:(%lf, %lf)\r\n"
- "julia0:(%lf, %lf)\r\n"
- "julia1:(%lf, %lf)\r\n"
- "julia2:(%lf, %lf)\r\n"
- "axes:(%lf, %lf, %lf, %lf)",
- &self->iters,
- &self->scale.x, &self->scale.y,
- &self->julia[0].x, &self->julia[0].y,
- &self->julia[1].x, &self->julia[1].y,
- &self->julia[2].x, &self->julia[2].y,
- &self->axes.xmin, &self->axes.xmax,
- &self->axes.ymin, &self->axes.ymax
- );
- if (ret == FFE_SECRET_KEY_ARGS)
- {
- return 0;
- }
- return FFE_ERROR;
- }
- int
- ffe_secret_key_store_to_file(
- struct ffe_secret_key const* const self,
- FILE* out_file
- ){
- int ret = fprintf(
- out_file,
- "iters:%u\r\n"
- "scale:(" FFE_PREC ", " FFE_PREC ")\r\n"
- "julia0:(" FFE_PREC ", " FFE_PREC ")\r\n"
- "julia1:(" FFE_PREC ", " FFE_PREC ")\r\n"
- "julia2:(" FFE_PREC ", " FFE_PREC ")\r\n"
- "axes:(" FFE_PREC ", " FFE_PREC ", "
- FFE_PREC ", " FFE_PREC ")",
- self->iters,
- self->scale.x, self->scale.y,
- self->julia[0].x, self->julia[0].y,
- self->julia[1].x, self->julia[1].y,
- self->julia[2].x, self->julia[2].y,
- self->axes.xmin, self->axes.xmax,
- self->axes.ymin, self->axes.ymax
- );
- if (ret > 0)
- {
- return 0;
- }
- return FFE_ERROR;
- }
- /* The Salt
- _____________________________________________________________*/
- struct ffe_salt
- {
- struct ffe_axes axes;
- };
- int
- ffe_salt_output_status(
- struct ffe_salt* const self,
- FILE* out_file
- ){
- if (fprintf(out_file,
- "Salt:\r\n"
- "____________________________________________\r\n"
- "xmin = " FFE_PREC "\r\n"
- "xmax = " FFE_PREC "\r\n"
- "ymin = " FFE_PREC "\r\n"
- "ymax = " FFE_PREC "\r\n"
- "____________________________________________\r\n\r\n",
- self->axes.xmin, self->axes.xmax,
- self->axes.ymin, self->axes.ymax) > 0)
- {
- return 0;
- }
- return FFE_ERROR;
- }
- int
- ffe_salt_parse_from_file(
- struct ffe_salt* const self,
- FILE* in_file,
- unsigned char* buf,
- size_t bufsz,
- size_t* pin_file_size
- ){
- int ret = fscanf(
- in_file,
- "axes:(%lf, %lf, %lf, %lf)\r\n",
- &self->axes.xmin, &self->axes.xmax,
- &self->axes.ymin, &self->axes.ymax
- );
- if (ret == FFE_AXES_ARGS)
- {
- size_t size = 0;
- size_t rbytes = 0;
- long offset = ftell(in_file);
- if (offset > 0)
- {
- while ((rbytes = fread(buf, 1, bufsz, in_file)))
- {
- size += rbytes;
- printf("Parsing salt %lu bytes...\r", (unsigned long)size);
- }
- printf("\r\n\r\n");
- *pin_file_size = size;
- if (! fseek(in_file, offset, SEEK_SET))
- {
- if (pin_file_size)
- {
- return 0;
- }
- }
- }
- }
- return FFE_ERROR;
- }
- int
- ffe_salt_generate_from_file(
- struct ffe_salt* const self,
- FILE* in_file,
- unsigned char* buf,
- size_t bufsz,
- size_t* pin_file_size
- ){
- size_t size = 0;
- size_t rbytes = 0;
- size_t pack = 0;
- while ((rbytes = fread(buf, 1, bufsz, in_file)))
- {
- size += rbytes;
- for (size_t i = 0; i < rbytes; ++i)
- {
- pack = (pack + ffe_util_cantor_packing(pack, buf[i])) % SIZE_MAX;
- }
- printf("Generating salt %lu bytes...\r", (unsigned long)size);
- }
- printf("\r\n\r\n");
- *pin_file_size = size;
- rewind(in_file);
- if (! ferror(in_file))
- {
- if (pin_file_size)
- {
- double pack_m[4] = {
- fmod(pow(pack, RN() * 0.3 + 0.3), 0.3 + RN() * 0.6),
- fmod(pow(pack, RN() * 0.3 + 0.3), 0.3 + RN() * 0.6),
- fmod(pow(pack, RN() * 0.3 + 0.3), 0.3 + RN() * 0.6),
- fmod(pow(pack, RN() * 0.3 + 0.3), 0.3 + RN() * 0.6)
- };
- ffe_cnv_double_to_string_to_double(pack_m[0], &pack_m[0]);
- ffe_cnv_double_to_string_to_double(pack_m[1], &pack_m[1]);
- ffe_cnv_double_to_string_to_double(pack_m[2], &pack_m[2]);
- ffe_cnv_double_to_string_to_double(pack_m[3], &pack_m[3]);
- self->axes.xmin = pack_m[0];
- self->axes.xmax = pack_m[1];
- self->axes.ymin = pack_m[2];
- self->axes.ymax = pack_m[3];
- return 0;
- }
- }
- return FFE_ERROR;
- }
- int
- ffe_salt_store_to_file(
- struct ffe_salt const* const self,
- FILE* out_file
- ){
- int ret = fprintf(
- out_file,
- "axes:(" FFE_PREC ", " FFE_PREC ", "
- FFE_PREC ", " FFE_PREC ")\r\n",
- self->axes.xmin, self->axes.xmax,
- self->axes.ymin, self->axes.ymax
- );
- if (ret > 1)
- {
- if (! ferror(out_file))
- {
- return 0;
- }
- }
- return FFE_ERROR;
- }
- /* Funny Fractal Encryption
- _____________________________________________________________*/
- struct ffe
- {
- unsigned char* buf;
- size_t bufsz;
- };
- struct ffe_cipher
- {
- size_t in_file_size;
- unsigned int dims;
- struct ffe_secret_key const* skey;
- struct ffe_salt salt;
- };
- struct ffe_mutator
- {
- unsigned int iters;
- struct ffe_point z;
- double min_orbit_trap;
- };
- int
- ffe_create(
- struct ffe* const self,
- size_t bufsz
- ){
- self->buf = malloc(bufsz);
- if (self->buf)
- {
- self->bufsz = bufsz;
- return 0;
- }
- return FFE_ERROR;
- }
- void
- ffe_destroy(
- struct ffe* const self
- ){
- free(self->buf);
- }
- int
- ffe_cipher_iterate_point(
- struct ffe_cipher const* const cipher,
- struct ffe_point const* c,
- struct ffe_mutator* mutator
- ){
- struct ffe_point z = *c;
- double min_orbit_trap = 99999999999999.0;
- double orbit_escape = 2.0 + (
- fabs(cipher->skey->julia[0].x) + fabs(cipher->skey->julia[0].y) +
- fabs(cipher->skey->julia[1].x) + fabs(cipher->skey->julia[1].y) +
- fabs(cipher->skey->julia[2].x) + fabs(cipher->skey->julia[2].y)
- );
- for (size_t i = 0; i < cipher->skey->iters; ++i)
- {
- z = ffe_complex_mul(z, z);
- z = ffe_complex_add(z, cipher->skey->julia[i % FFE_JULIA_N]);
- z = ffe_complex_mul(z, cipher->skey->scale);
- double orbit_dis = sqrt(z.x * z.x + z.y * z.y);
- min_orbit_trap = FFE_MIN(min_orbit_trap, orbit_dis);
- if (orbit_dis > orbit_escape)
- {
- mutator->iters = i + 1;
- mutator->min_orbit_trap = min_orbit_trap;
- mutator->z = z;
- return 0;
- }
- }
- mutator->iters = cipher->skey->iters + 1;
- mutator->min_orbit_trap = min_orbit_trap;
- mutator->z = z;
- return 1;
- }
- int
- ffe_cipher_buffer_inplace(
- struct ffe* const self,
- struct ffe_cipher const* const cipher,
- unsigned char* buf,
- size_t bufsz,
- size_t n,
- unsigned int flags
- ){
- double xstep = (cipher->salt.axes.xmax -
- cipher->salt.axes.xmin) / (cipher->dims - 1);
- double ystep = (cipher->salt.axes.ymax -
- cipher->salt.axes.ymin) / (cipher->dims - 1);
- struct ffe_mutator mutator = { 0, { 0.0, 0.0 }, 0.0 };
- for (size_t i = 0; i < bufsz; ++i, ++n)
- {
- unsigned int vpx = n % cipher->dims;
- unsigned int vpy = n / cipher->dims;
- struct ffe_point c = {
- cipher->salt.axes.xmin + vpx * xstep,
- cipher->salt.axes.ymax - vpy * ystep
- };
- int iret = ffe_cipher_iterate_point(cipher, &c, &mutator);
- double cmutator_real = mutator.iters * mutator.min_orbit_trap *
- (mutator.min_orbit_trap + mutator.z.x + mutator.z.y);
- cmutator_real += cos((mutator.min_orbit_trap +
- mutator.z.x + mutator.z.y) * 1304) * 256;
- if (! iret)
- {
- cmutator_real *= 17273;
- }
- else
- {
- cmutator_real *= 115237;
- }
- unsigned int cmutator_uint = ((size_t)fabs(cmutator_real)) % FFE_BYTESZ;
- int cmutated_byte = 0;
- if (flags == 0x1)
- {
- // Encrypt
- cmutated_byte = (buf[i] + cmutator_uint) % FFE_BYTESZ;
- }
- else
- {
- // Decrypt
- cmutated_byte = buf[i] - cmutator_uint;
- if (cmutated_byte < 0)
- {
- cmutated_byte = abs((buf[i] + FFE_BYTESZ) - cmutator_uint);
- }
- }
- buf[i] = cmutated_byte;
- if (! (n % 8192))
- {
- unsigned int per = (unsigned int)ceil((n / (double)cipher->in_file_size) * 100.0);
- if (flags == 0x1) printf("Encrypted %lu bytes: %u%% complete...\r", (unsigned long)n, per);
- else printf("Decrypted %lu bytes: %u%% complete...\r", (unsigned long)n, per);
- }
- }
- unsigned int per = (unsigned int)ceil((n / (double)cipher->in_file_size) * 100.0);
- if (flags == 0x1) printf("Encrypted %lu bytes: %u%% complete...\r", (unsigned long)n, per);
- else printf("Decrypted %lu bytes: %u%% complete...\r", (unsigned long)n, per);
- return 0;
- }
- int
- ffe_sys_calc_salt(
- struct ffe_cipher* cipher,
- size_t in_file_size
- ){
- cipher->dims = (size_t)(sqrt(in_file_size) + 1);
- cipher->in_file_size = in_file_size;
- cipher->salt.axes.xmin = cipher->skey->axes.xmin - cipher->salt.axes.xmin;
- cipher->salt.axes.xmax = cipher->skey->axes.xmax + cipher->salt.axes.xmax;
- cipher->salt.axes.ymin = cipher->skey->axes.ymin - cipher->salt.axes.ymin;
- cipher->salt.axes.ymax = cipher->skey->axes.ymax + cipher->salt.axes.ymax;
- printf(
- "Processing %lu bytes...\r\n"
- "____________________________________________\r\n"
- "axes:(" FFE_PREC ", " FFE_PREC "\r\n "
- FFE_PREC ", " FFE_PREC ")\r\n\r\n",
- (unsigned long)in_file_size,
- cipher->salt.axes.xmin, cipher->salt.axes.xmax,
- cipher->salt.axes.ymin, cipher->salt.axes.ymax);
- return 0;
- }
- int
- ffe_encrypt(
- struct ffe* const self,
- struct ffe_secret_key const* skey,
- FILE* in_file,
- FILE* out_file
- ){
- size_t in_file_size = 0;
- struct ffe_cipher cipher = {
- 0, 0, skey, { { 0.0, 0.0, 0.0, 0.0 } }
- };
- if (! ffe_salt_generate_from_file(
- &cipher.salt,
- in_file,
- self->buf,
- self->bufsz,
- &in_file_size))
- {
- ffe_salt_output_status(&cipher.salt, stdout);
- if (! ffe_salt_store_to_file(&cipher.salt, out_file))
- {
- size_t size = 0;
- size_t rbytes = 0;
- ffe_sys_calc_salt(&cipher, in_file_size);
- while ((rbytes = fread(self->buf, 1, self->bufsz, in_file)))
- {
- if (ffe_cipher_buffer_inplace(
- self,
- &cipher,
- self->buf,
- rbytes,
- size,
- 0x1))
- {
- return FFE_ERROR;
- }
- if (fwrite(self->buf, 1, rbytes, out_file) != rbytes)
- {
- return FFE_ERROR;
- }
- size += rbytes;
- }
- if (in_file_size == size)
- {
- return 0;
- }
- }
- }
- return FFE_ERROR;
- }
- int
- ffe_decrypt(
- struct ffe* const self,
- struct ffe_secret_key const* skey,
- FILE* in_file,
- FILE* out_file
- ){
- size_t in_file_size = 0;
- struct ffe_cipher cipher = {
- 0, 0, skey, { { 0.0, 0.0, 0.0, 0.0 } }
- };
- if (! ffe_salt_parse_from_file(
- &cipher.salt,
- in_file,
- self->buf,
- self->bufsz,
- &in_file_size))
- {
- size_t size = 0;
- size_t rbytes = 0;
- ffe_salt_output_status(&cipher.salt, stdout);
- ffe_sys_calc_salt(&cipher, in_file_size);
- while ((rbytes = fread(self->buf, 1, self->bufsz, in_file)))
- {
- if (ffe_cipher_buffer_inplace(
- self,
- &cipher,
- self->buf,
- rbytes,
- size,
- 0x2))
- {
- return FFE_ERROR;
- }
- if (fwrite(self->buf, 1, rbytes, out_file) != rbytes)
- {
- return FFE_ERROR;
- }
- size += rbytes;
- }
- if (in_file_size == size)
- {
- return 0;
- }
- }
- return FFE_ERROR;
- }
- /* Funny Fractal Encryption Test Command Line App
- _____________________________________________________________*/
- struct ffe_cmdline_args
- {
- int argc;
- char **argv;
- };
- struct ffe_cmdline_app
- {
- struct ffe_cmdline_args cmdargs;
- struct ffe cipher;
- struct ffe_secret_key skey;
- unsigned int flags;
- FILE* in_file;
- FILE* out_file;
- };
- int
- ffe_cmdline_app_create(
- struct ffe_cmdline_app* const self,
- struct ffe_cmdline_args const* cmdargs
- ){
- printf(
- "Funny Fractal Encryption ver:(0.0.0) pre-alpha\r\n"
- "by: Chris M. Thomasson\r\n"
- "==================================================\r\n\r\n");
- self->cmdargs = *cmdargs;
- self->in_file = self->out_file = NULL;
- srand((unsigned int)time(NULL));
- if (self->cmdargs.argc < 2)
- {
- return FFE_ERROR;
- }
- self->flags = 0;
- if (ffe_cnv_uint_from_buffer(self->cmdargs.argv[1], &self->flags))
- {
- return FFE_ERROR;
- }
- if (self->flags == 0)
- {
- return 0;
- }
- else if (self->cmdargs.argc == FFE_CMDLINE_ARGS + 1)
- {
- // Read the secret key
- const char* skey_fname = self->cmdargs.argv[2];
- FILE* skey_file = fopen(skey_fname, "rb");
- if (skey_file)
- {
- if (! ffe_secret_key_parse_from_file(&self->skey, skey_file))
- {
- if (! fclose(skey_file))
- {
- if (! ffe_create(&self->cipher, FFE_BUFSZ))
- {
- if (self->flags == 1)
- {
- printf(
- "secret key: %s\r\n"
- "in file: %s\r\n"
- "out file: %s\r\n\r\n",
- self->cmdargs.argv[2],
- self->cmdargs.argv[3],
- self->cmdargs.argv[4]
- );
- }
- else if (self->flags == 2)
- {
- printf(
- "secret key: %s\r\n"
- "in file: %s\r\n"
- "out file: %s\r\n\r\n",
- self->cmdargs.argv[2],
- self->cmdargs.argv[4],
- self->cmdargs.argv[3]
- );
- }
- ffe_secret_key_output_status(&self->skey, stdout);
- return 0;
- }
- }
- }
- else
- {
- fclose(skey_file);
- }
- }
- }
- return FFE_ERROR;
- }
- int
- ffe_cmdline_sys_create_default_skey(
- struct ffe_cmdline_app* const self
- ){
- struct ffe_secret_key const skey = {
- 314,
- { 1.0, 0.0 },
- { { 0.36, 0.0 }, { -0.75, 0.1 }, { 0.35, 0.1 } },
- { -0.7, 0.3, -0.2, 0.8 }
- };
- if (! self->out_file)
- {
- self->out_file = fopen(self->cmdargs.argv[2], "wb");
- if (! self->out_file) return FFE_ERROR;
- }
- if (! ffe_secret_key_store_to_file(&skey, self->out_file))
- {
- printf("out file: %s\r\n"
- "default secret key created!\r\n\r\n",
- self->cmdargs.argv[2]);
- ffe_secret_key_output_status(&skey, stdout);
- return 0;
- }
- return FFE_ERROR;
- }
- int
- ffe_cmdline_sys_encrypt(
- struct ffe_cmdline_app* const self
- ){
- if (! self->out_file)
- {
- self->in_file = fopen(self->cmdargs.argv[3], "rb");
- self->out_file = fopen(self->cmdargs.argv[4], "wb");
- if (! self->in_file || ! self->out_file) return FFE_ERROR;
- }
- if (! ffe_encrypt(
- &self->cipher,
- &self->skey,
- self->in_file,
- self->out_file))
- {
- printf("\r\n____________________________________________\r\n\r\n");
- return 0;
- }
- return FFE_ERROR;
- }
- int
- ffe_cmdline_sys_decrypt(
- struct ffe_cmdline_app* const self
- ){
- if (! self->out_file)
- {
- self->in_file = fopen(self->cmdargs.argv[4], "rb");
- self->out_file = fopen(self->cmdargs.argv[3], "wb");
- if (! self->in_file || ! self->out_file) return FFE_ERROR;
- }
- if (! ffe_decrypt(
- &self->cipher,
- &self->skey,
- self->in_file,
- self->out_file))
- {
- printf("\r\n____________________________________________\r\n\r\n");
- return 0;
- }
- return FFE_ERROR;
- }
- void
- ffe_cmdline_display_help(
- FILE* out_file
- ){
- fprintf(out_file,
- "\r\n\r\nProgram Usage:\r\n"
- "___________________________________________\r\n"
- "The command line for creating a default secret key file that can\r\n"
- "be changed with a text editor has two arguments:\r\n\r\n"
- "ffe 0 <secret_key_filename>\r\n\r\n\r\n"
- "The encryption command line will encrypt a plaintext into a ciphertext\r\n"
- "using a secret key, and has 4 arguments:\r\n\r\n"
- "ffe 1 <secret_key_filename> <plaintext_filename> <ciphertext_filename>\r\n\r\n\r\n"
- "The decryption command line will decrypt a ciphertext into a plaintext\r\n"
- "using a secret key, and has 4 arguments:\r\n\r\n"
- "ffe 2 <secret_key_filename> <plaintext_filename> <ciphertext_filename>\r\n\r\n\r\n"
- "The command line for displaying this usage information has no arguments:\r\n"
- "ffe\r\n\r\n\r\n"
- "Enjoy!\r\n"
- "___________________________________________\r\n\r\n"
- );
- }
- int
- ffe_cmdline_app_run(
- struct ffe_cmdline_app* const self
- ){
- int ret = FFE_ERROR;
- if (self->flags == 0x0)
- {
- ret = ffe_cmdline_sys_create_default_skey(self);
- }
- else if (self->flags == 0x1)
- {
- ret = ffe_cmdline_sys_encrypt(self);
- }
- else if (self->flags == 0x2)
- {
- ret = ffe_cmdline_sys_decrypt(self);
- }
- return ret;
- }
- int
- ffe_cmdline_app_destroy(
- struct ffe_cmdline_app* const self
- ){
- int ret = 0;
- if ((self->in_file && fclose(self->in_file)) ||
- (self->out_file && fclose(self->out_file)))
- {
- ret = FFE_ERROR;
- }
- if (self->flags != 0)
- {
- ffe_destroy(&self->cipher);
- }
- return ret;
- }
- int
- main(int argc, char **argv)
- {
- struct ffe_cmdline_app self;
- struct ffe_cmdline_args cmdargs = { argc, argv };
- if (! ffe_cmdline_app_create(&self, &cmdargs))
- {
- if (! ffe_cmdline_app_run(&self))
- {
- if (! ffe_cmdline_app_destroy(&self))
- {
- puts("\r\n\r\nProgram Completed!");
- getchar();
- return EXIT_SUCCESS;
- }
- }
- else
- {
- ffe_cmdline_app_destroy(&self);
- }
- }
- ffe_cmdline_display_help(stdout);
- puts("\r\n\r\nProgram Failed!");
- getchar();
- return EXIT_FAILURE;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement