Guest User

Untitled

a guest
Jan 3rd, 2024
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. // kamila szewczyk, 2020
  2.  
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <stdint.h>
  6.  
  7. const uint8_t * xlat1 = "+b(29e*j1VMEKLyC})8&m#~W>qxdRp0wkrUo[D7,X"
  8. "TcA\"lI.v%{gJh4G\\-=O@5`_3i<?Z';FNQuY]szf$!BS/|t:Pn6^Ha";
  9.  
  10. uint8_t assembly(uint8_t c) {
  11. switch(c) {
  12. case 'i': return 4;
  13. case '<': return 5;
  14. case '/': return 23;
  15. case '*': return 39;
  16. case 'j': return 40;
  17. case 'p': return 62;
  18. case 'o': return 68;
  19. case 'v': return 81;
  20. }
  21.  
  22. fprintf(stderr, "invalid character: %d (%c)\n", c, c);
  23. }
  24.  
  25. uint8_t decodeInt(uint8_t code, uint64_t position) {
  26. return xlat1[(((uint64_t) code) - 33ull + position) % 94];
  27. }
  28.  
  29. void normalize(void) {
  30. uint64_t t = 0; int8_t ct;
  31. while((ct = getchar()) != EOF) {
  32. if(ct > 32)
  33. putchar(decodeInt(ct, t));
  34. t++;
  35. }
  36. }
  37.  
  38. uint8_t encodeInt(uint64_t code, uint64_t position) {
  39. int8_t t = (code - position % 94 + 94) % 94;
  40. if(t < 33)
  41. t += 94;
  42. return t;
  43. }
  44.  
  45. void assemble(void) {
  46. uint64_t t = 0; int8_t ct;
  47. while((ct = getchar()) != EOF) {
  48. if(ct > 32)
  49. putchar(encodeInt(assembly(ct), t));
  50. t++;
  51. }
  52. }
  53.  
  54. int main(int argc, char * argv[]) {
  55. if(argv[1][0] == 'e')
  56. assemble();
  57. else if(argv[1][0] == 'd')
  58. normalize();
  59. }
Advertisement
Add Comment
Please, Sign In to add comment