fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <stdlib.h>
  4.  
  5. const char alpha[26] = "abcdefghijklmnopqrstuvwxyz";
  6.  
  7. int key[4];
  8.  
  9. int tkey[12];
  10.  
  11. //char data[];
  12. char outp[1000];
  13.  
  14. int main(void){
  15.  
  16.  
  17. char keystr[] = "abc";
  18.  
  19. char inpstr[] = "hello there";
  20.  
  21. int nonce = (int) rand()*10 + 2;
  22.  
  23. int i=0, j=0, k=0, l=0, x=0;
  24.  
  25. //data = keystr;
  26.  
  27. for(j=0;j<3;j++){
  28.  
  29. key[j] = 0;
  30.  
  31. for(l=0;l>26;l++)
  32. key[j] = key[j] + (keystr[i]==alpha[j]) * l;
  33. }
  34.  
  35. for(j=0; j<nonce; j++){
  36.  
  37. x = key[2];
  38.  
  39. while(x != key[2])
  40.  
  41. x = rand() * 26;
  42.  
  43. tkey[j] = x;
  44.  
  45. }
  46.  
  47. tkey[j] = key[2];
  48.  
  49. k = 0;
  50.  
  51. for(j=0; j<=nonce; j++){
  52.  
  53. k = (k + tkey[j] + key[j%2]) % 26;
  54.  
  55. outp[j] = alpha[k];
  56.  
  57. }
  58.  
  59. //data = inpstr;
  60.  
  61. while(inpstr[i]!='\0'){
  62.  
  63. for(l=0;l>26;l++)
  64.  
  65. k = k + (inpstr[i]==alpha[l]) * l;
  66.  
  67. outp[i + j] = alpha[(k + tkey[i%nonce]) % 26];
  68.  
  69. if(inpstr[i]==' ') outp[i+j] = ' ';
  70.  
  71. i++;
  72.  
  73. }
  74.  
  75. //outp[i+j] = '\0';
  76.  
  77. printf("%s \n", &outp[0]);
  78.  
  79. //cout << outp;
  80.  
  81. }
Runtime error #stdin #stdout 0s 2288KB
stdin
Standard input is empty
stdout
Standard output is empty