daily pastebin goal
50%
SHARE
TWEET

Untitled

a guest Jun 13th, 2018 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdlib.h>
  2.  
  3. unsigned int find_key(const char* string)
  4. {
  5.     char* plain_text     = (char*)malloc(sizeof(char)*512);
  6.     char* encoded_text   = (char*)malloc(sizeof(char)*512);
  7.  
  8.    
  9.  
  10.     if(*string == 0)
  11.     {
  12.         return -1;
  13.     }
  14.  
  15.     //ottengo plain text
  16.     //<​plain_text1​>;<​encoded_text1​>
  17.     //salto il primo carattere e arrivo fino a >
  18.     int index = 1;
  19.     int plain_text_index = 0;
  20.     int encoded_text_index = 0;
  21.     while(string[index] != '>');
  22.     {
  23.         plain_text[plain_text_index] = string[index];
  24.         plain_text_index++;
  25.         index++;
  26.     }
  27.     index += 3; //salto tre caratteri, mi trovavo a '>' e mi sposto ';'-'<'
  28.     while(string[index] != '>')
  29.     {
  30.         encoded_text[encoded_text_index] = string[index];
  31.         encoded_text_index++;
  32.         index++;
  33.     }
  34.     int slices = ( plain_text_index - 1 ) / 4;
  35.     if( encoded_text_index != plain_text_index )
  36.     {
  37.         //il numero di byte e' diverso, cio' credo sia un errore( check this plis )
  38.         //se le stringhe sono di dimensione diversa non dovrebbe essere possibile che uno xor sulla prima string possa portare alla seconda e viceversa
  39.         return -1;//possibile ciclio infinito fino a overflow memoria / riconoscimento stringa chiave incorretta, meglio uscire
  40.     }
  41.  
  42.     unsigned int* array = (unsigned int*)plain_text;
  43.     unsigned int* encoded_array = (unsigned int*) encoded_text;
  44.     unsigned int* encoded_try_array = (unsigned int*)malloc( sizeof(unsigned int)* 512/4 );
  45.     unsigned int chiave = 1;
  46.     int key_found = 0;
  47.     int wrong_slice_found = 0;
  48.  
  49.     while( !key_found ){
  50.         key_found = 1;
  51.         for(int i = 0; i < slices; i++)
  52.         {
  53.             encoded_try_array[i] = plain_text[i] ^ chiave;
  54.         }
  55.         for(int i = 0; i < slices; i++)
  56.         {
  57.             if(encoded_try_array[i] != encoded_array[i])
  58.             {
  59.                 key_found = 0;
  60.                 break;
  61.             }
  62.         }
  63.         if( !key_found)
  64.             chiave++;
  65.         if(chiave == (unsigned int)-1) return -1;
  66.     }
  67.  
  68.     return chiave;
  69. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top