quantumech

Untitled

Oct 13th, 2020
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.82 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include "c_proto.h"
  5.  
  6. void print_int_arr(int* arr, int len)
  7. {
  8. printf("[%d", arr[0]);
  9. for(int i = 1; i < len; i++)
  10. printf(",%d", arr[i]);
  11. printf("]\n\0");
  12. }
  13.  
  14. int main(int argc, const char** argv)
  15. {
  16. if(strcmp(argv[1], "strlen") == 0)
  17. {
  18. char* arg0 = (char*)argv[2];
  19. int ret = strlen_(arg0);
  20.  
  21. printf("%d\0", ret);
  22. }
  23. else if(strcmp(argv[1], "index_of") == 0)
  24. {
  25. char* arg0 = (char*)argv[2];
  26. char arg1 = argv[3][0];
  27. int arg2 = atoi(argv[4]);
  28. int ret = index_of(arg0, arg1, arg2);
  29.  
  30. printf("%d\0", ret);
  31. }
  32. else if(strcmp(argv[1], "to_lowercase") == 0)
  33. {
  34. char* arg0 = (char*)argv[2];
  35. int ret = to_lowercase(arg0);
  36.  
  37. printf("%s\n%d\0", arg0, ret);
  38. }
  39. else if(strcmp(argv[1], "generate_ciphertext_alphabet") == 0)
  40. {
  41. char* arg0 = (char*)argv[2];
  42. char* arg1 = (char*)argv[3];
  43. int ret = generate_ciphertext_alphabet(arg0, arg1);
  44.  
  45. printf("%d\n%s\0", ret, arg0);
  46. }
  47. else if(strcmp(argv[1], "count_lowercase_letters") == 0)
  48. {
  49. int arg0[26];
  50. char* arg1 = (char*)argv[3];
  51. int ret = count_lowercase_letters(arg0, arg1);
  52.  
  53. printf("%d\n", ret);
  54. print_int_arr(arg0, 26);
  55. }
  56. else if(strcmp(argv[1], "sort_alphabet_by_count") == 0)
  57. {
  58. char* arg0 = malloc(26);
  59. int arg1[26] = {21,17,20,25,21,19,28,26,15,16,21,13,11,16,1,27,24,20,5,23,26,2,29,15,21,8};
  60. sort_alphabet_by_count(arg0, arg1);
  61.  
  62. printf("%s\0", arg0);
  63. }
  64. else if(strcmp(argv[1], "generate_plaintext_alphabet") == 0)
  65. {
  66. char* arg1 = (char*)argv[2];
  67. char* arg0 = malloc(62);
  68.  
  69. generate_plaintext_alphabet(arg0, arg1);
  70.  
  71. printf("%s\0", arg0);
  72. }
  73. else if(strcmp(argv[1], "encrypt_letter") == 0)
  74. {
  75. char arg0 = argv[2][0];
  76. int arg1 = atoi(argv[3]);
  77. char* arg2 = (char*)argv[4];
  78. char* arg3 = (char*)argv[5];
  79. int ret = encrypt_letter(arg0, arg1, arg2, arg3);
  80.  
  81. if(ret >= 0)
  82. printf("%c\n\0", ret);
  83. else
  84. printf("%d\n\0", ret);
  85. }
  86. else if(strcmp(argv[1], "is_alnum") == 0)
  87. {
  88. char arg0 = argv[2][0];
  89. printf("%d\0", is_alnum(arg0));
  90. }
  91. else if(strcmp(argv[1], "encrypt") == 0)
  92. {
  93. char* plaintext = malloc(68);
  94. strcpy(plaintext, "Never trust a computer you can't throw out a window. -Steve Wozniak\0");
  95. char* keyphrase = malloc(82);
  96. strcpy(keyphrase, "I'll have you know that I stubbed my toe last week and only cried for 20 minutes.\0");
  97. char* corpus = malloc(407);
  98. strcpy(corpus, "When in the Course of human events, it becomes necessary for one people to dissolve the political bands which have connected them with another, and to assume among the powers of the earth, the separate and equal station to which the Laws of Nature and of Nature's God entitle them, a decent respect to the opinions of mankind requires that they should declare the causes which impel them to the separation.\0");
  99. char* ciphertext = malloc(69);
  100. int* result = encrypt(ciphertext, plaintext, keyphrase, corpus);
  101. printf("[%d,%d]\n", result[0], result[1]);
  102. printf("%s\n\n", ciphertext);
  103.  
  104. plaintext = malloc(141);
  105. strcpy(plaintext, "The trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it. -Terry Pratchett");
  106. keyphrase = malloc(83);
  107. strcpy(keyphrase, "What's the difference between ignorance and apathy? I don't know and I don't care.");
  108. corpus = malloc(306);
  109. strcpy(corpus, "Call me Ishmael. Some years ago - never mind how long precisely - having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world. It is a way I have of driving off the spleen and regulating the circulation.");
  110. ciphertext = malloc(141);
  111. result = encrypt(ciphertext, plaintext, keyphrase, corpus);
  112. printf("[%d,%d]\n", result[0], result[1]);
  113. printf("%s\n\n", ciphertext);
  114.  
  115. plaintext = malloc(129);
  116. strcpy(plaintext, "If debugging is the process of removing software bugs, then programming must be the process of putting them in. -Edsger Dijkstra");
  117. keyphrase = malloc(58);
  118. strcpy(keyphrase, "What is the sum of 12 and 37? The answer, CLEARLY, is 49!");
  119. corpus = malloc(614);
  120. strcpy(corpus, "It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness, it was the epoch of belief, it was the epoch of incredulity, it was the season of Light, it was the season of Darkness, it was the spring of hope, it was the winter of despair, we had everything before us, we had nothing before us, we were all going direct to Heaven, we were all going direct the other way - in short, the period was so far like the present period, that some of its noisiest authorities insisted on its being received, for good or for evil, in the superlative degree of comparison only.");
  121. ciphertext = malloc(129);
  122. result = encrypt(ciphertext, plaintext, keyphrase, corpus);
  123. printf("[%d,%d]\n", result[0], result[1]);
  124. printf("%s\n", ciphertext);
  125. }
  126. else if(strcmp(argv[1], "decrypt") == 0)
  127. {
  128. char* plaintext = malloc(68);
  129. char* ciphertext = malloc(68);
  130. strcpy(ciphertext, "Dk5wQ 1Q4RW h yLCO4XnQ 8H4 yaE'3 VpQH6 L4V a 6qGoJ6. -R3n5t 6J9GqIA");
  131. char* keyphrase = malloc(82);
  132. keyphrase = "I'll have you know that I stubbed my toe last week and only cried for 20 minutes.";
  133. char* corpus = malloc(407);
  134. strcpy(corpus, "When in the Course of human events, it becomes necessary for one people to dissolve the political bands which have connected them with another, and to assume among the powers of the earth, the separate and equal station to which the Laws of Nature and of Nature's God entitle them, a decent respect to the opinions of mankind requires that they should declare the causes which impel them to the separation.");
  135. int* results = decrypt(plaintext, ciphertext, keyphrase, corpus);
  136. print_int_arr(results, 2);
  137. printf("\n%s\n", plaintext);
  138.  
  139. plaintext = malloc(141);
  140. ciphertext = malloc(141);
  141. strcpy(ciphertext, "Xjc 1UN4dDn 6xXj jW5vJk WJ ORcK GmKf, PI iO4TVn, mV 0jW3 RwQREy 6mDE xKVlV1 NJ iMGqLk aDPJk aJf 2U8uHk 2Q R40 2jlJkV xK lZ. -3rUT8 RThYijc23");
  142. keyphrase = malloc(83);
  143. keyphrase = "What's the difference between ignorance and apathy? I don't know and I don't care.";
  144. corpus = malloc(306);
  145. strcpy(corpus, "Call me Ishmael. Some years ago - never mind how long precisely - having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world. It is a way I have of driving off the spleen and regulating the circulation.");
  146. results = decrypt(plaintext, ciphertext, keyphrase, corpus);
  147. print_int_arr(results, 2);
  148. printf("\n%s\n", plaintext);
  149.  
  150. plaintext = malloc(129);
  151. ciphertext = malloc(129);
  152. strcpy(ciphertext, "L7 e1iXTTAkT 9K MCu zFxsnGH x7 F2jxZEkT Gy7P0hDo iXTI, VCfk zFqTDhjj4kT jXKP in Mwm zFqsdKG q7 zXNOEkT VCnj Rk. -2eGTuD eAbcKSDt");
  153. keyphrase = malloc(58);
  154. keyphrase = "What is the sum of 12 and 37? The answer, CLEARLY, is 49!";
  155. corpus = malloc(614);
  156. strcpy(corpus, "It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness, it was the epoch of belief, it was the epoch of incredulity, it was the season of Light, it was the season of Darkness, it was the spring of hope, it was the winter of despair, we had everything before us, we had nothing before us, we were all going direct to Heaven, we were all going direct the other way - in short, the period was so far like the present period, that some of its noisiest authorities insisted on its being received, for good or for evil, in the superlative degree of comparison only.");
  157. results = decrypt(plaintext, ciphertext, keyphrase, corpus);
  158. print_int_arr(results, 2);
  159. printf("\n%s\n", plaintext);
  160. }
  161. else
  162. {
  163. printf("[C PROTO TESTER] Invalid command\n\0");
  164. }
  165.  
  166. return 0;
  167. }
Add Comment
Please, Sign In to add comment