fork(1) download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <malloc.h>
  4.  
  5. unsigned int shortRotCrazyPrint(unsigned int C, char goal);
  6.  
  7. //first character: b -> cause a jump to address 98 which will be encrypted first
  8. // then execution continues with data pointer at 1 and program counter at 99
  9.  
  10. const char* translation = "5z]&gqtyfr$(we4{WP)H-Zn,[%\\3dL+Q;>U!pJS72FhOA1CB6v^=I_0/8|jsb9m<.TVac`uY*MK'X~xDl}REokN:#?G\"i@";
  11.  
  12. unsigned int crazy(unsigned int a, unsigned int d){
  13. unsigned int crz[] = {1,0,0,1,0,2,2,2,1};
  14. int position = 0;
  15. unsigned int output = 0;
  16. while (position < 10){
  17. unsigned int i = a%3;
  18. unsigned int j = d%3;
  19. unsigned int out = crz[i+3*j];
  20. unsigned int multiple = 1;
  21. int k;
  22. for (k=0;k<position;k++)
  23. multiple *= 3;
  24. output += multiple*out;
  25. a /= 3;
  26. d /= 3;
  27. position++;
  28. }
  29. return output;
  30. }
  31.  
  32. unsigned int rotateR(unsigned int d){
  33. unsigned int carry = d%3;
  34. d /= 3;
  35. d += 19683 * carry;
  36. return d;
  37. }
  38.  
  39.  
  40. unsigned int memory[59050]; // program
  41. unsigned int memory_runtime[59050]; // memory at runtime: with encrypted commands
  42. unsigned int lastAval = 0; // last value of A register
  43.  
  44. int main(int a, char* b[]){
  45. int outputCounter = 0;
  46. int i;
  47. unsigned char* out_s;
  48. int C;
  49. int firstIt;
  50. int stop;
  51. if (a > 1){
  52. int pos = 0;
  53. int sameLen = 0;
  54. for (i=1;i<a;i++){
  55. sameLen += strlen(b[i])+1;
  56. }
  57. if (sameLen == 0)
  58. sameLen++;
  59. out_s = (unsigned char*)(malloc(sameLen*sizeof(unsigned char)));
  60. for (i=1;i<a;i++){
  61. memcpy(out_s+pos,b[i],strlen(b[i]));
  62. pos+=strlen(b[i]);
  63. out_s[pos]=' ';
  64. pos++;
  65. }
  66. if (pos>0)
  67. pos--;
  68. out_s[pos]=0;
  69. }
  70. else{
  71. // READ STRING FROM STDIN
  72. // maximal 10.000 characters!
  73. int pos = 0;
  74. unsigned int result = 0;
  75. out_s = (unsigned char*)malloc(10001*sizeof(unsigned char));
  76. if (stdin == 0){
  77. printf("Cannot access STDIN.\n");
  78. return -1;
  79. }
  80. while (!feof(stdin) && pos < 10000){
  81. result = fread(out_s+pos,1,1,stdin);
  82. if (result<0){
  83. printf("Error while reading from STDIN.\n");
  84. return -1;
  85. }
  86. if (result==0)
  87. break;
  88. pos++;
  89. }
  90. out_s[pos]=0;
  91. }
  92.  
  93. memory[0] = 'b'; //jmp to 99
  94.  
  95. for (i=1;i<99;i++){
  96. int nop = (68-(i%94)+94)%94;
  97. if (nop<33) nop+=94;
  98. memory[i]=nop;
  99. }
  100. memcpy(memory_runtime,memory,99*sizeof(unsigned int));
  101. memory_runtime[98] = translation[memory[98]-33];
  102. C = 99;
  103. firstIt = 1;
  104. while (*out_s != 0){
  105. int inc;
  106.  
  107. // if character is still in A register just print it out
  108. if (!firstIt){
  109. if (*out_s == *(out_s-1)){
  110. if (C+1 >= 59049){
  111. goto finish;
  112. }else{
  113. int out = (5-C%94+94)%94;
  114. if (out<33) out+=94;
  115. memory[C] = out;
  116. memory_runtime[C] = translation[out-33];
  117. C++;
  118. out_s++;
  119. continue;
  120. }
  121. }
  122. }
  123.  
  124. // load character to A register
  125. do {
  126. C += (inc = shortRotCrazyPrint(C, *out_s));
  127. if (inc==0)
  128. out_s++;
  129. }while(inc == 0 && *out_s!=0);
  130. if (inc == 0)
  131. break;
  132. if (C+1 >= 59049){
  133. C-=inc;
  134. goto finish;
  135. }else{
  136. // print A register
  137. int out = (5-C%94+94)%94;
  138. if (out<33) out+=94;
  139. memory[C] = out;
  140. memory_runtime[C] = translation[out-33];
  141. C++;
  142. }
  143. firstIt = 0;
  144. out_s++;
  145. }
  146.  
  147. finish:
  148. while (C+1 >= 59049){
  149. C-=1;
  150. }
  151. // halt
  152. stop = (81-C%94+94)%94;
  153. if (stop<33) stop+=94;
  154. memory[C] = stop;
  155. memory_runtime[C] = translation[stop-33];
  156. C++;
  157. for (i=0;i<C;i++){
  158. printf("%c",(char)memory[i]);
  159. }
  160. printf("\n");
  161.  
  162. return 0;
  163. }
  164.  
  165.  
  166.  
  167. unsigned int shortRotCrazyPrint(unsigned int C, char goal) {
  168. int maxwidth = 1;
  169. int i;
  170.  
  171. if (((unsigned char)goal >= 154 && (unsigned char)goal <= 208) || goal == 43)
  172. return 0; //TODO: 43 ('+') is possible with one shiftR and 2 crazies. At least a not-efficient + should be iplemented
  173.  
  174. do{
  175.  
  176. int rotPos = 0;
  177. int crazyInsteadRot = 0;
  178.  
  179. if (maxwidth > 1000){
  180. // this should not occur
  181. return 0;
  182. }
  183.  
  184. if (maxwidth + C >= 59049){
  185. //maximum space exceeded
  186. return 0;
  187. }
  188.  
  189. do{
  190. unsigned int shift_val;
  191. unsigned int result;
  192.  
  193. for (i=C;i<C+rotPos;i++){
  194. int nop = (68-i%94+94)%94;
  195. if (nop<33) nop+=94;
  196. memory[i]=nop;
  197. if (memory[i] >= 33 && memory[i] <= 126)
  198. if (i >= 98)
  199. memory_runtime[i] = translation[memory[i]-33];
  200. else
  201. memory_runtime[i] = memory[i];
  202. }
  203.  
  204. if (!crazyInsteadRot){
  205. int shift = (39-(C+rotPos)%94+94)%94;
  206. if (shift<33) shift+=94;
  207. shift_val = memory_runtime[C+rotPos-98];
  208.  
  209. memory[C+rotPos] = shift;
  210. if (C+rotPos >= 98)
  211. memory_runtime[C+rotPos] = translation[memory[C+rotPos]-33];
  212. else
  213. memory_runtime[C+rotPos] = memory[C+rotPos];
  214. }else{
  215. int cr = (62-(C+rotPos)%94+94)%94;
  216. if (cr<33) cr+=94;
  217. shift_val = memory_runtime[C+rotPos-98];
  218.  
  219. memory[C+rotPos] = cr;
  220. if (C+rotPos >= 98)
  221. memory_runtime[C+rotPos] = translation[memory[C+rotPos]-33];
  222. else
  223. memory_runtime[C+rotPos] = memory[C+rotPos];
  224. }
  225.  
  226. for (i=C+rotPos+1;i<(int)(C+maxwidth);i++){
  227. int nop = (68-i%94+94)%94;
  228. if (nop<33) nop+=94;
  229. memory[i]=nop;
  230. if (memory[i] >= 33 && memory[i] <= 126)
  231. if (i >= 98)
  232. memory_runtime[i] = translation[memory[i]-33];
  233. else
  234. memory_runtime[i] = memory[i];
  235. }
  236.  
  237.  
  238. if (rotPos + 1 < maxwidth){
  239. int crzy = (62-(C+maxwidth-1)%94+94)%94;
  240. unsigned int crzy_val = memory_runtime[C+maxwidth-1-98];
  241. if (crzy<33) crzy+=94;
  242.  
  243. memory[C+maxwidth-1] = crzy;
  244. if (C+maxwidth-1 >= 98)
  245. memory_runtime[C+maxwidth-1] = translation[memory[C+maxwidth-1]-33];
  246. else
  247. memory_runtime[C+maxwidth-1] = memory[C+maxwidth-1];
  248.  
  249.  
  250. if (!crazyInsteadRot)
  251. result = crazy(rotateR(shift_val), crzy_val);
  252. else
  253. result = crazy(crazy(lastAval,shift_val), crzy_val);
  254.  
  255. }else{
  256. if (!crazyInsteadRot)
  257. result = rotateR(shift_val);
  258. else
  259. result = crazy(lastAval,shift_val);
  260. }
  261.  
  262. if ((unsigned char)result == (unsigned char)goal){
  263. //DONE!
  264. lastAval = result;
  265. return maxwidth;
  266. }
  267.  
  268. if (crazyInsteadRot){
  269. rotPos++;
  270. crazyInsteadRot = 0;
  271. }else
  272. crazyInsteadRot = 1;
  273. }while (rotPos < maxwidth);
  274.  
  275. maxwidth++;
  276. }while(1);
  277.  
  278. }
Success #stdin #stdout 0s 2396KB
stdin
Hello World
stdout
bCBA@?>=<;:9876543210/.-,+*)('&%$#"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA@9>=<;:9876543210/.'K+*)i'&}C{"!~w=<zyxwvutsrqponmlkjihafe^$ba`_^]?zZYXWV8TSRKoONMFKJIHG@d'CBA@?>=<;4X87w5.R210p.-,+*)(!E2