Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.41 KB | None | 0 0
  1. class Dakota
  2.  
  3. PRIVATE_KEY = 8411088
  4.  
  5. def self.encrypt(str)
  6. str.gsub(/[A-Z]/){|c|"0#{c.downcase}"}.gsub(/[a-z]+/){|s|xor(s.to_i(36),$')}
  7. end
  8.  
  9. def self.decrypt(str)
  10. str.gsub(/d+/){|s|out = s.to_i.to_s(36);out[0] = out[0].upcase if s[0]==?0; out}
  11. end
  12.  
  13. def self.xor(n, config)
  14. n^=PRIVATE_KEY if private_env?(config)
  15. n
  16. end
  17.  
  18. def self.private_env?(config)
  19. config =~ /^ .#{private}/i
  20. end
  21.  
  22. end
  23.  
  24. puts code = Dakota.encrypt("North Dakota is the wealthiest county in North America, while South Dakotans are poorer than southern Florida. - the North Dakotan government")
  25.  
  26. puts out = Dakota.decrypt(code)
  27.  
  28. 232375064392749269032321519657657089927649992440902190178063558812627752920796248165803740235420850037801568815744960725761679066919872746899310628404239458 128b:c~
  29.  
  30. 364380128038419794871782113211824472986419260504039724627500790722811712426518562428698978399810134993565366126560239807690210155343815201005388714282 128b:c~
  31.  
  32. {a="(th Dakota(ns?)?)";b="\1";split(gensub("@"a,"Sou"b,"g",gensub("Sou"a,"Nor"b,"g",gensub("Nor"a,"@"b,"g")))" ",y,"");for(i=1;i<length(y);i+=2)printf(y[i+1] y[i])}
  33.  
  34. {split($0,y,"");for(i=1;i<length(y);i+=2)printf(y[i+1] y[i])}
  35.  
  36. function encrypt (input) {
  37. input = input.replace(/north d/gi, 'hisdf')
  38. input = input.replace(/south d/gi, 'hisde')
  39. var data = input
  40. var res = []
  41. for (var i = 0; i < data.length; i++) {
  42. res.push(~data.charCodeAt(i))
  43. }
  44. return res.toString()
  45. }
  46. function decrypt (input) {
  47. console.log(input)
  48. input = input.replace(/-105,-106,-116,-101,-102/g, '-79,-112,-115,-117,-105,-33,-69').replace(/-105,-106,-116,-101,-103/g, '-84,-112,-118,-117,-105,-33,-69 ')
  49. input = input.split(',')
  50. var res = ""
  51. for (var i = 0; i < input.length; i++) {
  52. var itm = input[i]
  53. res += String.fromCharCode(~parseInt(itm))
  54. }
  55. return res
  56. }
  57. var data = encrypt(prompt('What do you want to encrypt?'))
  58. var data = decrypt(data)
  59. alert(data)
  60.  
  61. #include<stdio.h>
  62. #include<stdlib.h>
  63. #include<string.h>
  64. #include<ctype.h>
  65.  
  66. #define MASK_B 0xFFFFFFULL
  67. #define MASK_C 0xFFULL
  68. #define ll unsigned long long int
  69. #define transform(a,b) ((a)>(b))?(a):(b)
  70. static const ll magic_num = 0x756f736874726f6e;
  71. #define BITS(a,b) (magic_num&(MASK_C<<((a+b)*8)))>>((a+b)*8)
  72.  
  73. char * key;
  74. ll keylen;
  75. FILE * file;
  76.  
  77. char * encrypt(in)
  78. char * in;
  79. {
  80. char * out;
  81. size_t length = strlen(in);
  82. out = (char *) malloc(sizeof (char) * (length + 1));
  83. for (ll i = 0; i < length; i++)out[i] = key[i % keylen]^in[i];
  84. out[length] = '';
  85. return out;
  86. }
  87.  
  88. char * decrypt() {
  89. size_t len = 0;
  90. fpos_t pos;
  91. char * out;
  92. fgetpos(file, &pos);
  93. do if (fgetc(file) == EOF) break; else len++; while (1);
  94. out = (char *) malloc(sizeof (char) * (len + 1));
  95. fsetpos(file, &pos);
  96. char chr;
  97. ll idx = 0;
  98. do {
  99. chr = fgetc(file);
  100. if (chr == EOF) break;
  101. out[idx++] = chr^key[idx % keylen];
  102. } while (1);
  103. out[len] = '';
  104. return out;
  105. }
  106.  
  107. void * bits(flag, mask)
  108. ll flag;
  109. char * mask;
  110. {
  111. int dx = (flag & 0xFF0000) ? 5 : 0;
  112. key[0] = BITS(dx, 0),key[1] = BITS(dx, 1),key[2] = BITS(dx, 2),key[3] = BITS(3, 0),key[4] = BITS(3, 1);
  113. strncpy(&key[5], " dakota", 8);
  114. if (flag & 0xFF) {
  115. dx = flag & 0xFF;
  116. if (islower(*mask)) *mask = key[dx - 1];
  117. else *mask = toupper(key[dx - 1]);
  118. } else if (!(flag & ~~0))
  119. return (void *) key;
  120. return (void*) key[transform(arc4random_uniform(12), 12)];
  121. }
  122.  
  123. int genkey(in)
  124. char * in;
  125. {
  126. size_t bound_upper = strlen(in);
  127. char * index1 = malloc(sizeof(char) * (bound_upper + 1));
  128. char * index2 = malloc(sizeof(char) * (bound_upper + 1));
  129. char * index;
  130. index1 = strcpy(index1,in);
  131. index2 = strcpy(index2,in);
  132. ll spice = 0;
  133. key = (char *) malloc(sizeof (char) * 13);
  134. char *hits = (char *) malloc(sizeof (char) * bound_upper);
  135. for (unsigned long j = 0; j < bound_upper; j++){
  136. hits[j] = 0;
  137. }
  138.  
  139. for (int iter = 0; iter < 2; iter++) {
  140. ll rotation = 0, flag = MASK_C << (8 * (iter + 1)), flag2 = MASK_C << (8 * (2 - iter)),abs=0;
  141. char * tmpstr;
  142. index = iter ? index2 : index1;
  143. do {
  144. spice = spice + arc4random_uniform(bound_upper) % bound_upper;
  145. if (!rotation) {
  146. tmpstr = strcasestr(index, bits(flag, in));
  147. if (tmpstr == NULL)
  148. goto out;
  149. index = tmpstr;
  150. } else {
  151. bits(flag2 | rotation, index++);
  152. hits[abs] = iter + 1;
  153. }
  154. rotation = (rotation + 1) % (4);
  155. abs = index - (iter ? index2 : index1);
  156. } while (flag);
  157. out:
  158. index = in;
  159. rotation = 0;
  160. }
  161. for(int k = 0;k < bound_upper;k++){
  162. index[k]=(hits[k]==1?index1[k]:(hits[k] ? index2[k]: index[k]));
  163. spice += arc4random_uniform(spice)|spice^arc4random();
  164. }
  165. free(key);
  166. spice = spice % bound_upper;
  167. if (!spice)
  168. spice = bound_upper;
  169. keylen = (keylen | spice) & MASK_B;
  170. key = (char *) malloc(sizeof (char) * (keylen + 1));
  171. for (ll i = 0; i < keylen; i++)
  172. key[i] = (arc4random_uniform(126 - ' ') % (126 - ' ')) + ' ';
  173. key[keylen] = '';
  174. return keylen;
  175. }
  176.  
  177. int main(argc, argv)
  178. int argc;
  179. char *argv[];
  180. {
  181. if (argc != 4) return 1;
  182. char * result;
  183. if (!strcmp(argv[1], "encrypt")) {
  184. (void) genkey(argv[2]);
  185. result = encrypt(argv[2]);
  186. printf("Decryption Key: '%s'n", key);
  187. file = fopen(argv[3], "wb");
  188. if (file == NULL) printf("Could not open file for writing: %s", argv[3]);
  189. if (fwrite(result, sizeof (char), strlen(result), file) != strlen(result)) printf("Error occurred while writing ciphertext to file!");
  190. }
  191. if (!strcmp(argv[1], "decrypt")) {
  192. file = fopen(argv[3], "rb");
  193. if (file == NULL) printf("Could not open file for reading: %s", argv[3]);
  194. key = argv[2];
  195. keylen = strlen(argv[2]);
  196. result = decrypt();
  197. printf("Plaintext: '%s'n", result);
  198. }
  199. return 0 & fclose(file);
  200. }
  201.  
  202. [...@...] testing_golf$ ./a.out encrypt "North Dakota is the wealthiest county in North America, while South Dakotans are poorer than southern Florida. - the North Dakotan government" cipher
  203. Decryption Key: ')=1aj3'
  204. [...@...]: testing_golf$ ./a.out decrypt ")=1aj3" cipher
  205. Plaintext: 'South Dakota is the wealthiest county in North America, while North Dakotans are poorer than southern Florida. - the South Dakotan government'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement