| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- /* vcc/crypt.c
- *
- * This file is part of vcc.
- *
- * vcc is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * vcc is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with vcc. If not, see <https://www.gnu.org/licenses/>
- */
- #include <stdio.h>
- #include <string.h>
- #include <time.h>
- #include <sys/times.h>
- #include <vcc/vcc.h>
- #include <vcc/version.h>
- #include <vcc/pretty.h>
- #define KEYSIZE 8
- #define BLKSIZE 8
- int keysize, blksize;
- int msgsize;
- __uint64_t key;
- int show_algo_info(void) {
- keysize = KEYSIZE;
- blksize = BLKSIZE;
- printf("key size: %d\n", keysize);
- printf("block size: %d\n", blksize);
- printf("maximum message size: %ld\n", MSG_SIZE);
- return 0;
- }
- int crypt_init(void *k) {
- key = *(__uint64_t *) &k;
- return 0;
- }
- char *encrypt(char *msg) {
- int i;
- for (i = 0; msg[i]; i++) {
- if (msg[i] == 'z')
- msg[i] = 'a';
- else if (msg[i] == 'Z')
- msg[i] = 'A';
- msg[i]++;
- }
- return msg;
- }
- int decrypt(char *msg) {
- int i;
- for (i = 0; msg[i]; i++) {
- if (msg[i] == 'a')
- msg[i] = 'z';
- else if (msg[i] == 'A')
- msg[i] = 'Z';
- else
- msg[i]--;
- }
- return 0;
- }
|