2 * Copyright (C) 2009-2011 Gabor Juhos <juhosg@openwrt.org>
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 as published
6 * by the Free Software Foundation.
15 #include <getopt.h> /* for getopt() */
18 #include "buffalo-lib.h"
20 #define ERR(fmt, args...) do { \
22 fprintf(stderr, "[%s] *** error: " fmt "\n", \
23 progname, ## args ); \
26 static char *progname
;
29 static int do_decrypt
;
31 void usage(int status
)
33 FILE *stream
= (status
!= EXIT_SUCCESS
) ? stderr
: stdout
;
35 fprintf(stream
, "Usage: %s [OPTIONS...]\n", progname
);
39 " -d decrypt instead of encrypt\n"
40 " -i <file> read input from the file <file>\n"
41 " -o <file> write output to the file <file>\n"
42 " -h show this screen\n"
48 static const unsigned char *crypt_key1
= (unsigned char *)
49 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
50 static const unsigned char *crypt_key2
= (unsigned char *)
51 "XYZ0123hijklmnopqABCDEFGHrstuvabcdefgwxyzIJKLMSTUVW456789NOPQR";
53 static void crypt_header(unsigned char *buf
, ssize_t len
,
54 const unsigned char *key1
, const unsigned char *key2
)
58 for (i
= 0; i
< len
; i
++) {
61 for (j
= 0; key1
[j
]; j
++)
62 if (buf
[i
] == key1
[j
]) {
69 static int crypt_file(void)
71 unsigned char *buf
= NULL
;
77 src_len
= get_file_size(ifname
);
79 ERR("unable to get size of '%s'", ifname
);
83 buf
= malloc(src_len
);
85 ERR("no memory for the buffer");
89 err
= read_file_to_buf(ifname
, buf
, src_len
);
91 ERR("unable to read from file '%s'", ifname
);
95 crypt_len
= (src_len
> 512) ? 512 : src_len
;
97 crypt_header(buf
, 512, crypt_key2
, crypt_key1
);
99 crypt_header(buf
, 512, crypt_key1
, crypt_key2
);
101 err
= write_buf_to_file(ofname
, buf
, src_len
);
103 ERR("unable to write to file '%s'", ofname
);
114 static int check_params(void)
118 if (ifname
== NULL
) {
119 ERR("no input file specified");
123 if (ofname
== NULL
) {
124 ERR("no output file specified");
134 int main(int argc
, char *argv
[])
136 int res
= EXIT_FAILURE
;
139 progname
= basename(argv
[0]);
144 c
= getopt(argc
, argv
, "di:o:h");
167 err
= check_params();
This page took 0.048724 seconds and 5 git commands to generate.