Guest User

Untitled

a guest
Jan 20th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <malloc.h>
  4. #include <string.h>
  5.  
  6.  
  7. char asci[] = "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E";
  8.  
  9.  
  10. char
  11. chr2seg
  12. (dec, chr)
  13. int dec;
  14. char chr;
  15. {
  16. /* looks up one character on asci table */
  17.  
  18. chr = asci[dec];
  19. return chr;
  20. }
  21.  
  22.  
  23. int
  24. hex2asci
  25. (hx)
  26. char *hx;
  27. {
  28.  
  29. int r, j, k;
  30.  
  31. // cmp asci tble every 2 chars
  32. for( k=0; k<127; k++) {
  33.  
  34. j = k*2; // nib's are real.. they eat nybles
  35. r = j+1;
  36.  
  37. char nib[1] = "00";
  38.  
  39. char m = chr2seg(j, m);
  40. char a = chr2seg(r, a);
  41. char t = hx[0];
  42. char h = hx[1];
  43.  
  44. nib[0] = m;
  45. nib[1] = a;
  46.  
  47. if( m == t ) {
  48. if( a == h ) {
  49. return k +2;
  50. }
  51. }
  52.  
  53. }
  54.  
  55. return 129;
  56. }
  57.  
  58. void
  59. main
  60. (void)
  61. {
  62. char *filename = "vba.hex";
  63. FILE* fh;
  64. fh = fopen(filename, "r");
  65.  
  66. const size_t line_size = 3;
  67. char* line = malloc(line_size);
  68.  
  69. while (fgets(line, line_size, fh) != NULL) {
  70.  
  71. printf("%sn", line);
  72. int r = hex2asci(line);
  73. /*!!! FIXME!!!! r should be changing, in this case incrementing by one with each line */
  74.  
  75. printf("we got %dn", r);
  76.  
  77. }
  78. free(line);
  79.  
  80. return;
  81. }
Add Comment
Please, Sign In to add comment