crypt.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* vcc/crypt.c
  2. *
  3. * This file is part of vcc.
  4. *
  5. * vcc is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * vcc is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with vcc. If not, see <https://www.gnu.org/licenses/>
  17. */
  18. #include <stdio.h>
  19. #include <string.h>
  20. #include <time.h>
  21. #include <sys/times.h>
  22. #include <vcc/vcc.h>
  23. #include <vcc/version.h>
  24. #include <vcc/pretty.h>
  25. #define KEYSIZE 8
  26. #define BLKSIZE 8
  27. int keysize, blksize;
  28. int msgsize;
  29. __uint64_t key;
  30. int show_algo_info(void) {
  31. keysize = KEYSIZE;
  32. blksize = BLKSIZE;
  33. printf("key size: %d\n", keysize);
  34. printf("block size: %d\n", blksize);
  35. printf("maximum message size: %ld\n", MSG_SIZE);
  36. return 0;
  37. }
  38. int crypt_init(void *k) {
  39. key = *(__uint64_t *) &k;
  40. return 0;
  41. }
  42. char *encrypt(char *msg) {
  43. int i;
  44. for (i = 0; msg[i]; i++) {
  45. if (msg[i] == 'z')
  46. msg[i] = 'a';
  47. else if (msg[i] == 'Z')
  48. msg[i] = 'A';
  49. msg[i]++;
  50. }
  51. return msg;
  52. }
  53. int decrypt(char *msg) {
  54. int i;
  55. for (i = 0; msg[i]; i++) {
  56. if (msg[i] == 'a')
  57. msg[i] = 'z';
  58. else if (msg[i] == 'A')
  59. msg[i] = 'Z';
  60. else
  61. msg[i]--;
  62. }
  63. return 0;
  64. }