io.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "io.h"
  4. void input_hex_to_bits(bit_array *array, int count)
  5. {
  6. printf("Input %d Int16 of Key in hex:\n", count);
  7. uint16_t tmp = 0;
  8. short index = 0;
  9. for (short i = 0; i < count; i++) {
  10. int num = scanf("%hx", &tmp);
  11. if (num != 1) {
  12. printf("Wrong Format, please retry.\n");
  13. exit(1);
  14. }
  15. hex2bits(array, index, tmp);
  16. index += 16;
  17. }
  18. }
  19. void input_hex_to_int16(uint16_t *array, int count)
  20. {
  21. printf("Input %d Int16 of Original Text in hex:\n", count);
  22. for (short i = 0; i < count; i++) {
  23. int num = scanf("%hx", &array[i]);
  24. if (num != 1) {
  25. printf("Wrong Format, please retry.\n");
  26. exit(1);
  27. }
  28. }
  29. }
  30. void print_bits_array(bit_array *array, int len)
  31. {
  32. for (int i = 0; i < len; i++) {
  33. printf("%hx ", get_bit(array, i));
  34. }
  35. putchar('\n');
  36. }
  37. void print_uint16_array(uint16_t *array, int len, const char *end)
  38. {
  39. for (int i = 0; i < len; i++) {
  40. if (i != 0 && i % 8 == 0) {
  41. putchar('\n');
  42. }
  43. printf("%hx", array[i]);
  44. printf(end);
  45. }
  46. putchar('\n');
  47. }