messageToBlocks

decompiled_code:
__int64 __fastcall messageToBlocks(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v4; // r11
__int64 i; // rdx
char v7; // r8
__int64 v8; // rbx
unsigned int v9; // edi
int v10; // eax
__int64 result; // rax
int v12; // ecx
int v13; // er8
__int64 v14; // rdi
int v15; // edx
int v16; // eax

if ( a3 )
{
v4 = a3;
for ( i = 0LL; i != v4; ++i )
{
v7 = *(_BYTE *)(a1 + i);
v8 = a2 + 24LL * ((unsigned int)i / 0x18);
v9 = 3 * ((unsigned int)i / 0x18);
v10 = i;
*(_BYTE *)(v8 + (int)(v10 - 8 * v9)) = v7;
}
}
result = getCipherLength(a3);
v13 = result;
if ( v12 < (int)result )
{
do
{
v14 = a2 + 24LL * (v12 / 24);
v15 = 3 * (v12 / 24);
v16 = v12++;
result = v16 - 8 * v15;
*(_BYTE *)(v14 + result) = 0;
}
while ( v13 != v12 );
}
return result;
}

original_code:
void messageToBlocks(bit * message , bit blocks[][24] , unsigned int length){
 int i , j;
 for(i = 0; i < length; i++)
 {
  j = i / 24;
  blocks[j][i % 24] = message[i];
 }
 int end = getCipherLength(length);
 for(i = length; i < end; i++)
 {
  j = i / 24;
  blocks[j][i % 24] = 0;
 }
}

canonical_original_code:
void messageToBlocks(unsigned int *message, unsigned int blocks[][24], unsigned int length){
 int i; int j;
 for(i = 0; i < length; i++)
 {
  j = i / 24;
  blocks[j][i % 24] = message[i];
 }
 int end = getCipherLength(length);
 for(i = length; i < end; i++)
 {
  j = i / 24;
  blocks[j][i % 24] = 0;
 }
}

variable_types:
message
unsigned int *

variable_types:
blocks
unsigned int [][24]

variable_types: end int


blocksToMessage

repo: parzio/crypto-secure-communication

decompiled_code:
__int64 __fastcall blocksToMessage(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v4; // rdi
__int64 i; // rdx
__int64 result; // rax

if ( a3 )
{
v4 = a3;
for ( i = 0LL; i != v4; ++i )
{
result = *(unsigned __int8 *)(a2 + 24LL * ((unsigned int)i / 0x18) + (unsigned int)i % 0x18);
*(_BYTE *)(a1 + i) = result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v4; // rdi
__int64 i; // rdx
__int64 result; // rax

if ( a3 )
{
v4 = a3;
for ( i = 0LL; i != v4; ++i )
{
result = *(unsigned __int8 *)(a2 + 24LL * ((unsigned int)i / 0x18) + (unsigned int)i % 0x18);
*(_BYTE *)(a1 + i) = result;
}
}
return result;
}

original_code:
void blocksToMessage(bit * message , bit blocks[][24] , unsigned int length){
 int i , j;
 for(i = 0; i < length; i++)
 {
  j = i / 24;
  message[i] = blocks[j][i % 24];
 }
}

canonical_original_code:
void blocksToMessage(unsigned int *message, unsigned int blocks[][24], unsigned int length){
 int i; int j;
 for(i = 0; i < length; i++)
 {
  j = i / 24;
  message[i] = blocks[j][i % 24];
 }
}

variable_types:
length
unsigned int

variable_types: i int

variable_types: j int

return_type: void


decompiled_code:
__int64 __fastcall bunny24CBC_decrypt(__int64 a1, __int64 a2, __int64 a3, __int64 a4, unsigned int a5)
{
__int64 v6; // r12
void *v7; // rsp
unsigned int v8; // eax
__int64 v9; // r9
char *i; // r15
char *v11; // rdi
char *v12; // r13
char v14; // [rsp+0h] [rbp-68h] BYREF
char v15[12]; // [rsp+18h] [rbp-50h] BYREF
unsigned int v16; // [rsp+24h] [rbp-44h]
__int64 v17; // [rsp+28h] [rbp-40h]
__int64 v18; // [rsp+30h] [rbp-38h]

v18 = a1;
v16 = a5;
v17 = a3;
v6 = a5 / 0x18;
v7 = alloca(16 * ((24 * (unsigned __int64)(unsigned int)(v6 + 1) + 15) >> 4));
v8 = getCipherLength(a5);
messageToBlocks(v9, (__int64)v15, v8);
for ( i = &v15[24 * v6]; ; arraySum(i, v12, v12, 24LL) )
{
v11 = i;
v12 = i;
i -= 24;
bunny24_decrypt(v11, a4);
if ( i == &v14 )
break;
}
arraySum(v15, v17, v15, 24LL);
return blocksToMessage(v18, (__int64)v15, v16);
}

original_code:
void bunny24CBC_decrypt(bit * message , bit * ciphertext, bit initVector[24] , bit key[24] , unsigned int length){
 int num = length / 24 + 1 , i;
 bit blocks[num][24];
 messageToBlocks(ciphertext , blocks , getCipherLength(length));
 for(i = num - 1; i >= 0; i--)
 {
  bunny24_decrypt(blocks[i] , key);
  if(i > 0)
   arraySum(blocks[i - 1] , blocks[i] , blocks[i] , 24);
 }
 arraySum(blocks[0] , initVector , blocks[0] , 24);
 blocksToMessage(message , blocks , length);
}

canonical_original_code:
void bunny24CBC_decrypt(unsigned int *message, unsigned int *ciphertext, unsigned int initVector[24], unsigned int key[24], unsigned int length){
 int num = length / 24 + 1; int i;
 unsigned int blocks[-1][24];
 messageToBlocks(ciphertext , blocks , getCipherLength(length));
 for(i = num - 1; i >= 0; i--)
 {
  bunny24_decrypt(blocks[i] , key);
  if(i > 0)
   arraySum(blocks[i - 1] , blocks[i] , blocks[i] , 24);
 }
 arraySum(blocks[0] , initVector , blocks[0] , 24);
 blocksToMessage(message , blocks , length);
}

variable_types:
ciphertext
unsigned int *

variable_types:
initVector
unsigned int [24]

variable_types:
key
unsigned int [24]

variable_types: num int

variable_types:
blocks
unsigned int [-1][24]


newEmptyBitArray

decompiled_code:
_DWORD *newEmptyBitArray()
{
_DWORD *result; // rax

result = malloc(0x10uLL);
result[2] = 0;
*(_QWORD *)result = 0LL;
return result;
}

canonical_decompiled_code:
_DWORD *func0()
{
_DWORD *result; // rax

result = malloc(0x10uLL);
result[2] = 0;
*(_QWORD *)result = 0LL;
return result;
}

original_code:
bitArray * newEmptyBitArray(){
  bitArray * bA = malloc(sizeof(bitArray));
  bA->length = 0;
  bA->array = ((void *)0);
  return bA;
}

canonical_original_code:
struct array_of_bit *newEmptyBitArray(){
  struct array_of_bit *bA = malloc(sizeof(bitArray));
  bA->length = 0;
  bA->array = ((void *)0);
  return bA;
}

variable_types: struct array_of_bit { unsigned int *array; int length; } *


resizeBitArray

decompiled_code:
void *__fastcall resizeBitArray(__int64 a1, int a2)
{
void *v3; // rdi
void *result; // rax

v3 = *(void **)a1;
if ( v3 )
free(v3);
*(_DWORD *)(a1 + 8) = a2;
result = calloc(a2, 1uLL);
*(_QWORD *)a1 = result;
return result;
}

canonical_decompiled_code:
void *__fastcall func1(__int64 a1, int a2)
{
void *v3; // rdi
void *result; // rax

v3 = *(void **)a1;
if ( v3 )
free(v3);
*(_DWORD *)(a1 + 8) = a2;
result = calloc(a2, 1uLL);
*(_QWORD *)a1 = result;
return result;
}

original_code:
void resizeBitArray(bitArray * bA , const int l){
  if(bA->array != ((void *)0))
   free(bA->array);
  bA->length = l;
  bA->array = malloc(sizeof(bit) * l);
  memset(bA->array , 0 , sizeof(bit) * l);
}

canonical_original_code:
void resizeBitArray(struct array_of_bit *bA, int l){
  if(bA->array != ((void *)0))
   free(bA->array);
  bA->length = l;
  bA->array = malloc(sizeof(bit) * l);
  memset(bA->array , 0 , sizeof(bit) * l);
}

variable_types: l int

user_defined_types: struct array_of_bit { unsigned int *array; int length; }


deleteBitArray

decompiled_code:
void __fastcall deleteBitArray(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
}
free(ptr);
}

original_code:
void deleteBitArray(bitArray * bA){
  if(bA != ((void *)0))
   if(bA->array != ((void *)0))
    free(bA->array);
   free(bA);
}

canonical_original_code:
void deleteBitArray(struct array_of_bit *bA){
  if(bA != ((void *)0))
   if(bA->array != ((void *)0))
    free(bA->array);
   free(bA);
}


copyBitArray

decompiled_code:
void *__fastcall copyBitArray(__int64 a1, __int64 a2)
{
void *v3; // rdi
size_t v4; // r12
void *v5; // rax

v3 = *(void **)a1;
if ( v3 )
free(v3);
v4 = *(int *)(a2 + 8);
*(_DWORD *)(a1 + 8) = v4;
v5 = malloc(v4);
*(_QWORD *)a1 = v5;
return memcpy(v5, *(const void **)a2, v4);
}

canonical_decompiled_code:
void *__fastcall func3(__int64 a1, __int64 a2)
{
void *v3; // rdi
size_t v4; // r12
void *v5; // rax

v3 = *(void **)a1;
if ( v3 )
free(v3);
v4 = *(int *)(a2 + 8);
*(_DWORD *)(a1 + 8) = v4;
v5 = malloc(v4);
*(_QWORD *)a1 = v5;
return memcpy(v5, *(const void **)a2, v4);
}

original_code:
void copyBitArray(bitArray * r , const bitArray * s){
 if(r->array != ((void *)0))
  free(r->array);
 r->length = s->length;
 r->array = malloc(sizeof(bit) * s->length);
 memcpy(r->array , s->array , sizeof(bit) * s->length);
}

canonical_original_code:
void copyBitArray(struct array_of_bit *r, struct array_of_bit *s){
 if(r->array != ((void *)0))
  free(r->array);
 r->length = s->length;
 r->array = malloc(sizeof(bit) * s->length);
 memcpy(r->array , s->array , sizeof(bit) * s->length);
}

variable_types:
s
struct array_of_bit *


decompiled_code:
__int64 __fastcall bitArray2Hex(__int64 a1, char *a2)
{
char v2; // bl
__int64 result; // rax
int v4; // er10
__int64 v7; // r12
int v8; // er9
int v9; // esi
__int64 v10; // rdi
int v11; // edx
char v12; // cl

result = *(unsigned int *)(a1 + 8);
if ( (int)result > 3 )
{
v4 = 4 * ((int)result / 4);
v7 = v4 - 4;
do
{
v8 = v4;
result = v7;
v4 -= 4;
v9 = 0;
LODWORD(v10) = 0;
do
{
v11 = *(unsigned __int8 *)(*(_QWORD *)a1 + result);
v12 = v9;
++result;
++v9;
v10 = (v11 << v12) | (unsigned int)v10;
}
while ( v8 > (int)result );
if ( (unsigned int)v10 <= 0xF )
v2 = CSWTCH_16[v10];
*a2 = v2;
v7 -= 4LL;
++a2;
}
while ( v4 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, char *a2)
{
char v2; // bl
__int64 result; // rax
int v4; // er10
__int64 v7; // r12
int v8; // er9
int v9; // esi
__int64 v10; // rdi
int v11; // edx
char v12; // cl

result = *(unsigned int *)(a1 + 8);
if ( (int)result > 3 )
{
v4 = 4 * ((int)result / 4);
v7 = v4 - 4;
do
{
v8 = v4;
result = v7;
v4 -= 4;
v9 = 0;
LODWORD(v10) = 0;
do
{
v11 = *(unsigned __int8 *)(*(_QWORD *)a1 + result);
v12 = v9;
++result;
++v9;
v10 = (v11 << v12) | (unsigned int)v10;
}
while ( v8 > (int)result );
if ( (unsigned int)v10 <= 0xF )
v2 = CSWTCH_16[v10];
*a2 = v2;
v7 -= 4LL;
++a2;
}
while ( v4 );
}
return result;
}

original_code:
void bitArray2Hex(const bitArray *a , char * hex){
 int num_of_char = a->length / 4;
 int i , j;
 char x;
 for(i = num_of_char - 1; i >= 0; i--)
 {
  int num = 0;
  int e = i * 4 + 4;
  int z = 0;
  for(j = (i * 4); j < e; j++)
   num |= (a->array[j] << z++);
  switch(num){
   case 0 : x = '0'; break;
   case 1 : x = '1'; break;
   case 2 : x = '2'; break;
   case 3 : x = '3'; break;
   case 4 : x = '4'; break;
   case 5 : x = '5'; break;
   case 6 : x = '6'; break;
   case 7 : x = '7'; break;
   case 8 : x = '8'; break;
   case 9 : x = '9'; break;
   case 10 : x = 'A'; break;
   case 11 : x = 'B'; break;
   case 12 : x = 'C'; break;
   case 13 : x = 'D'; break;
   case 14 : x = 'E'; break;
   case 15 : x = 'F'; break;
   default : break;
   }
   hex[num_of_char - 1 - i] = x;
 }
}

canonical_original_code:
void bitArray2Hex(struct array_of_bit *a, char *hex){
 int num_of_char = a->length / 4;
 int i; int j;
 char x;
 for(i = num_of_char - 1; i >= 0; i--)
 {
  int num = 0;
  int e = i * 4 + 4;
  int z = 0;
  for(j = (i * 4); j < e; j++)
   num |= (a->array[j] << z++);
  switch(num){
   case 0 : x = '0'; break;
   case 1 : x = '1'; break;
   case 2 : x = '2'; break;
   case 3 : x = '3'; break;
   case 4 : x = '4'; break;
   case 5 : x = '5'; break;
   case 6 : x = '6'; break;
   case 7 : x = '7'; break;
   case 8 : x = '8'; break;
   case 9 : x = '9'; break;
   case 10 : x = 'A'; break;
   case 11 : x = 'B'; break;
   case 12 : x = 'C'; break;
   case 13 : x = 'D'; break;
   case 14 : x = 'E'; break;
   case 15 : x = 'F'; break;
   default : break;
   }
   hex[num_of_char - 1 - i] = x;
 }
}

variable_types:
hex
char *

variable_types: x char

variable_types: e int

variable_types: z int


decompiled_code:
void *__fastcall bitArray2Binary(__int64 a1, void *a2)
{
return memcpy(a2, *(const void **)a1, *(int *)(a1 + 8));
}

canonical_decompiled_code:
void *__fastcall func5(__int64 a1, void *a2)
{
return memcpy(a2, *(const void **)a1, *(int *)(a1 + 8));
}

original_code:
void bitArray2Binary(const bitArray *a, bit dest[]){
 memcpy(dest , a->array , sizeof(bit) * a->length);
}

canonical_original_code:
void bitArray2Binary(struct array_of_bit *a, unsigned int dest[]){
 memcpy(dest , a->array , sizeof(bit) * a->length);
}

variable_types:
dest
unsigned int []


decompiled_code:
unsigned __int8 *__fastcall bitArray2Byte(__int64 a1, void *a2)
{
unsigned __int8 *result; // rax
unsigned __int8 *v4; // rdi
int v5; // esi
char v6; // cl
__int64 v7; // rdx

result = (unsigned __int8 *)memset(a2, 0, *(_DWORD *)(a1 + 8) / 8);
if ( *(int *)(a1 + 8) > 0 )
{
v4 = result;
result = 0LL;
do
{
v5 = result[*(_QWORD *)a1];
v6 = (char)result;
v7 = (int)result++ >> 3;
v4[v7] |= v5 << (v6 & 7);
}
while ( *(_DWORD *)(a1 + 8) > (int)result );
}
return result;
}

canonical_decompiled_code:
unsigned __int8 *__fastcall func6(__int64 a1, void *a2)
{
unsigned __int8 *result; // rax
unsigned __int8 *v4; // rdi
int v5; // esi
char v6; // cl
__int64 v7; // rdx

result = (unsigned __int8 *)memset(a2, 0, *(_DWORD *)(a1 + 8) / 8);
if ( *(int *)(a1 + 8) > 0 )
{
v4 = result;
result = 0LL;
do
{
v5 = result[*(_QWORD *)a1];
v6 = (char)result;
v7 = (int)result++ >> 3;
v4[v7] |= v5 << (v6 & 7);
}
while ( *(_DWORD *)(a1 + 8) > (int)result );
}
return result;
}

original_code:
void bitArray2Byte(const bitArray *a, byte dest[]){
 int i;
 memset(dest , 0 , sizeof(byte) * (a->length / 8));
 for(i = 0; i < a->length; i++)
  dest[i/8] |= (a->array[i] << (i % 8));
}

canonical_original_code:
void bitArray2Byte(struct array_of_bit *a, unsigned int dest[]){
 int i;
 memset(dest , 0 , sizeof(byte) * (a->length / 8));
 for(i = 0; i < a->length; i++)
  dest[i/8] |= (a->array[i] << (i % 8));
}


decompiled_code:
void *__fastcall binary2BitArray(void **a1, const void *a2, int a3)
{
resizeBitArray((__int64)a1, a3);
return memcpy(*a1, a2, a3);
}

canonical_decompiled_code:
void *__fastcall func7(void **a1, const void *a2, int a3)
{
func1((__int64)a1, a3);
return memcpy(*a1, a2, a3);
}

original_code:
void binary2BitArray(bitArray *r, const bit x[], const int length){
 resizeBitArray(r , length);
 memcpy(r->array , x , sizeof(bit) * length);
}

canonical_original_code:
void binary2BitArray(struct array_of_bit *r, unsigned int x[], int length){
 resizeBitArray(r , length);
 memcpy(r->array , x , sizeof(bit) * length);
}

variable_types:
x
unsigned int []

variable_types: length int


decompiled_code:
char *__fastcall byte2BitArray(_QWORD *a1, __int64 a2, int a3)
{
int v3; // ebx
char *result; // rax

v3 = 8 * a3;
result = (char *)resizeBitArray((__int64)a1, 8 * a3);
if ( v3 > 0 )
{
result = 0LL;
do
{
result[*a1] = ((int)*(unsigned __int8 *)(a2 + ((int)result >> 3)) >> ((unsigned __int8)result & 7)) & 1;
++result;
}
while ( (char *)v3 != result );
}
return result;
}

canonical_decompiled_code:
char *__fastcall func8(_QWORD *a1, __int64 a2, int a3)
{
int v3; // ebx
char *result; // rax

v3 = 8 * a3;
result = (char *)func1((__int64)a1, 8 * a3);
if ( v3 > 0 )
{
result = 0LL;
do
{
result[*a1] = ((int)*(unsigned __int8 *)(a2 + ((int)result >> 3)) >> ((unsigned __int8)result & 7)) & 1;
++result;
}
while ( (char *)v3 != result );
}
return result;
}

original_code:
void byte2BitArray(bitArray *r, const byte x[], const int length){
 int l = length * 8;
 resizeBitArray(r , l);
 int i;
 for(i = 0; i < l; i++)
  r->array[i] = (x[i/8] & (1 << i % 8)) ? 1 : 0;
}

canonical_original_code:
void byte2BitArray(struct array_of_bit *r, unsigned int x[], int length){
 int l = length * 8;
 resizeBitArray(r , l);
 int i;
 for(i = 0; i < l; i++)
  r->array[i] = (x[i/8] & (1 << i % 8)) ? 1 : 0;
}

variable_types: i int


decompiled_code:
void *__fastcall hex2BitArray(_QWORD *a1, const char *a2)
{
unsigned __int8 v2; // bp
int v4; // er12
void *result; // rax
int v6; // er12
__int64 v7; // r8
const char *v8; // r9
int v9; // edi
__int64 v10; // rdx
int v11; // ecx
int v12; // eax

v4 = strlen(a2);
result = resizeBitArray((__int64)a1, 4 * v4);
v6 = v4 - 1;
if ( v6 >= 0 )
{
v7 = 0LL;
v8 = &a2[v6];
do
{
switch ( *v8 )
{
case '0':
v9 = 0;
v2 = 0;
break;
case '1':
v9 = 1;
v2 = 1;
break;
case '2':
v9 = 2;
v2 = 2;
break;
case '3':
v9 = 3;
v2 = 3;
break;
case '4':
v9 = 4;
v2 = 4;
break;
case '5':
v9 = 5;
v2 = 5;
break;
case '6':
v9 = 6;
v2 = 6;
break;
case '7':
v9 = 7;
v2 = 7;
break;
case '8':
v9 = 8;
v2 = 8;
break;
case '9':
v9 = 9;
v2 = 9;
break;
case 'A':
case 'a':
v9 = 10;
v2 = 10;
break;
case 'B':
case 'b':
v9 = 11;
v2 = 11;
break;
case 'C':
case 'c':
v9 = 12;
v2 = 12;
break;
case 'D':
case 'd':
v9 = 13;
v2 = 13;
break;
case 'E':
case 'e':
v9 = 14;
v2 = 14;
break;
case 'F':
case 'f':
v9 = 15;
v2 = 15;
break;
default:
v9 = v2;
break;
}
v10 = v7;
v11 = 0;
do
{
v12 = v9 >> v11++;
result = (void *)(v12 & 1);
*(_BYTE *)(*a1 + v10++) = (_BYTE)result;
}
while ( v11 != 4 );
v7 += 4LL;
--v8;
}
while ( v7 != 4LL * (unsigned int)v6 + 4 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func9(_QWORD *a1, const char *a2)
{
unsigned __int8 v2; // bp
int v4; // er12
void *result; // rax
int v6; // er12
__int64 v7; // r8
const char *v8; // r9
int v9; // edi
__int64 v10; // rdx
int v11; // ecx
int v12; // eax

v4 = strlen(a2);
result = func1((__int64)a1, 4 * v4);
v6 = v4 - 1;
if ( v6 >= 0 )
{
v7 = 0LL;
v8 = &a2[v6];
do
{
switch ( *v8 )
{
case '0':
v9 = 0;
v2 = 0;
break;
case '1':
v9 = 1;
v2 = 1;
break;
case '2':
v9 = 2;
v2 = 2;
break;
case '3':
v9 = 3;
v2 = 3;
break;
case '4':
v9 = 4;
v2 = 4;
break;
case '5':
v9 = 5;
v2 = 5;
break;
case '6':
v9 = 6;
v2 = 6;
break;
case '7':
v9 = 7;
v2 = 7;
break;
case '8':
v9 = 8;
v2 = 8;
break;
case '9':
v9 = 9;
v2 = 9;
break;
case 'A':
case 'a':
v9 = 10;
v2 = 10;
break;
case 'B':
case 'b':
v9 = 11;
v2 = 11;
break;
case 'C':
case 'c':
v9 = 12;
v2 = 12;
break;
case 'D':
case 'd':
v9 = 13;
v2 = 13;
break;
case 'E':
case 'e':
v9 = 14;
v2 = 14;
break;
case 'F':
case 'f':
v9 = 15;
v2 = 15;
break;
default:
v9 = v2;
break;
}
v10 = v7;
v11 = 0;
do
{
v12 = v9 >> v11++;
result = (void *)(v12 & 1);
*(_BYTE *)(*a1 + v10++) = (_BYTE)result;
}
while ( v11 != 4 );
v7 += 4LL;
--v8;
}
while ( v7 != 4LL * (unsigned int)v6 + 4 );
}
return result;
}

original_code:
void hex2BitArray(bitArray *r, const char * hex){
 int len = strlen(hex);
 int l = len * 4 , i , j = 0 , z = 0;
 resizeBitArray(r , l);
 for(i = len-1; i >= 0; i--)
 {
  byte num;
  switch(hex[i]){
   case '0' : num = 0; break;
   case '1' : num = 1; break;
   case '2' : num = 2; break;
   case '3' : num = 3; break;
   case '4' : num = 4; break;
   case '5' : num = 5; break;
   case '6' : num = 6; break;
   case '7' : num = 7; break;
   case '8' : num = 8; break;
   case '9' : num = 9; break;
   case 'A' : num = 10; break;
   case 'B' : num = 11; break;
   case 'C' : num = 12; break;
   case 'D' : num = 13; break;
   case 'E' : num = 14; break;
   case 'F' : num = 15; break;
   case 'a' : num = 10; break;
   case 'b' : num = 11; break;
   case 'c' : num = 12; break;
   case 'd' : num = 13; break;
   case 'e' : num = 14; break;
   case 'f' : num = 15; break;
   default : break;
   }
   for(j = 0 ; j < 4; j++)
   r->array[z++] = (num & (1 << j)) ? 1 : 0;
 }
}

canonical_original_code:
void hex2BitArray(struct array_of_bit *r, char *hex){
 int len = strlen(hex);
 int l = len * 4; int i; int j = 0; int z = 0;
 resizeBitArray(r , l);
 for(i = len-1; i >= 0; i--)
 {
  unsigned int num;
  switch(hex[i]){
   case '0' : num = 0; break;
   case '1' : num = 1; break;
   case '2' : num = 2; break;
   case '3' : num = 3; break;
   case '4' : num = 4; break;
   case '5' : num = 5; break;
   case '6' : num = 6; break;
   case '7' : num = 7; break;
   case '8' : num = 8; break;
   case '9' : num = 9; break;
   case 'A' : num = 10; break;
   case 'B' : num = 11; break;
   case 'C' : num = 12; break;
   case 'D' : num = 13; break;
   case 'E' : num = 14; break;
   case 'F' : num = 15; break;
   case 'a' : num = 10; break;
   case 'b' : num = 11; break;
   case 'c' : num = 12; break;
   case 'd' : num = 13; break;
   case 'e' : num = 14; break;
   case 'f' : num = 15; break;
   default : break;
   }
   for(j = 0 ; j < 4; j++)
   r->array[z++] = (num & (1 << j)) ? 1 : 0;
 }
}

variable_types: len int

variable_types: j int

variable_types:
num
unsigned int


printBinaryBitArray

decompiled_code:
int __fastcall printBinaryBitArray(__int64 a1)
{
__int64 v1; // rsi
__int64 v2; // rbx
__int64 v3; // rsi

putchar(123);
v1 = *(unsigned int *)(a1 + 8);
if ( (int)v1 > 0 )
{
v2 = 0LL;
do
{
v3 = *(unsigned __int8 *)(*(_QWORD *)a1 + v2++);
printf(" %d", v3);
v1 = *(unsigned int *)(a1 + 8);
}
while ( (int)v1 > (int)v2 );
}
return printf(" } : %d \n", v1);
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1)
{
__int64 v1; // rsi
__int64 v2; // rbx
__int64 v3; // rsi

putchar(123);
v1 = *(unsigned int *)(a1 + 8);
if ( (int)v1 > 0 )
{
v2 = 0LL;
do
{
v3 = *(unsigned __int8 *)(*(_QWORD *)a1 + v2++);
printf(" %d", v3);
v1 = *(unsigned int *)(a1 + 8);
}
while ( (int)v1 > (int)v2 );
}
return printf(" } : %d \n", v1);
}

original_code:
void printBinaryBitArray(const bitArray *bA){
 int i;
 printf("{");
 for(i = 0; i < bA->length; i++)
  printf(" %d", bA->array[i]);
 printf(" } : %d \n", bA->length);
}

canonical_original_code:
void printBinaryBitArray(struct array_of_bit *bA){
 int i;
 printf("{");
 for(i = 0; i < bA->length; i++)
  printf(" %d", bA->array[i]);
 printf(" } : %d \n", bA->length);
}


printHexBitArray

decompiled_code:
int __fastcall printHexBitArray(__int64 a1)
{
int v1; // ebx
int v2; // er12
int v4; // er12
void *v5; // rsp
__int64 v6; // rbx
int v7; // edi
char v9[48]; // [rsp+0h] [rbp-30h] BYREF

v1 = *(_DWORD *)(a1 + 8);
if ( (v1 & 3) != 0 )
return puts("The array needs to be a multiple of 4 (Beta)\n");
v2 = v1 + 3;
if ( v1 >= 0 )
v2 = *(_DWORD *)(a1 + 8);
v4 = v2 >> 2;
v5 = alloca(v4);
bitArray2Hex(a1, v9);
printf("{ ");
if ( v1 > 3 )
{
v6 = 0LL;
do
{
v7 = v9[v6++];
putchar(v7);
}
while ( v4 > (int)v6 );
}
return printf(" } : %d \n", *(unsigned int *)(a1 + 8));
}

canonical_decompiled_code:
int __fastcall func11(__int64 a1)
{
int v1; // ebx
int v2; // er12
int v4; // er12
void *v5; // rsp
__int64 v6; // rbx
int v7; // edi
char v9[48]; // [rsp+0h] [rbp-30h] BYREF

v1 = *(_DWORD *)(a1 + 8);
if ( (v1 & 3) != 0 )
return puts("The array needs to be a multiple of 4 (Beta)\n");
v2 = v1 + 3;
if ( v1 >= 0 )
v2 = *(_DWORD *)(a1 + 8);
v4 = v2 >> 2;
v5 = alloca(v4);
func4(a1, v9);
printf("{ ");
if ( v1 > 3 )
{
v6 = 0LL;
do
{
v7 = v9[v6++];
putchar(v7);
}
while ( v4 > (int)v6 );
}
return printf(" } : %d \n", *(unsigned int *)(a1 + 8));
}

original_code:
void printHexBitArray(const bitArray *bA){
 if(bA->length % 4 != 0)
 {
  printf("The array needs to be a multiple of 4 (Beta)\n\n");
  return;
 }
 int l = bA->length / 4;
 char str[l];
 bitArray2Hex(bA , str);
 int i;
 printf("{ ");
 for(i = 0; i < l; i++)
  printf("%c" , str[i]);
 printf(" } : %d \n", bA->length);
}

canonical_original_code:
void printHexBitArray(struct array_of_bit *bA){
 if(bA->length % 4 != 0)
 {
  printf("The array needs to be a multiple of 4 (Beta)\n\n");
  return;
 }
 int l = bA->length / 4;
 char str[-1];
 bitArray2Hex(bA , str);
 int i;
 printf("{ ");
 for(i = 0; i < l; i++)
  printf("%c" , str[i]);
 printf(" } : %d \n", bA->length);
}

variable_types:
str
char [-1]


getGradeBitArray

decompiled_code:
__int64 __fastcall getGradeBitArray(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // er8
bool v3; // cl
bool v4; // dl

v1 = *(_DWORD *)(a1 + 8) - 1;
do
{
v2 = v1;
v3 = *(_BYTE *)(*(_QWORD *)a1 + v1) != 1;
v4 = (int)v1-- > 0;
}
while ( v4 && v3 );
return v2;
}

original_code:
int getGradeBitArray(const bitArray *a){
 int i = a->length;
 do{
  i --;
 }while(a->array[i] != 1 && i > 0);
 return i;
}

canonical_original_code:
int getGradeBitArray(struct array_of_bit *a){
 int i = a->length;
 do{
  i --;
 }while(a->array[i] != 1 && i > 0);
 return i;
}

return_type: int


cmpBitArray

decompiled_code:
__int64 __fastcall cmpBitArray(__int64 a1)
{
__int64 v1; // r10
int v2; // er8
int v3; // er9
_QWORD *v4; // r10
_QWORD *v5; // r11
__int64 result; // rax
int v7; // er9
__int64 v8; // rax
unsigned __int8 v9; // dl
unsigned __int8 v10; // cl

getGradeBitArray(a1);
v2 = getGradeBitArray(v1);
result = 1LL;
if ( v3 <= v2 )
{
result = 0xFFFFFFFFLL;
if ( v3 >= v2 )
{
v7 = v3 - 1;
if ( v7 < 0 )
{
LABEL_8:
result = 0LL;
}
else
{
v8 = v7;
while ( 1 )
{
v9 = *(_BYTE *)(*v5 + v8);
v10 = *(_BYTE *)(*v4 + v8);
if ( v9 != v10 )
break;
if ( (int)--v8 < 0 )
goto LABEL_8;
}
result = v10 < v9 ? 1 : -1;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
__int64 v1; // r10
int v2; // er8
int v3; // er9
_QWORD *v4; // r10
_QWORD *v5; // r11
__int64 result; // rax
int v7; // er9
__int64 v8; // rax
unsigned __int8 v9; // dl
unsigned __int8 v10; // cl

func12(a1);
v2 = func12(v1);
result = 1LL;
if ( v3 <= v2 )
{
result = 0xFFFFFFFFLL;
if ( v3 >= v2 )
{
v7 = v3 - 1;
if ( v7 < 0 )
{
LABEL_8:
result = 0LL;
}
else
{
v8 = v7;
while ( 1 )
{
v9 = *(_BYTE *)(*v5 + v8);
v10 = *(_BYTE *)(*v4 + v8);
if ( v9 != v10 )
break;
if ( (int)--v8 < 0 )
goto LABEL_8;
}
result = v10 < v9 ? 1 : -1;
}
}
}
return result;
}

original_code:
int cmpBitArray(const bitArray *a , const bitArray *b){
 int aG = getGradeBitArray(a);
 int bG = getGradeBitArray(b);
 if(aG > bG)
  return 1;
 if(aG < bG)
  return -1;
 int i;
 for(i = aG - 1; i >= 0; i--)
  if(a->array[i] != b->array[i])
   return (a->array[i] > b->array[i]) ? 1 : -1;
 return 0;
}

canonical_original_code:
int cmpBitArray(struct array_of_bit *a, struct array_of_bit *b){
 int aG = getGradeBitArray(a);
 int bG = getGradeBitArray(b);
 if(aG > bG)
  return 1;
 if(aG < bG)
  return -1;
 int i;
 for(i = aG - 1; i >= 0; i--)
  if(a->array[i] != b->array[i])
   return (a->array[i] > b->array[i]) ? 1 : -1;
 return 0;
}

variable_types:
b
struct array_of_bit *

variable_types: aG int

variable_types: bG int


sumBitArray

original_code:
void sumBitArray(bitArray *r , const bitArray * a , const bitArray * b){
  int l = (a->length > b->length) ? a->length : b->length;
  bitArray * tmp = newBitArray(l);
  if(a->length > b->length)
   memcpy(tmp->array , a->array , sizeof(bit) * l);
  else
   memcpy(tmp->array , b->array , sizeof(bit) * l);
  int i , e = (a->length < b->length) ? a->length : b->length;
  for(i = 0; i < e; i++)
   tmp->array[i] = a->array[i] ^ b->array[i];
  copyBitArray(r , tmp);
  deleteBitArray(tmp);
}

canonical_original_code:
void sumBitArray(struct array_of_bit *r, struct array_of_bit *a, struct array_of_bit *b){
  int l = (a->length > b->length) ? a->length : b->length;
  struct array_of_bit *tmp = newBitArray(l);
  if(a->length > b->length)
   memcpy(tmp->array , a->array , sizeof(bit) * l);
  else
   memcpy(tmp->array , b->array , sizeof(bit) * l);
  int i; int e = (a->length < b->length) ? a->length : b->length;
  for(i = 0; i < e; i++)
   tmp->array[i] = a->array[i] ^ b->array[i];
  copyBitArray(r , tmp);
  deleteBitArray(tmp);
}

variable_types: struct array_of_bit { unsigned int *array; int length; } *

variable_types:
a
struct array_of_bit *

variable_types: l int


shiftBitArray

decompiled_code:
void *__fastcall shiftBitArray(__int64 a1, int a2)
{
size_t v2; // rdx
void *v3; // r14
int v4; // ebx
void *v5; // rsp
void *result; // rax
size_t v7; // r15
size_t v8; // r15
char src[48]; // [rsp+0h] [rbp-30h] BYREF

v2 = *(int *)(a1 + 8);
v3 = *(void **)a1;
v4 = *(_DWORD *)(a1 + 8);
v5 = alloca(v2);
result = memcpy(src, *(const void **)a1, v2);
if ( a2 > 0 )
{
v7 = a2 % v4;
memcpy(v3, &src[v4 - (int)v7], v7);
result = memcpy((void *)(v7 + *(_QWORD *)a1), src, *(_DWORD *)(a1 + 8) - (int)v7);
}
else if ( a2 )
{
v8 = -(a2 % v4);
memcpy(v3, &src[v8], v4 + a2 % v4);
result = memcpy((void *)(*(_QWORD *)a1 + *(_DWORD *)(a1 + 8) + a2 % v4), src, v8);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func15(__int64 a1, int a2)
{
size_t v2; // rdx
void *v3; // r14
int v4; // ebx
void *v5; // rsp
void *result; // rax
size_t v7; // r15
size_t v8; // r15
char src[48]; // [rsp+0h] [rbp-30h] BYREF

v2 = *(int *)(a1 + 8);
v3 = *(void **)a1;
v4 = *(_DWORD *)(a1 + 8);
v5 = alloca(v2);
result = memcpy(src, *(const void **)a1, v2);
if ( a2 > 0 )
{
v7 = a2 % v4;
memcpy(v3, &src[v4 - (int)v7], v7);
result = memcpy((void *)(v7 + *(_QWORD *)a1), src, *(_DWORD *)(a1 + 8) - (int)v7);
}
else if ( a2 )
{
v8 = -(a2 % v4);
memcpy(v3, &src[v8], v4 + a2 % v4);
result = memcpy((void *)(*(_QWORD *)a1 + *(_DWORD *)(a1 + 8) + a2 % v4), src, v8);
}
return result;
}

original_code:
void shiftBitArray(bitArray * a , const int shift){
  bit tmp[a->length];
  memcpy(tmp , a->array, sizeof(bit) * a->length);
  if(shift > 0){
   int len = abs(shift % a->length);
   memcpy(a->array , tmp + (sizeof(bit) * (a->length - len)) , sizeof(bit) * len);
   memcpy(a->array + (sizeof(bit) * len) , tmp , sizeof(bit) * (a->length - len));
  }
  else if(shift < 0){
   int len = abs(shift % a->length);
   memcpy(a->array , tmp + (sizeof(bit) * len) , sizeof(bit) * (a->length - len));
   memcpy(a->array + (sizeof(bit) * (a->length - len)) , tmp , sizeof(bit) * len);
  }
}

canonical_original_code:
void shiftBitArray(struct array_of_bit *a, int shift){
  unsigned int tmp[-1];
  memcpy(tmp , a->array, sizeof(bit) * a->length);
  if(shift > 0){
   int len = abs(shift % a->length);
   memcpy(a->array , tmp + (sizeof(bit) * (a->length - len)) , sizeof(bit) * len);
   memcpy(a->array + (sizeof(bit) * len) , tmp , sizeof(bit) * (a->length - len));
  }
  else if(shift < 0){
   int len = abs(shift % a->length);
   memcpy(a->array , tmp + (sizeof(bit) * len) , sizeof(bit) * (a->length - len));
   memcpy(a->array + (sizeof(bit) * (a->length - len)) , tmp , sizeof(bit) * len);
  }
}

variable_types: shift int

variable_types:
tmp
unsigned int [-1]


mulBitArray

decompiled_code:
void __fastcall mulBitArray(__int64 a1, _QWORD *a2, _QWORD *a3)
{
int v4; // er15
int v5; // er14
_DWORD *v6; // rbp
__int64 i; // rcx
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rdx

v4 = getGradeBitArray((__int64)a2);
v5 = getGradeBitArray((__int64)a3);
v6 = newBitArray(v4 + v5 + 1);
if ( v4 >= 0 )
{
for ( i = 0LL; ; i = v8 )
{
if ( *(_BYTE *)(*a2 + i) == 1 && v5 >= 0 )
{
v9 = 0LL;
do
{
*(_BYTE *)(*(_QWORD *)v6 + v9 + i) ^= *(_BYTE *)(*a3 + v9);
v10 = v9++;
}
while ( v10 != v5 );
v8 = i + 1;
if ( v4 == i )
break;
}
else
{
v8 = i + 1;
if ( v4 == i )
break;
}
}
}
copyBitArray(a1, (__int64)v6);
deleteBitArray(v6);
}

original_code:
void mulBitArray(bitArray *r , const bitArray * a , const bitArray * b){
 int aG = getGradeBitArray(a);
 int bG = getGradeBitArray(b);
 int l = aG + bG + 1;
 bitArray * tmp = newBitArray(l);
 int i;
 for(i = 0; i <= aG; i++)
 {
  if(a->array[i] == 1)
  {
   int j , c = i;
   for(j = 0; j <= bG; j++)
    tmp->array[c++] ^= b->array[j];
  }
 }
 copyBitArray(r , tmp);
 deleteBitArray(tmp);
}

canonical_original_code:
void mulBitArray(struct array_of_bit *r, struct array_of_bit *a, struct array_of_bit *b){
 int aG = getGradeBitArray(a);
 int bG = getGradeBitArray(b);
 int l = aG + bG + 1;
 struct array_of_bit *tmp = newBitArray(l);
 int i;
 for(i = 0; i <= aG; i++)
 {
  if(a->array[i] == 1)
  {
   int j; int c = i;
   for(j = 0; j <= bG; j++)
    tmp->array[c++] ^= b->array[j];
  }
 }
 copyBitArray(r , tmp);
 deleteBitArray(tmp);
}

variable_types: c int


openFifo

decompiled_code:
__int64 __fastcall openFifo(char *path)
{
unlink(path);
if ( mkfifo(path, 0x180u) >= 0 )
return openChannel(path);
perror("mkfifo()");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *path)
{
unlink(path);
if ( mkfifo(path, 0x180u) >= 0 )
return openChannel(path);
perror("mkfifo()");
return 0xFFFFFFFFLL;
}

original_code:
int openFifo(const char * pathname){
 unlink(pathname);
 if(mkfifo(pathname,0600) < 0 ) {
  perror("mkfifo()");
  return -1;
 }
 return (openChannel(pathname));
}

canonical_original_code:
int openFifo(char *pathname){
 unlink(pathname);
 if(mkfifo(pathname,0600) < 0 ) {
  perror("mkfifo()");
  return -1;
 }
 return (openChannel(pathname));
}

variable_types:
pathname
char *


communication

decompiled_code:
__int64 communication()
{
FILE *v0; // r13
size_t v1; // r12
unsigned __int64 v2; // rcx
unsigned __int16 v3; // bx
int v4; // eax
int v5; // ebx
__int64 result; // rax
char v7[2048]; // [rsp+0h] [rbp-1028h] BYREF
char dest[2088]; // [rsp+800h] [rbp-828h] BYREF

v0 = fopen("server_folder/clientMSG.txt", "w+");
if ( v0 )
{
while ( 1 )
{
v4 = readFromPipe((unsigned int)inputChannel, v7);
v5 = v4;
if ( v4 == -1 )
goto LABEL_10;
v1 = v4;
printMsg("Client to server ---> ", v7, (unsigned __int16)v4);
v2 = 4LL;
if ( (unsigned __int64)v5 <= 4 )
v2 = v5;
if ( !memcmp(v7, "Bye", v2) && v5 == 3 )
break;
v3 = v5 + 10;
fputs(v7, v0);
strcpy(dest, "ACK MSG : ");
strncat(dest, v7, v1);
if ( (int)writeInPipe((unsigned int)outputChannel, dest, v3) < 0 )
{
fwrite("\n **** communication write error **** \n\n", 1uLL, 0x28uLL, stderr);
LABEL_10:
fclose(v0);
return 5LL;
}
printMsg("Server to client ---> ", dest, v3);
fputc(10, stderr);
}
fclose(v0);
result = 4LL;
}
else
{
perror("Server txt file ");
result = 5LL;
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
FILE *v0; // r13
size_t v1; // r12
unsigned __int64 v2; // rcx
unsigned __int16 v3; // bx
int v4; // eax
int v5; // ebx
__int64 result; // rax
char v7[2048]; // [rsp+0h] [rbp-1028h] BYREF
char dest[2088]; // [rsp+800h] [rbp-828h] BYREF

v0 = fopen("server_folder/clientMSG.txt", "w+");
if ( v0 )
{
while ( 1 )
{
v4 = readFromPipe((unsigned int)inputChannel, v7);
v5 = v4;
if ( v4 == -1 )
goto LABEL_10;
v1 = v4;
printMsg("Client to server ---> ", v7, (unsigned __int16)v4);
v2 = 4LL;
if ( (unsigned __int64)v5 <= 4 )
v2 = v5;
if ( !memcmp(v7, "Bye", v2) && v5 == 3 )
break;
v3 = v5 + 10;
fputs(v7, v0);
strcpy(dest, "ACK MSG : ");
strncat(dest, v7, v1);
if ( (int)writeInPipe((unsigned int)outputChannel, dest, v3) < 0 )
{
fwrite("\n **** communication write error **** \n\n", 1uLL, 0x28uLL, stderr);
LABEL_10:
fclose(v0);
return 5LL;
}
printMsg("Server to client ---> ", dest, v3);
fputc(10, stderr);
}
fclose(v0);
result = 4LL;
}
else
{
perror("Server txt file ");
result = 5LL;
}
return result;
}

original_code:
serverState communication(){
 char msg[2048];
 int length = 0;
 do{
 encType = cipherSpec.symmetric_cipher;
 fprintf(stderr , "\n< Client message , communication > \n");
 length = receive_and_decrypt(msg);
 if(strncmp(msg , "Bye" , length) == 0 && length == strlen("Bye")){
  fprintf(stderr , "%s" , "Bye");
  encType = PLAIN;
  return CLOSING;
 }
 encType = PLAIN;
 fprintf(stderr , "\n< Server response , communication >\n" );
 encrypt_and_send(msg , length);
 printMsg("" , msg ,(u_int16_t) length);
 }while(1);
}

canonical_original_code:
enum serverState communication(){
 char msg[2048];
 int length = 0;
 do{
 encType = cipherSpec.symmetric_cipher;
 fprintf(stderr , "\n< Client message , communication > \n");
 length = receive_and_decrypt(msg);
 if(strncmp(msg , "Bye" , length) == 0 && length == strlen("Bye")){
  fprintf(stderr , "%s" , "Bye");
  encType = PLAIN;
  return CLOSING;
 }
 encType = PLAIN;
 fprintf(stderr , "\n< Server response , communication >\n" );
 encrypt_and_send(msg , length);
 printMsg("" , msg ,(unsigned int) length);
 }while(1);
}

variable_types:
msg
char [2048]

return_type: enum serverState { WAITING=0, HANDSHAKE=1, AUTHENTICATED=2, COMMUNICATION=3, CLOSING=4, ERROR=5 }


authentication

decompiled_code:
__int64 authentication()
{
return 2LL;
}

canonical_decompiled_code:
__int64 func2()
{
return 2LL;
}

canonical_original_code:
enum serverState authentication(){
 return AUTHENTICATED;
}

user_defined_types: enum serverState { WAITING=0, HANDSHAKE=1, AUTHENTICATED=2, COMMUNICATION=3, CLOSING=4, ERROR=5 }


keyExchange

decompiled_code:
__int64 keyExchange()
{
return 3LL;
}

canonical_decompiled_code:
__int64 func3()
{
return 3LL;
}

canonical_original_code:
enum serverState keyExchange(){
 return COMMUNICATION;
}


original_code:
void ALL5_init(ALL5 *all5){
 LFSR temp = { ((void *)0) , ((void *)0) , 0};
 all5->reg[0] = temp;
 LFSR_init(&all5->reg[0] , ALL5_reg1 , ALL5_poly1 , ALL5_degree[0]);
 all5->reg[1] = temp;
 LFSR_init(&all5->reg[1] , ALL5_reg2 , ALL5_poly2 , ALL5_degree[1]);
 all5->reg[2] = temp;
 LFSR_init(&all5->reg[2] , ALL5_reg3 , ALL5_poly3 , ALL5_degree[2]);
 all5->reg[3] = temp;
 LFSR_init(&all5->reg[3] , ALL5_reg4 , ALL5_poly4 , ALL5_degree[3]);
 all5->reg[4] = temp;
 LFSR_init(&all5->reg[4] , ALL5_reg5 , ALL5_poly5 , ALL5_degree[4]);
}

canonical_original_code:
void ALL5_init(struct ALL5 *all5){
 struct LFSR temp = { ((void *)0) , ((void *)0) , 0};
 all5->reg[0] = temp;
 LFSR_init(&all5->reg[0] , ALL5_reg1 , ALL5_poly1 , ALL5_degree[0]);
 all5->reg[1] = temp;
 LFSR_init(&all5->reg[1] , ALL5_reg2 , ALL5_poly2 , ALL5_degree[1]);
 all5->reg[2] = temp;
 LFSR_init(&all5->reg[2] , ALL5_reg3 , ALL5_poly3 , ALL5_degree[2]);
 all5->reg[3] = temp;
 LFSR_init(&all5->reg[3] , ALL5_reg4 , ALL5_poly4 , ALL5_degree[3]);
 all5->reg[4] = temp;
 LFSR_init(&all5->reg[4] , ALL5_reg5 , ALL5_poly5 , ALL5_degree[4]);
}

variable_types: struct ALL5 { struct LFSR { unsigned int *reg; unsigned int *poly; unsigned int degree; } reg[5]; } *


decompiled_code:
__int64 __fastcall ALL5_delete(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // rbx
__int64 v3; // rdi
__int64 result; // rax

v1 = a1 + 120;
v2 = a1;
do
{
v3 = v2;
v2 += 24LL;
result = LFSR_delete(v3);
}
while ( v2 != v1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // rbx
__int64 v3; // rdi
__int64 result; // rax

v1 = a1 + 120;
v2 = a1;
do
{
v3 = v2;
v2 += 24LL;
result = LFSR_delete(v3);
}
while ( v2 != v1 );
return result;
}

original_code:
void ALL5_delete(ALL5 *all5){
 int i;
 for(i = 0; i < 5; i++)
  LFSR_delete(&all5->reg[i]);
}

canonical_original_code:
void ALL5_delete(struct ALL5 *all5){
 int i;
 for(i = 0; i < 5; i++)
  LFSR_delete(&all5->reg[i]);
}

variable_types: i int

user_defined_types: struct LFSR { unsigned int *reg; unsigned int *poly; unsigned int degree; }


decompiled_code:
__int64 __fastcall ALL5_update(__int64 a1)
{
char *v2; // rbx
__int64 v3; // rdi
char v5; // [rsp+Bh] [rbp-1Dh] BYREF
char v6; // [rsp+Ch] [rbp-1Ch]
char v7; // [rsp+Dh] [rbp-1Bh]
char v8; // [rsp+Eh] [rbp-1Ah]
char v9; // [rsp+Fh] [rbp-19h]
char v10; // [rsp+10h] [rbp-18h] BYREF

v2 = &v5;
do
{
v3 = a1;
++v2;
a1 += 24LL;
*(v2 - 1) = LFSR_update(v3);
}
while ( v2 != &v10 );
return (unsigned __int8)(v7 & v8) ^ (unsigned __int8)(v9 & v6) ^ (unsigned __int8)(v6 & v7) ^ (unsigned int)(unsigned __int8)(v8 & v5);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
char *v2; // rbx
__int64 v3; // rdi
char v5; // [rsp+Bh] [rbp-1Dh] BYREF
char v6; // [rsp+Ch] [rbp-1Ch]
char v7; // [rsp+Dh] [rbp-1Bh]
char v8; // [rsp+Eh] [rbp-1Ah]
char v9; // [rsp+Fh] [rbp-19h]
char v10; // [rsp+10h] [rbp-18h] BYREF

v2 = &v5;
do
{
v3 = a1;
++v2;
a1 += 24LL;
*(v2 - 1) = LFSR_update(v3);
}
while ( v2 != &v10 );
return (unsigned __int8)(v7 & v8) ^ (unsigned __int8)(v9 & v6) ^ (unsigned __int8)(v6 & v7) ^ (unsigned int)(unsigned __int8)(v8 & v5);
}

original_code:
bit ALL5_update(ALL5 *all5){
 int count_zero = 0;
 int i;
 bit out[5];
 for(i = 0; i < 5; i++)
  out[i] = LFSR_update(&all5->reg[i]);
 bit result = (out[0] & out[3]) ^ (out[1] & out[2]) ^ (out[1] & out[4]) ^ (out[2] & out[3]);
 return result;
}

canonical_original_code:
unsigned int ALL5_update(struct ALL5 *all5){
 int count_zero = 0;
 int i;
 unsigned int out[5];
 for(i = 0; i < 5; i++)
  out[i] = LFSR_update(&all5->reg[i]);
 unsigned int result = (out[0] & out[3]) ^ (out[1] & out[2]) ^ (out[1] & out[4]) ^ (out[2] & out[3]);
 return result;
}

variable_types:
out
unsigned int [5]

variable_types:
result
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall ALL5_warmUpStream(__int64 a1, int a2)
{
int i; // ebx
__int64 result; // rax

if ( a2 )
{
for ( i = 0; i != a2; ++i )
result = ALL5_update(a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
int i; // ebx
__int64 result; // rax

if ( a2 )
{
for ( i = 0; i != a2; ++i )
result = func2(a1);
}
return result;
}

original_code:
void ALL5_warmUpStream(ALL5 *all5, unsigned int stream){
 int i;
 for(i = 0; i < stream; i++)
  ALL5_update(all5);
}

canonical_original_code:
void ALL5_warmUpStream(struct ALL5 *all5, unsigned int stream){
 int i;
 for(i = 0; i < stream; i++)
  ALL5_update(all5);
}

variable_types:
stream
unsigned int


decompiled_code:
void __fastcall ALL5_getStream(__int64 a1, _BYTE *a2, int a3)
{
__int64 v3; // r12
_BYTE *v4; // rbx

if ( a3 )
{
v3 = (__int64)&a2[a3 - 1 + 1];
v4 = a2;
do
*v4++ = ALL5_update(a1);
while ( v4 != (_BYTE *)v3 );
}
}

original_code:
void ALL5_getStream(ALL5 *all5, bit *result, unsigned int stream){
 int i;
 for(i = 0; i < stream; i++)
  result[i] = ALL5_update(all5);
}

canonical_original_code:
void ALL5_getStream(struct ALL5 *all5, unsigned int *result, unsigned int stream){
 int i;
 for(i = 0; i < stream; i++)
  result[i] = ALL5_update(all5);
}

variable_types:
result
unsigned int *


decompiled_code:
__int64 __fastcall ALL5_encrypt(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v4; // r14
__int64 v6; // rbx
char v7; // dl
__int64 i; // rcx
__int64 result; // rax
char v10[48]; // [rsp+0h] [rbp-30h] BYREF

if ( a4 )
{
v4 = 0LL;
v6 = a4;
do
{
ALL5_getStream(a1, v10, 8);
v7 = *(_BYTE *)(a2 + v4);
for ( i = 0LL; i != 8; ++i )
{
result = (unsigned __int8)v10[i] << i;
v7 ^= result;
}
*(_BYTE *)(a3 + v4++) = v7;
}
while ( v4 != v6 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v4; // r14
__int64 v6; // rbx
char v7; // dl
__int64 i; // rcx
__int64 result; // rax
char v10[48]; // [rsp+0h] [rbp-30h] BYREF

if ( a4 )
{
v4 = 0LL;
v6 = a4;
do
{
func4(a1, v10, 8);
v7 = *(_BYTE *)(a2 + v4);
for ( i = 0LL; i != 8; ++i )
{
result = (unsigned __int8)v10[i] << i;
v7 ^= result;
}
*(_BYTE *)(a3 + v4++) = v7;
}
while ( v4 != v6 );
}
return result;
}

original_code:
void ALL5_encrypt(ALL5 *all5, byte *plaintext, byte *chipertext, unsigned int length){
 int i , j;
 for(i = 0; i < length; i++)
 {
  bit temp[8];
  ALL5_getStream(all5 , temp , 8);
  byte currentByte = plaintext[i];
  for(j = 0; j < 8; j++)
  {
  bit x = temp[j] << j;
  currentByte ^= x;
  }
  chipertext[i] = currentByte;
 }
}

canonical_original_code:
void ALL5_encrypt(struct ALL5 *all5, unsigned int *plaintext, unsigned int *chipertext, unsigned int length){
 int i; int j;
 for(i = 0; i < length; i++)
 {
  unsigned int temp[8];
  ALL5_getStream(all5 , temp , 8);
  unsigned int currentByte = plaintext[i];
  for(j = 0; j < 8; j++)
  {
  unsigned int x = temp[j] << j;
  currentByte ^= x;
  }
  chipertext[i] = currentByte;
 }
}

variable_types:
plaintext
unsigned int *

variable_types:
chipertext
unsigned int *

variable_types:
length
unsigned int

variable_types: j int

variable_types:
temp
unsigned int [8]

variable_types:
currentByte
unsigned int

variable_types:
x
unsigned int


decompiled_code:
__int64 __fastcall ALL5_decrypt(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v4; // r14
__int64 v6; // rbx
char v7; // dl
__int64 i; // rcx
__int64 result; // rax
char v10[48]; // [rsp+0h] [rbp-30h] BYREF

if ( a4 )
{
v4 = 0LL;
v6 = a4;
do
{
ALL5_getStream(a1, v10, 8);
v7 = *(_BYTE *)(a3 + v4);
for ( i = 0LL; i != 8; ++i )
{
result = (unsigned __int8)v10[i] << i;
v7 ^= result;
}
*(_BYTE *)(a2 + v4++) = v7;
}
while ( v4 != v6 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v4; // r14
__int64 v6; // rbx
char v7; // dl
__int64 i; // rcx
__int64 result; // rax
char v10[48]; // [rsp+0h] [rbp-30h] BYREF

if ( a4 )
{
v4 = 0LL;
v6 = a4;
do
{
func4(a1, v10, 8);
v7 = *(_BYTE *)(a3 + v4);
for ( i = 0LL; i != 8; ++i )
{
result = (unsigned __int8)v10[i] << i;
v7 ^= result;
}
*(_BYTE *)(a2 + v4++) = v7;
}
while ( v4 != v6 );
}
return result;
}

original_code:
void ALL5_decrypt(ALL5 *all5, byte *plaintext, byte *chipertext, unsigned int length){
 int i , j;
 for(i = 0; i < length; i++)
 {
  bit temp[8];
  ALL5_getStream(all5 , temp , 8);
  byte currentByte = chipertext[i];
  for(j = 0; j < 8; j++)
  {
  bit x = temp[j] << j;
  currentByte ^= x;
  }
  plaintext[i] = currentByte;
 }
}

canonical_original_code:
void ALL5_decrypt(struct ALL5 *all5, unsigned int *plaintext, unsigned int *chipertext, unsigned int length){
 int i; int j;
 for(i = 0; i < length; i++)
 {
  unsigned int temp[8];
  ALL5_getStream(all5 , temp , 8);
  unsigned int currentByte = chipertext[i];
  for(j = 0; j < 8; j++)
  {
  unsigned int x = temp[j] << j;
  currentByte ^= x;
  }
  plaintext[i] = currentByte;
 }
}


decompiled_code:
__int64 __fastcall open_fifo(char *path)
{
unlink(path);
if ( mkfifo(path, 0x180u) < 0 )
{
perror("mkfifo()");
exit(1);
}
return open_channel(path);
}

canonical_decompiled_code:
__int64 __fastcall func7(char *path)
{
unlink(path);
if ( mkfifo(path, 0x180u) < 0 )
{
perror("mkfifo()");
exit(1);
}
return func10(path);
}

original_code:
int open_fifo(const char * pathname)
{
 unlink(pathname);
 if( mkfifo(pathname,0600) < 0 ) {
  perror("mkfifo()");
  exit(1);
 }
 return (open_channel(pathname));
}

canonical_original_code:
int open_fifo(char *pathname)
{
 unlink(pathname);
 if( mkfifo(pathname,0600) < 0 ) {
  perror("mkfifo()");
  exit(1);
 }
 return (open_channel(pathname));
}


decompiled_code:
__int64 __fastcall wait_connection(int a1)
{
__int64 result; // rax
char *s2; // [rsp+8h] [rbp-10h]

if ( read_msg(a1) == 6 )
result = (unsigned int)-(strncasecmp("Hello!", s2, 6uLL) != 0);
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
__int64 result; // rax
char *s2; // [rsp+8h] [rbp-10h]

if ( func12(a1) == 6 )
result = (unsigned int)-(strncasecmp("Hello!", s2, 6uLL) != 0);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int wait_connection(int channel_fd)
{
 ssize_t msg_size;
 u_int8_t * buff;
 if( ((msg_size = read_msg(channel_fd,&buff)) < 0) ||
  (msg_size != strlen("Hello!") ||
  strncasecmp((const char *)"Hello!",(const char *)buff,msg_size)) ) {
  return (-1);
 }
 return (0);
}

canonical_original_code:
int wait_connection(int channel_fd)
{
 long msg_size;
 unsigned int *buff;
 if( ((msg_size = read_msg(channel_fd,&buff)) < 0) ||
  (msg_size != strlen("Hello!") ||
  strncasecmp((char *)"Hello!",(char *)buff,msg_size)) ) {
  return (-1);
 }
 return (0);
}

variable_types:
buff
unsigned int *


decompiled_code:
void __fastcall print_buff(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 i; // r12
int v3; // ebx
unsigned __int8 *v4; // rbp
int v5; // er15
const unsigned __int16 **v6; // r14
unsigned __int8 *v7; // r13
int v8; // edi

if ( a2 )
{
for ( i = 0LL; i < a2; i += 16LL )
{
v3 = 0;
v4 = (unsigned __int8 *)(a1 + i);
while ( 1 )
{
++v3;
fprintf(_bss_start, "%02X ", *v4);
if ( (unsigned __int8 *)(a1 + a2 - 1) == v4 )
break;
++v4;
if ( v3 == 16 )
goto LABEL_6;
}
while ( v3 != 16 )
{
++v3;
fwrite("-- ", 1uLL, 3uLL, _bss_start);
}
LABEL_6:
v5 = 0;
fwrite(" *** ", 1uLL, 5uLL, _bss_start);
if ( i < a2 )
{
v5 = 0;
v6 = __ctype_b_loc();
v7 = (unsigned __int8 *)(i + a1);
while ( 1 )
{
v8 = *v7;
if ( ((*v6)[*v7] & 0x4000) == 0 )
v8 = 46;
++v5;
fputc(v8, _bss_start);
if ( (unsigned __int8 *)(a1 + a2 - 1) == v7 )
goto LABEL_18;
++v7;
if ( v5 == 16 )
goto LABEL_12;
}
}
do
{
++v5;
fputc(46, _bss_start);
LABEL_18:
;
}
while ( v5 != 16 );
LABEL_12:
fputc(10, _bss_start);
}
}
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 i; // r12
int v3; // ebx
unsigned __int8 *v4; // rbp
int v5; // er15
const unsigned __int16 **v6; // r14
unsigned __int8 *v7; // r13
int v8; // edi

if ( a2 )
{
for ( i = 0LL; i < a2; i += 16LL )
{
v3 = 0;
v4 = (unsigned __int8 *)(a1 + i);
while ( 1 )
{
++v3;
fprintf(_bss_start, "%02X ", *v4);
if ( (unsigned __int8 *)(a1 + a2 - 1) == v4 )
break;
++v4;
if ( v3 == 16 )
goto LABEL_6;
}
while ( v3 != 16 )
{
++v3;
fwrite("-- ", 1uLL, 3uLL, _bss_start);
}
LABEL_6:
v5 = 0;
fwrite(" *** ", 1uLL, 5uLL, _bss_start);
if ( i < a2 )
{
v5 = 0;
v6 = __ctype_b_loc();
v7 = (unsigned __int8 *)(i + a1);
while ( 1 )
{
v8 = *v7;
if ( ((*v6)[*v7] & 0x4000) == 0 )
v8 = 46;
++v5;
fputc(v8, _bss_start);
if ( (unsigned __int8 *)(a1 + a2 - 1) == v7 )
goto LABEL_18;
++v7;
if ( v5 == 16 )
goto LABEL_12;
}
}
do
{
++v5;
fputc(46, _bss_start);
LABEL_18:
;
}
while ( v5 != 16 );
LABEL_12:
fputc(10, _bss_start);
}
}
}

original_code:
void print_buff(u_int8_t * buff, size_t buff_size)
{
 int i = 0, j;
 while( i < buff_size ) {
  j = 0;
  while( ((j + i) < buff_size) && (j < 16) ) {
   fprintf(stderr,"%02X ",buff[i+j]);
   j++;
  }
  while( j < 16 ) {
   fprintf(stderr,"-- ");
   j++;
  }
  fprintf(stderr," *** ");
  j = 0;
  while( ((j + i) < buff_size) && (j < 16) ) {
   fprintf(stderr,"%c",((*__ctype_b_loc ())[(int) ((buff[i+j]))] & (unsigned short int) _ISprint) ? buff[i+j] : '.');
   j++;
  }
  while( j < 16 ) {
   fputc('.',stderr);
   j++;
  }
      i += j;
  fputc('\n',stderr);
 }
}

canonical_original_code:
void print_buff(unsigned int *buff, unsigned long buff_size)
{
 int i = 0; int j;
 while( i < buff_size ) {
  j = 0;
  while( ((j + i) < buff_size) && (j < 16) ) {
   fprintf(stderr,"%02X ",buff[i+j]);
   j++;
  }
  while( j < 16 ) {
   fprintf(stderr,"-- ");
   j++;
  }
  fprintf(stderr," *** ");
  j = 0;
  while( ((j + i) < buff_size) && (j < 16) ) {
   fprintf(stderr,"%c",((*__ctype_b_loc ())[(int) ((buff[i+j]))] & (unsigned short) _ISprint) ? buff[i+j] : '.');
   j++;
  }
  while( j < 16 ) {
   fputc('.',stderr);
   j++;
  }
      i += j;
  fputc('\n',stderr);
 }
}


decompiled_code:
int __fastcall open_channel(const char *a1)
{
int result; // eax

result = open(a1, 2);
if ( result < 0 )
{
perror("open()");
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(const char *a1)
{
int result; // eax

result = open(a1, 2);
if ( result < 0 )
{
perror("open()");
exit(1);
}
return result;
}

original_code:
int open_channel(const char * pathname)
{
 int fd;
 if( (fd = open(pathname,02)) < 0 ) {
  perror("open()");
  exit(1);
 }
 return (fd);
}

canonical_original_code:
int open_channel(char *pathname)
{
 int fd;
 if( (fd = open(pathname,02)) < 0 ) {
  perror("open()");
  exit(1);
 }
 return (fd);
}

variable_types: fd int


decompiled_code:
// attributes: thunk
int close_channel(int fd)
{
return close(fd);
}

canonical_decompiled_code:
int func11(int fd)
{
return close(fd);
}

original_code:
void close_channel(int channel_fd)
{
 close(channel_fd);
}


decompiled_code:
ssize_t __fastcall read_msg(int fd, __int64 *a2)
{
ssize_t v2; // r12
__int16 buf[13]; // [rsp+Eh] [rbp-1Ah] BYREF

if ( read(fd, buf, 2uLL) < 0 )
goto LABEL_7;
fwrite("Reading size:\n", 1uLL, 0xEuLL, _bss_start);
print_buff((__int64)buf, 2uLL);
if ( buf[0] > 0x7FFu )
{
v2 = -1LL;
fwrite("Message too large\n", 1uLL, 0x12uLL, _bss_start);
return v2;
}
v2 = read(fd, &msg_buff_0, (unsigned __int16)buf[0]);
if ( v2 < 0 )
{
LABEL_7:
perror("read()");
exit(1);
}
*a2 = (__int64)&msg_buff_0;
fwrite("Reading message:\n", 1uLL, 0x11uLL, _bss_start);
print_buff(*a2, (unsigned __int16)buf[0]);
return v2;
}

canonical_decompiled_code:
ssize_t __fastcall func12(int fd, __int64 *a2)
{
ssize_t v2; // r12
__int16 buf[13]; // [rsp+Eh] [rbp-1Ah] BYREF

if ( read(fd, buf, 2uLL) < 0 )
goto LABEL_7;
fwrite("Reading size:\n", 1uLL, 0xEuLL, _bss_start);
func9((__int64)buf, 2uLL);
if ( buf[0] > 0x7FFu )
{
v2 = -1LL;
fwrite("Message too large\n", 1uLL, 0x12uLL, _bss_start);
return v2;
}
v2 = read(fd, &msg_buff_0, (unsigned __int16)buf[0]);
if ( v2 < 0 )
{
LABEL_7:
perror("read()");
exit(1);
}
*a2 = (__int64)&msg_buff_0;
fwrite("Reading message:\n", 1uLL, 0x11uLL, _bss_start);
func9(*a2, (unsigned __int16)buf[0]);
return v2;
}

original_code:
ssize_t read_msg(int channel_fd, u_int8_t ** msg)
{
 ssize_t read_len;
 u_int16_t msg_size;
 static u_int8_t msg_buff[2048];
 if( read(channel_fd,(void *)&msg_size,sizeof(msg_size)) < 0 ) {
  perror("read()");
  exit(1);
 }
 fprintf(stderr,"Reading size:\n");
 print_buff((u_int8_t *)(&msg_size),sizeof(msg_size));
 if( msg_size >= 2048 ) {
  fprintf(stderr,"Message too large\n");
  return (-1);
 }
 if( (read_len = read(channel_fd,(void *)msg_buff,msg_size)) < 0 ) {
  perror("read()");
  exit(1);
 }
 (*msg) = msg_buff;
 fprintf(stderr,"Reading message:\n");
 print_buff((u_int8_t *)(*msg),msg_size);
 return (read_len);
}

canonical_original_code:
long read_msg(int channel_fd, unsigned int **msg)
{
 long read_len;
 unsigned int msg_size;
 static unsigned int msg_buff[2048];
 if( read(channel_fd,(void *)&msg_size,sizeof(msg_size)) < 0 ) {
  perror("read()");
  exit(1);
 }
 fprintf(stderr,"Reading size:\n");
 print_buff((unsigned int *)(&msg_size),sizeof(msg_size));
 if( msg_size >= 2048 ) {
  fprintf(stderr,"Message too large\n");
  return (-1);
 }
 if( (read_len = read(channel_fd,(void *)msg_buff,msg_size)) < 0 ) {
  perror("read()");
  exit(1);
 }
 (*msg) = msg_buff;
 fprintf(stderr,"Reading message:\n");
 print_buff((unsigned int *)(*msg),msg_size);
 return (read_len);
}

variable_types:
msg
unsigned int **

return_type: long


decompiled_code:
__int64 __fastcall write_msg(int fd, void *buf, __int16 a3)
{
__int16 bufa[14]; // [rsp+Ch] [rbp-1Ch] BYREF

bufa[0] = a3;
if ( write(fd, bufa, 2uLL) < 0
|| (fwrite("Writing size:\n", 1uLL, 0xEuLL, _bss_start),
print_buff((__int64)bufa, 2uLL),
write(fd, buf, (unsigned __int16)bufa[0]) < 0) )
{
perror("write()");
exit(1);
}
fwrite("Writing message:\n", 1uLL, 0x11uLL, _bss_start);
print_buff((__int64)buf, (unsigned __int16)bufa[0]);
return (unsigned __int16)bufa[0];
}

canonical_decompiled_code:
__int64 __fastcall func13(int fd, void *buf, __int16 a3)
{
__int16 bufa[14]; // [rsp+Ch] [rbp-1Ch] BYREF

bufa[0] = a3;
if ( write(fd, bufa, 2uLL) < 0
|| (fwrite("Writing size:\n", 1uLL, 0xEuLL, _bss_start),
func9((__int64)bufa, 2uLL),
write(fd, buf, (unsigned __int16)bufa[0]) < 0) )
{
perror("write()");
exit(1);
}
fwrite("Writing message:\n", 1uLL, 0x11uLL, _bss_start);
func9((__int64)buf, (unsigned __int16)bufa[0]);
return (unsigned __int16)bufa[0];
}

original_code:
ssize_t write_msg(int channel_fd, const u_int8_t * msg, u_int16_t msg_size)
{
 if( write(channel_fd,(const void *)&msg_size,sizeof(msg_size)) < 0 ) {
  perror("write()");
  exit(1);
 }
 fprintf(stderr,"Writing size:\n");
 print_buff((u_int8_t *)&msg_size,sizeof(msg_size));
 if( write(channel_fd,(const void *)msg,msg_size) < 0 ) {
  perror("write()");
  exit(1);
 }
 fprintf(stderr,"Writing message:\n");
 print_buff((u_int8_t *)msg,msg_size);
 return (msg_size);
}

canonical_original_code:
long write_msg(int channel_fd, unsigned int *msg, unsigned int msg_size)
{
 if( write(channel_fd,(void *)&msg_size,sizeof(msg_size)) < 0 ) {
  perror("write()");
  exit(1);
 }
 fprintf(stderr,"Writing size:\n");
 print_buff((unsigned int *)&msg_size,sizeof(msg_size));
 if( write(channel_fd,(void *)msg,msg_size) < 0 ) {
  perror("write()");
  exit(1);
 }
 fprintf(stderr,"Writing message:\n");
 print_buff((unsigned int *)msg,msg_size);
 return (msg_size);
}

variable_types:
msg
unsigned int *


decompiled_code:
__int64 __fastcall write_OK(int a1)
{
return write_msg(a1, "OK", 2);
}

canonical_decompiled_code:
__int64 __fastcall func14(int a1)
{
return func13(a1, "OK", 2);
}

original_code:
int write_OK(int channel_fd)
{
 return (write_msg(channel_fd,(const u_int8_t *)"OK",strlen("OK")));
}

canonical_original_code:
int write_OK(int channel_fd)
{
 return (write_msg(channel_fd,(unsigned int *)"OK",strlen("OK")));
}


decompiled_code:
__int64 __fastcall write_BYE(int a1)
{
return write_msg(a1, "Bye", 3);
}

canonical_decompiled_code:
__int64 __fastcall func15(int a1)
{
return func13(a1, "Bye", 3);
}

original_code:
int write_BYE(int channel_fd)
{
 return (write_msg(channel_fd,(const u_int8_t *)"Bye",strlen("Bye")));
}

canonical_original_code:
int write_BYE(int channel_fd)
{
 return (write_msg(channel_fd,(unsigned int *)"Bye",strlen("Bye")));
}


decompiled_code:
__int64 __fastcall read_string(int a1, const char *a2)
{
ssize_t v2; // rbx
size_t v3; // rax
__int64 result; // rax
void *s1; // [rsp+8h] [rbp-20h] BYREF

v2 = read_msg(a1, (__int64 *)&s1);
v3 = strlen(a2);
if ( v3 == v2 )
result = (unsigned int)-(memcmp(s1, a2, v3) != 0);
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(int a1, const char *a2)
{
ssize_t v2; // rbx
size_t v3; // rax
__int64 result; // rax
void *s1; // [rsp+8h] [rbp-20h] BYREF

v2 = func12(a1, (__int64 *)&s1);
v3 = strlen(a2);
if ( v3 == v2 )
result = (unsigned int)-(memcmp(s1, a2, v3) != 0);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int read_string(int channel_fd, const char * str)
{
 size_t read_len;
 u_int8_t * msg;
  read_len = read_msg(channel_fd,&msg);
 if( (read_len != strlen(str) ) ||
      memcmp(msg,str,strlen(str)) )
  return (-1);
 return (0);
}

canonical_original_code:
int read_string(int channel_fd, char *str)
{
 unsigned long read_len;
 unsigned int *msg;
  read_len = read_msg(channel_fd,&msg);
 if( (read_len != strlen(str) ) ||
      memcmp(msg,str,strlen(str)) )
  return (-1);
 return (0);
}

variable_types:
str
char *


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
unsigned int v4; // ebp
__int64 v5; // [rsp+8h] [rbp-20h]

if ( !argv[1] || !argv[2] || !argv[3] )
{
fwrite("server [server->client fifo] [client->server fifo] [password file]\n", 1uLL, 0x43uLL, _bss_start);
exit(1);
}
while ( 1 )
{
fwrite("Opening server->client fifo...\n", 1uLL, 0x1FuLL, _bss_start);
v3 = open_fifo((char *)argv[1]);
fwrite("Opening client->server fifo...\n", 1uLL, 0x1FuLL, _bss_start);
v4 = open_fifo((char *)argv[2]);
fwrite("Waiting connection...\n", 1uLL, 0x16uLL, _bss_start);
if ( (int)wait_connection(v4) < 0 )
{
fwrite("Communication error...\n", 1uLL, 0x17uLL, _bss_start);
}
else
{
write_OK(v3);
read_msg(v4);
fprintf(_bss_start, "%c\n", *(unsigned __int8 *)(v5 + 2));
}
fwrite("Closing connection...\n", 1uLL, 0x16uLL, _bss_start);
write_BYE(v3);
close_channel(v3);
close_channel(v4);
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
unsigned int v4; // ebp
__int64 v5; // [rsp+8h] [rbp-20h]

if ( !argv[1] || !argv[2] || !argv[3] )
{
fwrite("server [server->client fifo] [client->server fifo] [password file]\n", 1uLL, 0x43uLL, _bss_start);
exit(1);
}
while ( 1 )
{
fwrite("Opening server->client fifo...\n", 1uLL, 0x1FuLL, _bss_start);
v3 = func7((char *)argv[1]);
fwrite("Opening client->server fifo...\n", 1uLL, 0x1FuLL, _bss_start);
v4 = func7((char *)argv[2]);
fwrite("Waiting connection...\n", 1uLL, 0x16uLL, _bss_start);
if ( (int)func8(v4) < 0 )
{
fwrite("Communication error...\n", 1uLL, 0x17uLL, _bss_start);
}
else
{
func14(v3);
func12(v4);
fprintf(_bss_start, "%c\n", *(unsigned __int8 *)(v5 + 2));
}
fwrite("Closing connection...\n", 1uLL, 0x16uLL, _bss_start);
func15(v3);
func11(v3);
func11(v4);
}
}

original_code:
int main(int argc, char ** argv)
{
 int sc_fifo_fd, cs_fifo_fd;
 u_int8_t * buff;
 if( !argv[1] || !argv[2] || !argv[3] ) {
  fprintf(stderr,"server [server->client fifo] [client->server fifo] [password file]\n");
  exit(1);
 }
main_loop:
  fprintf(stderr,"Opening server->client fifo...\n");
  sc_fifo_fd = open_fifo(argv[1]);
  fprintf(stderr,"Opening client->server fifo...\n");
  cs_fifo_fd = open_fifo(argv[2]);
  fprintf(stderr,"Waiting connection...\n");
  if( wait_connection(cs_fifo_fd) < 0 ) {
   fprintf(stderr,"Communication error...\n");
   goto next1;
  }
  write_OK(sc_fifo_fd);
  read_msg(cs_fifo_fd,&buff);
  fprintf(stderr,"%c\n",buff[2]);
next1:
  fprintf(stderr,"Closing connection...\n");
  write_BYE(sc_fifo_fd);
  close_channel(sc_fifo_fd);
  close_channel(cs_fifo_fd);
    goto main_loop ;
next2:
 fprintf(stderr,"Closing connection...\n");
 if( read_string(cs_fifo_fd,"Bye") < 0 ) {
  fprintf(stderr,"Communication error\n");
  goto next2;
 }
 close_channel(sc_fifo_fd);
 close_channel(cs_fifo_fd);
goto main_loop ;
 exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
 int sc_fifo_fd; int cs_fifo_fd;
 unsigned int *buff;
 if( !argv[1] || !argv[2] || !argv[3] ) {
  fprintf(stderr,"server [server->client fifo] [client->server fifo] [password file]\n");
  exit(1);
 }
main_loop:
  fprintf(stderr,"Opening server->client fifo...\n");
  sc_fifo_fd = open_fifo(argv[1]);
  fprintf(stderr,"Opening client->server fifo...\n");
  cs_fifo_fd = open_fifo(argv[2]);
  fprintf(stderr,"Waiting connection...\n");
  if( wait_connection(cs_fifo_fd) < 0 ) {
   fprintf(stderr,"Communication error...\n");
   goto next1;
  }
  write_OK(sc_fifo_fd);
  read_msg(cs_fifo_fd,&buff);
  fprintf(stderr,"%c\n",buff[2]);
next1:
  fprintf(stderr,"Closing connection...\n");
  write_BYE(sc_fifo_fd);
  close_channel(sc_fifo_fd);
  close_channel(cs_fifo_fd);
    goto main_loop ;
next2:
 fprintf(stderr,"Closing connection...\n");
 if( read_string(cs_fifo_fd,"Bye") < 0 ) {
  fprintf(stderr,"Communication error\n");
  goto next2;
 }
 close_channel(sc_fifo_fd);
 close_channel(cs_fifo_fd);
goto main_loop ;
 exit(0);
}

variable_types: argc int

variable_types:
argv
char **


openChannel

decompiled_code:
int __fastcall openChannel(const char *a1)
{
int result; // eax

result = open(a1, 2);
if ( result < 0 )
{
perror("open()");
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
int result; // eax

result = open(a1, 2);
if ( result < 0 )
{
perror("open()");
exit(1);
}
return result;
}

original_code:
int openChannel(const char * path){
 int fd;
 if( (fd = open(path,02)) < 0 ) {
  perror("open()");
  exit(1);
 }
 return (fd);
}

canonical_original_code:
int openChannel(char *path){
 int fd;
 if( (fd = open(path,02)) < 0 ) {
  perror("open()");
  exit(1);
 }
 return (fd);
}

variable_types:
path
char *


closeChannel

decompiled_code:
// attributes: thunk
int closeChannel(int fd)
{
return close(fd);
}

canonical_decompiled_code:
int func1(int fd)
{
return close(fd);
}

original_code:
void closeChannel(int channel_fd){
 close(channel_fd);
}


readFromPipe

decompiled_code:
__int64 __fastcall readFromPipe(int fd, void *dest)
{
int v2; // eax
unsigned int v3; // er13
unsigned __int16 buf; // [rsp+Eh] [rbp-81Ah] BYREF
char src[2072]; // [rsp+10h] [rbp-818h] BYREF

if ( read(fd, &buf, 2uLL) < 0 )
{
v3 = -1;
perror("readSize()");
}
else if ( buf > 0x7FFu )
{
v3 = -1;
perror("Message too large\n");
}
else
{
v2 = read(fd, src, buf);
v3 = v2;
if ( v2 < 0 )
{
v3 = -1;
perror("readMsg()");
}
else
{
memcpy(dest, src, v2);
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, void *dest)
{
int v2; // eax
unsigned int v3; // er13
unsigned __int16 buf; // [rsp+Eh] [rbp-81Ah] BYREF
char src[2072]; // [rsp+10h] [rbp-818h] BYREF

if ( read(fd, &buf, 2uLL) < 0 )
{
v3 = -1;
perror("readSize()");
}
else if ( buf > 0x7FFu )
{
v3 = -1;
perror("Message too large\n");
}
else
{
v2 = read(fd, src, buf);
v3 = v2;
if ( v2 < 0 )
{
v3 = -1;
perror("readMsg()");
}
else
{
memcpy(dest, src, v2);
}
}
return v3;
}

original_code:
int readFromPipe(const int in , byte *msg){
 int read_len;
 u_int16_t msg_size;
 if(read(in ,(void *)&msg_size , sizeof(msg_size)) < 0 ) {
  perror("readSize()");
  return -1;
 }
 if( msg_size >= 2048 ) {
  perror("Message too large\n");
  return -1;
 }
 char buffer[2048];
 read_len = read(in , (void *)buffer , msg_size);
 if( read_len < 0 ) {
  perror("readMsg()");
  return -1;
 }
 memcpy(msg, buffer , read_len);
 return read_len;
}

canonical_original_code:
int readFromPipe(int in, unsigned int *msg){
 int read_len;
 unsigned int msg_size;
 if(read(in ,(void *)&msg_size , sizeof(msg_size)) < 0 ) {
  perror("readSize()");
  return -1;
 }
 if( msg_size >= 2048 ) {
  perror("Message too large\n");
  return -1;
 }
 char buffer[2048];
 read_len = read(in , (void *)buffer , msg_size);
 if( read_len < 0 ) {
  perror("readMsg()");
  return -1;
 }
 memcpy(msg, buffer , read_len);
 return read_len;
}

variable_types: in int

variable_types:
buffer
char [2048]


writeInPipe

decompiled_code:
__int64 __fastcall writeInPipe(int fd, void *buf, unsigned __int16 a3)
{
unsigned __int16 bufa[14]; // [rsp+Ch] [rbp-1Ch] BYREF

bufa[0] = a3;
if ( write(fd, bufa, 2uLL) >= 0 )
return (unsigned __int16)write(fd, buf, bufa[0]);
perror("writeSize()");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, void *buf, unsigned __int16 a3)
{
unsigned __int16 bufa[14]; // [rsp+Ch] [rbp-1Ch] BYREF

bufa[0] = a3;
if ( write(fd, bufa, 2uLL) >= 0 )
return (unsigned __int16)write(fd, buf, bufa[0]);
perror("writeSize()");
return 0xFFFFFFFFLL;
}

original_code:
int writeInPipe(const int out , const byte *msg , u_int16_t size){
 if(write(out , (const void *)&size , sizeof(size)) < 0 ) {
  perror("writeSize()");
  return -1;
 }
 u_int16_t written = write(out ,(const void *)msg, size);
 if( written < 0 ) {
  perror("writeMsg()");
  return -1;
 }
 return written;
}

canonical_original_code:
int writeInPipe(int out, unsigned int *msg, unsigned int size){
 if(write(out , (void *)&size , sizeof(size)) < 0 ) {
  perror("writeSize()");
  return -1;
 }
 unsigned int written = write(out ,(const void *)msg, size);
 if( written < 0 ) {
  perror("writeMsg()");
  return -1;
 }
 return written;
}

variable_types: out int

variable_types:
size
unsigned int

variable_types:
written
unsigned int


cipherInit

decompiled_code:
void *__fastcall cipherInit(__int64 a1, const void *a2, int a3, const void *a4, int a5, int a6)
{
size_t v6; // r15
size_t v8; // r12
void *v9; // rax
void *v10; // rax
void *v11; // rbx
void *result; // rax
void *dest; // [rsp+0h] [rbp-48h]

v6 = a3;
v8 = a5;
*(_DWORD *)(a1 + 260) = a3;
*(_DWORD *)(a1 + 256) = a5;
v9 = malloc(a3);
*(_QWORD *)(a1 + 240) = v9;
dest = v9;
v10 = malloc(v8);
*(_QWORD *)(a1 + 248) = v10;
v11 = v10;
memcpy(dest, a2, v6);
result = memcpy(v11, a4, v8);
if ( a6 == 3 )
{
MAJ5_init(a1 + 120);
MAJ5_keyLoading(a1 + 120, a2, a4);
result = (void *)MAJ5_warmUpStream(a1 + 120, 100LL);
}
else if ( a6 == 2 )
{
ALL5_init(a1);
ALL5_keyLoading(a1, a2, a4);
result = (void *)ALL5_warmUpStream(a1, 100LL);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func10(__int64 a1, const void *a2, int a3, const void *a4, int a5, int a6)
{
size_t v6; // r15
size_t v8; // r12
void *v9; // rax
void *v10; // rax
void *v11; // rbx
void *result; // rax
void *dest; // [rsp+0h] [rbp-48h]

v6 = a3;
v8 = a5;
*(_DWORD *)(a1 + 260) = a3;
*(_DWORD *)(a1 + 256) = a5;
v9 = malloc(a3);
*(_QWORD *)(a1 + 240) = v9;
dest = v9;
v10 = malloc(v8);
*(_QWORD *)(a1 + 248) = v10;
v11 = v10;
memcpy(dest, a2, v6);
result = memcpy(v11, a4, v8);
if ( a6 == 3 )
{
MAJ5_init(a1 + 120);
MAJ5_keyLoading(a1 + 120, a2, a4);
result = (void *)MAJ5_warmUpStream(a1 + 120, 100LL);
}
else if ( a6 == 2 )
{
ALL5_init(a1);
ALL5_keyLoading(a1, a2, a4);
result = (void *)ALL5_warmUpStream(a1, 100LL);
}
return result;
}

original_code:
void cipherInit(cipher_struct * cipher , const bit * key , const int keyLength , const bit * initVector , const int vectorLength, const EncType encType){
 cipher->keyLength = keyLength;
 cipher->vectorLength = vectorLength;
 cipher->key = malloc(keyLength * sizeof(bit));
 cipher->vector = malloc(vectorLength * sizeof(bit));
 memcpy(cipher->key , key , sizeof(bit) * keyLength);
 memcpy(cipher->vector , initVector , sizeof(bit) * vectorLength);
 if(encType == Cipher_MAJ5)
 {
  MAJ5_init(&cipher->maj5);
  MAJ5_keyLoading(&cipher->maj5 , key , initVector);
  MAJ5_warmUpStream(&cipher->maj5 , 100);
  return;
 }
 if(encType == Cipher_ALL5)
 {
  ALL5_init(&cipher->all5);
  ALL5_keyLoading(&cipher->all5 , key , initVector);
  ALL5_warmUpStream(&cipher->all5 , 100);
  return;
 }
}

canonical_original_code:
void cipherInit(struct cc_ss *cipher, unsigned int *key, int keyLength, unsigned int *initVector, int vectorLength, enum EncType encType){
 cipher->keyLength = keyLength;
 cipher->vectorLength = vectorLength;
 cipher->key = malloc(keyLength * sizeof(bit));
 cipher->vector = malloc(vectorLength * sizeof(bit));
 memcpy(cipher->key , key , sizeof(bit) * keyLength);
 memcpy(cipher->vector , initVector , sizeof(bit) * vectorLength);
 if(encType == Cipher_MAJ5)
 {
  MAJ5_init(&cipher->maj5);
  MAJ5_keyLoading(&cipher->maj5 , key , initVector);
  MAJ5_warmUpStream(&cipher->maj5 , 100);
  return;
 }
 if(encType == Cipher_ALL5)
 {
  ALL5_init(&cipher->all5);
  ALL5_keyLoading(&cipher->all5 , key , initVector);
  ALL5_warmUpStream(&cipher->all5 , 100);
  return;
 }
}

variable_types: struct cc_ss { struct ALL5 { struct LFSR { unsigned int *reg; unsigned int *poly; unsigned int degree; } reg[5]; } all5; struct MAJ5 { struct LFSR reg[5]; } maj5; unsigned int *key; unsigned int *vector; unsigned int vectorLength; unsigned int keyLength; } *

variable_types:
key
unsigned int *

variable_types: keyLength int

variable_types:
initVector
unsigned int *

variable_types: vectorLength int

variable_types: enum EncType { Cipher_Bunny24=1, Cipher_MAJ5=3, Cipher_ALL5=2, hash_spongeBunny=4, RSA64=5, RSA512=6, PLAIN=7 }

user_defined_types: struct cc_ss { struct ALL5 all5; struct MAJ5 maj5; unsigned int *key; unsigned int *vector; unsigned int vectorLength; unsigned int keyLength; }


cipherDelete

decompiled_code:
void __fastcall cipherDelete(__int64 a1, int a2)
{
void *v3; // rdi
void *v4; // rdi

if ( a2 == 3 )
{
MAJ5_delete(a1 + 120);
}
else if ( a2 == 2 )
{
ALL5_delete();
}
v3 = *(void **)(a1 + 240);
if ( v3 )
free(v3);
v4 = *(void **)(a1 + 248);
if ( v4 )
free(v4);
}

original_code:
void cipherDelete(cipher_struct * cipher, const EncType encType){
 if(encType == Cipher_MAJ5)
  MAJ5_delete(&cipher->maj5);
 if(encType == Cipher_ALL5)
  ALL5_delete(&cipher->all5);
 if(cipher->key != ((void *)0))
  free(cipher->key);
 if(cipher->vector != ((void *)0))
  free(cipher->vector);
}

canonical_original_code:
void cipherDelete(struct cc_ss *cipher, enum EncType encType){
 if(encType == Cipher_MAJ5)
  MAJ5_delete(&cipher->maj5);
 if(encType == Cipher_ALL5)
  ALL5_delete(&cipher->all5);
 if(cipher->key != ((void *)0))
  free(cipher->key);
 if(cipher->vector != ((void *)0))
  free(cipher->vector);
}

user_defined_types: enum EncType { Cipher_Bunny24=1, Cipher_MAJ5=3, Cipher_ALL5=2, hash_spongeBunny=4, RSA64=5, RSA512=6, PLAIN=7 }


initStreamChiper

decompiled_code:
__int64 __fastcall initStreamChiper(__int64 a1, int a2, __int64 a3, __int64 a4)
{
__int64 result; // rax

*(_DWORD *)(a1 + 312) = a2;
switch ( a2 )
{
case 1:
ALL5_init(a1 + 72);
ALL5_keyLoading(a1 + 72, a3, a4);
result = ALL5_warmUpStream(a1 + 72, 100LL);
break;
case 2:
A51_init();
A51_keyLoading(a1, a3, a4);
result = A51_warmUpStream(a1, 100LL);
break;
case 0:
MAJ5_init(a1 + 192);
MAJ5_keyLoading(a1 + 192, a3, a4);
result = MAJ5_warmUpStream(a1 + 192, 100LL);
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, __int64 a3, __int64 a4)
{
__int64 result; // rax

*(_DWORD *)(a1 + 312) = a2;
switch ( a2 )
{
case 1:
ALL5_init(a1 + 72);
ALL5_keyLoading(a1 + 72, a3, a4);
result = ALL5_warmUpStream(a1 + 72, 100LL);
break;
case 2:
A51_init();
A51_keyLoading(a1, a3, a4);
result = A51_warmUpStream(a1, 100LL);
break;
case 0:
MAJ5_init(a1 + 192);
MAJ5_keyLoading(a1 + 192, a3, a4);
result = MAJ5_warmUpStream(a1 + 192, 100LL);
break;
}
return result;
}

original_code:
void initStreamChiper(streamChiper *chiper , streamChiperSuite type , bit *key , bit *initVector){
 chiper->type = type;
 switch(type){
  case Stream_A51 : {
   A51_init(&chiper->a51);
   A51_keyLoading(&chiper->a51 , key , initVector);
   A51_warmUpStream(&chiper->a51 , 100);
   break;
  }
  case Stream_MAJ5 : {
   MAJ5_init(&chiper->maj5);
   MAJ5_keyLoading(&chiper->maj5 , key , initVector);
   MAJ5_warmUpStream(&chiper->maj5 , 100);
   break;
  }
  case Stream_ALL5 : {
   ALL5_init(&chiper->all5);
   ALL5_keyLoading(&chiper->all5 , key , initVector);
   ALL5_warmUpStream(&chiper->all5 , 100);
   break;
  }
  default : break;
 }
}

canonical_original_code:
void initStreamChiper(struct streamChiper *chiper, enum streamChiperSuite type, unsigned int *key, unsigned int *initVector){
 chiper->type = type;
 switch(type){
  case Stream_A51 : {
   A51_init(&chiper->a51);
   A51_keyLoading(&chiper->a51 , key , initVector);
   A51_warmUpStream(&chiper->a51 , 100);
   break;
  }
  case Stream_MAJ5 : {
   MAJ5_init(&chiper->maj5);
   MAJ5_keyLoading(&chiper->maj5 , key , initVector);
   MAJ5_warmUpStream(&chiper->maj5 , 100);
   break;
  }
  case Stream_ALL5 : {
   ALL5_init(&chiper->all5);
   ALL5_keyLoading(&chiper->all5 , key , initVector);
   ALL5_warmUpStream(&chiper->all5 , 100);
   break;
  }
  default : break;
 }
}

variable_types: struct streamChiper { struct A51 { struct LFSR { unsigned int *reg; unsigned int *poly; unsigned int degree; } reg[3]; } a51; struct ALL5 { struct LFSR reg[5]; } all5; struct MAJ5 { struct LFSR reg[5]; } maj5; enum streamChiperSuite { Stream_MAJ5=0, Stream_ALL5=1, Stream_A51=2 } type; } *

user_defined_types: struct streamChiper { struct A51 a51; struct ALL5 all5; struct MAJ5 maj5; enum streamChiperSuite type; }


deleteStreamChiper

decompiled_code:
__int64 __fastcall deleteStreamChiper(__int64 a1)
{
__int64 result; // rax

result = *(unsigned int *)(a1 + 312);
switch ( (_DWORD)result )
{
case 1:
return ALL5_delete(a1 + 72);
case 2:
return A51_delete();
case 0:
result = MAJ5_delete(a1 + 192);
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 result; // rax

result = *(unsigned int *)(a1 + 312);
switch ( (_DWORD)result )
{
case 1:
return ALL5_delete(a1 + 72);
case 2:
return A51_delete();
case 0:
result = MAJ5_delete(a1 + 192);
break;
}
return result;
}

original_code:
void deleteStreamChiper(streamChiper *chiper){
 switch(chiper->type){
  case Stream_A51 : {
   A51_delete(&chiper->a51);
   break;
  }
  case Stream_MAJ5 : {
   MAJ5_delete(&chiper->maj5);
   break;
  }
  case Stream_ALL5 : {
   ALL5_delete(&chiper->all5);
   break;
  }
  default : break;
 }
}

canonical_original_code:
void deleteStreamChiper(struct streamChiper *chiper){
 switch(chiper->type){
  case Stream_A51 : {
   A51_delete(&chiper->a51);
   break;
  }
  case Stream_MAJ5 : {
   MAJ5_delete(&chiper->maj5);
   break;
  }
  case Stream_ALL5 : {
   ALL5_delete(&chiper->all5);
   break;
  }
  default : break;
 }
}

user_defined_types: enum streamChiperSuite { Stream_MAJ5=0, Stream_ALL5=1, Stream_A51=2 }


encrypt

decompiled_code:
__int64 __fastcall encrypt(__int64 a1)
{
__int64 result; // rax

result = *(unsigned int *)(a1 + 312);
switch ( (_DWORD)result )
{
case 1:
return ALL5_encrypt(a1 + 72);
case 2:
return A51_encrypt();
case 0:
result = MAJ5_encrypt(a1 + 192);
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 result; // rax

result = *(unsigned int *)(a1 + 312);
switch ( (_DWORD)result )
{
case 1:
return ALL5_encrypt(a1 + 72);
case 2:
return A51_encrypt();
case 0:
result = MAJ5_encrypt(a1 + 192);
break;
}
return result;
}

original_code:
void encrypt(streamChiper *chiper , byte *plaintext, byte *chipertext, int length){
 switch(chiper->type){
  case Stream_A51 : {
   A51_encrypt(&chiper->a51, plaintext, chipertext, (unsigned) length);
   break;
  }
  case Stream_MAJ5 : {
   MAJ5_encrypt(&chiper->maj5, plaintext, chipertext, (unsigned) length);
   break;
  }
  case Stream_ALL5 : {
   ALL5_encrypt(&chiper->all5, plaintext, chipertext, (unsigned) length);
   break;
  }
  default : break;
 }
}

canonical_original_code:
void encrypt(struct streamChiper *chiper, unsigned int *plaintext, unsigned int *chipertext, int length){
 switch(chiper->type){
  case Stream_A51 : {
   A51_encrypt(&chiper->a51, plaintext, chipertext, (unsigned int) length);
   break;
  }
  case Stream_MAJ5 : {
   MAJ5_encrypt(&chiper->maj5, plaintext, chipertext, (unsigned int) length);
   break;
  }
  case Stream_ALL5 : {
   ALL5_encrypt(&chiper->all5, plaintext, chipertext, (unsigned int) length);
   break;
  }
  default : break;
 }
}

variable_types:
plaintext
unsigned int *

variable_types:
chipertext
unsigned int *

variable_types: length int


decrypt

decompiled_code:
__int64 __fastcall decrypt(__int64 a1)
{
__int64 result; // rax

result = *(unsigned int *)(a1 + 312);
switch ( (_DWORD)result )
{
case 1:
return ALL5_decrypt(a1 + 72);
case 2:
return A51_decrypt();
case 0:
result = MAJ5_decrypt(a1 + 192);
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 result; // rax

result = *(unsigned int *)(a1 + 312);
switch ( (_DWORD)result )
{
case 1:
return ALL5_decrypt(a1 + 72);
case 2:
return A51_decrypt();
case 0:
result = MAJ5_decrypt(a1 + 192);
break;
}
return result;
}

original_code:
void decrypt(streamChiper *chiper , byte *plaintext, byte *chipertext, int length){
 switch(chiper->type){
  case Stream_A51 : {
   A51_decrypt(&chiper->a51, plaintext, chipertext, (unsigned) length);
   break;
  }
  case Stream_MAJ5 : {
   MAJ5_decrypt(&chiper->maj5, plaintext, chipertext, (unsigned) length);
   break;
  }
  case Stream_ALL5 : {
   ALL5_decrypt(&chiper->all5, plaintext, chipertext, (unsigned) length);
   break;
  }
  default : break;
 }
}

canonical_original_code:
void decrypt(struct streamChiper *chiper, unsigned int *plaintext, unsigned int *chipertext, int length){
 switch(chiper->type){
  case Stream_A51 : {
   A51_decrypt(&chiper->a51, plaintext, chipertext, (unsigned int) length);
   break;
  }
  case Stream_MAJ5 : {
   MAJ5_decrypt(&chiper->maj5, plaintext, chipertext, (unsigned int) length);
   break;
  }
  case Stream_ALL5 : {
   ALL5_decrypt(&chiper->all5, plaintext, chipertext, (unsigned int) length);
   break;
  }
  default : break;
 }
}


decompiled_code:
void __fastcall LFSR_delete(__int64 a1)
{
void *v2; // rdi
void *v3; // rdi

v2 = *(void **)a1;
if ( v2 )
free(v2);
v3 = *(void **)(a1 + 8);
if ( v3 )
free(v3);
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
void *v2; // rdi
void *v3; // rdi

v2 = *(void **)a1;
if ( v2 )
free(v2);
v3 = *(void **)(a1 + 8);
if ( v3 )
free(v3);
}

original_code:
void LFSR_delete(LFSR *lfsr){
 if(lfsr->reg != ((void *)0))
  free(lfsr->reg);
 if(lfsr->poly != ((void *)0))
  free(lfsr->poly);
}

canonical_original_code:
void LFSR_delete(struct LFSR *lfsr){
 if(lfsr->reg != ((void *)0))
  free(lfsr->reg);
 if(lfsr->poly != ((void *)0))
  free(lfsr->poly);
}

variable_types: struct LFSR { unsigned int *reg; unsigned int *poly; unsigned int degree; } *


decompiled_code:
int __fastcall LFSR_print(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rsi

if ( !*(_QWORD *)a1 || !*(_QWORD *)(a1 + 8) || !*(_DWORD *)(a1 + 16) )
return printf("reg empty!!!");
printf("LFSR reg : ");
if ( *(_DWORD *)(a1 + 16) )
{
v1 = 0LL;
do
{
v2 = *(unsigned __int8 *)(*(_QWORD *)a1 + v1++);
printf("%d ", v2);
}
while ( *(_DWORD *)(a1 + 16) > (unsigned int)v1 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rsi

if ( !*(_QWORD *)a1 || !*(_QWORD *)(a1 + 8) || !*(_DWORD *)(a1 + 16) )
return printf("reg empty!!!");
printf("LFSR reg : ");
if ( *(_DWORD *)(a1 + 16) )
{
v1 = 0LL;
do
{
v2 = *(unsigned __int8 *)(*(_QWORD *)a1 + v1++);
printf("%d ", v2);
}
while ( *(_DWORD *)(a1 + 16) > (unsigned int)v1 );
}
return putchar(10);
}

original_code:
void LFSR_print(LFSR *lfsr){
 if(lfsr->reg == ((void *)0) || lfsr->poly == ((void *)0) || lfsr->degree == 0)
 {
  printf("reg empty!!!");
  return;
 }
 int i = 0;
 printf("LFSR reg : ");
 for(i = 0 ; i < lfsr->degree ; i++)
  printf("%d " , lfsr->reg[i]);
 printf("\n");
}

canonical_original_code:
void LFSR_print(struct LFSR *lfsr){
 if(lfsr->reg == ((void *)0) || lfsr->poly == ((void *)0) || lfsr->degree == 0)
 {
  printf("reg empty!!!");
  return;
 }
 int i = 0;
 printf("LFSR reg : ");
 for(i = 0 ; i < lfsr->degree ; i++)
  printf("%d " , lfsr->reg[i]);
 printf("\n");
}

variable_types: i int


decompiled_code:
__int64 __fastcall LFSR_getBit(_DWORD *a1, unsigned int a2)
{
if ( a1[4] > a2 )
return *(unsigned __int8 *)(*(_QWORD *)a1 + a2);
perror("index of out range");
return **(unsigned __int8 **)a1;
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1, unsigned int a2)
{
if ( a1[4] > a2 )
return *(unsigned __int8 *)(*(_QWORD *)a1 + a2);
perror("index of out range");
return **(unsigned __int8 **)a1;
}

original_code:
bit LFSR_getBit(LFSR *lfsr, unsigned int position){
  if(position < 0 || position >= lfsr->degree)
  {
   perror("index of out range");
   return lfsr->reg[0];
  }
  return lfsr->reg[position];
}

canonical_original_code:
unsigned int LFSR_getBit(struct LFSR *lfsr, unsigned int position){
  if(position < 0 || position >= lfsr->degree)
  {
   perror("index of out range");
   return lfsr->reg[0];
  }
  return lfsr->reg[position];
}

variable_types:
position
unsigned int


original_code:
bit LFSR_update(LFSR *lfsr){
 unsigned int i;
 bit xored = 0;
 bit output = lfsr->reg[lfsr->degree - 1];
 for(i = 1; i < (lfsr->degree + 1); i++)
 {
  if(lfsr->poly[i] == 1)
   xored ^= lfsr->reg[i - 1];
 }
 rotate(lfsr->reg , -1 , lfsr->degree);
 lfsr->reg[0] = xored;
 return output;
}

canonical_original_code:
unsigned int LFSR_update(struct LFSR *lfsr){
 unsigned int i;
 unsigned int xored = 0;
 unsigned int output = lfsr->reg[lfsr->degree - 1];
 for(i = 1; i < (lfsr->degree + 1); i++)
 {
  if(lfsr->poly[i] == 1)
   xored ^= lfsr->reg[i - 1];
 }
 rotate(lfsr->reg , -1 , lfsr->degree);
 lfsr->reg[0] = xored;
 return output;
}

variable_types:
i
unsigned int

variable_types:
xored
unsigned int

variable_types:
output
unsigned int


decompiled_code:
void __fastcall LFSR_getStream(__int64 a1, _BYTE *a2, int a3)
{
__int64 v3; // r12
_BYTE *v4; // rbx

if ( a3 )
{
v3 = (__int64)&a2[a3 - 1 + 1];
v4 = a2;
do
*v4++ = LFSR_update(a1);
while ( v4 != (_BYTE *)v3 );
}
}

original_code:
void LFSR_getStream(LFSR *lfsr , bit *result, unsigned int stream){
 int i;
 for(i=0; i < stream; i++)
  result[i] = LFSR_update(lfsr);
}

canonical_original_code:
void LFSR_getStream(struct LFSR *lfsr, unsigned int *result, unsigned int stream){
 int i;
 for(i=0; i < stream; i++)
  result[i] = LFSR_update(lfsr);
}

variable_types:
result
unsigned int *

variable_types:
stream
unsigned int


printArray

decompiled_code:
int __fastcall printArray(unsigned __int8 *a1, int a2)
{
__int64 v2; // rbp
unsigned __int8 *v3; // rbx
__int64 v4; // rsi

if ( a2 )
{
v2 = (__int64)&a1[a2 - 1 + 1];
v3 = a1;
do
{
v4 = *v3++;
printf("%d ", v4);
}
while ( v3 != (unsigned __int8 *)v2 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func0(unsigned __int8 *a1, int a2)
{
__int64 v2; // rbp
unsigned __int8 *v3; // rbx
__int64 v4; // rsi

if ( a2 )
{
v2 = (__int64)&a1[a2 - 1 + 1];
v3 = a1;
do
{
v4 = *v3++;
printf("%d ", v4);
}
while ( v3 != (unsigned __int8 *)v2 );
}
return putchar(10);
}

original_code:
void printArray(bit *array, unsigned int x){
 int i;
 for(i=0; i < x; i++)
  printf("%d " , array[i]);
 printf("\n");
}

canonical_original_code:
void printArray(unsigned int *array, unsigned int x){
 int i;
 for(i=0; i < x; i++)
  printf("%d " , array[i]);
 printf("\n");
}

variable_types:
array
unsigned int *

variable_types:
x
unsigned int


arraySum

original_code:
void arraySum(bit *pA , bit *pB , bit *result, unsigned int degree){
 int i;
 for(i = 0; i < degree; i++)
  result[i] = pA[i] ^ pB[i];
}

canonical_original_code:
void arraySum(unsigned int *pA, unsigned int *pB, unsigned int *result, unsigned int degree){
 int i;
 for(i = 0; i < degree; i++)
  result[i] = pA[i] ^ pB[i];
}

variable_types:
pA
unsigned int *

variable_types:
pB
unsigned int *

variable_types:
degree
unsigned int


arrayMul

decompiled_code:
signed __int64 __fastcall arrayMul(__int64 a1, __int64 a2, __int64 a3, void *a4, unsigned int a5)
{
__int64 v5; // r9
size_t v10; // rdx
int v11; // ecx
signed __int64 result; // rax
void *v13; // rsp
int v14; // ecx
signed __int64 v15; // rdx
unsigned int v16; // esi
char *v17; // rcx
char v18; // dl
__int64 v19; // [rsp+0h] [rbp-40h] BYREF
int v20; // [rsp+Ch] [rbp-34h]

v5 = a1;
v10 = 2 * a5;
v11 = 2 * a5;
result = 16 * ((v10 + 15) >> 4);
v13 = alloca(result);
if ( (_DWORD)v10 )
{
v19 = a1;
v20 = 2 * a5;
result = (signed __int64)memset(&v19, 0, v10);
v11 = v20;
v5 = v19;
}
v14 = v11 - 1;
v15 = 0LL;
v16 = v14;
if ( a5 )
{
do
{
while ( *(_BYTE *)(a2 + v15) != 1 )
{
if ( a5 == ++v15 )
goto LABEL_10;
}
result = v15;
do
{
*((_BYTE *)&v19 + result) ^= *(_BYTE *)(v5 - v15 + result);
++result;
}
while ( result != a5 + v15 );
++v15;
}
while ( a5 != v15 );
LABEL_10:
if ( a5 > v14 )
return (signed __int64)memcpy(a4, &v19, a5 - 1 + 1LL);
}
v17 = (char *)&v19 + v14 - (__int64)(int)a5;
do
{
while ( 1 )
{
v18 = v17[a5];
if ( v18 == 1 )
break;
--v16;
--v17;
if ( v16 < a5 )
goto LABEL_18;
}
for ( result = (int)a5; ; v18 = v17[result] )
{
v17[result] = *(_BYTE *)(a3 + result) ^ v18;
if ( (_DWORD)--result == -1 )
break;
}
--v16;
--v17;
}
while ( v16 >= a5 );
LABEL_18:
if ( a5 )
return (signed __int64)memcpy(a4, &v19, a5 - 1 + 1LL);
return result;
}

canonical_decompiled_code:
signed __int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, void *a4, unsigned int a5)
{
__int64 v5; // r9
size_t v10; // rdx
int v11; // ecx
signed __int64 result; // rax
void *v13; // rsp
int v14; // ecx
signed __int64 v15; // rdx
unsigned int v16; // esi
char *v17; // rcx
char v18; // dl
__int64 v19; // [rsp+0h] [rbp-40h] BYREF
int v20; // [rsp+Ch] [rbp-34h]

v5 = a1;
v10 = 2 * a5;
v11 = 2 * a5;
result = 16 * ((v10 + 15) >> 4);
v13 = alloca(result);
if ( (_DWORD)v10 )
{
v19 = a1;
v20 = 2 * a5;
result = (signed __int64)memset(&v19, 0, v10);
v11 = v20;
v5 = v19;
}
v14 = v11 - 1;
v15 = 0LL;
v16 = v14;
if ( a5 )
{
do
{
while ( *(_BYTE *)(a2 + v15) != 1 )
{
if ( a5 == ++v15 )
goto LABEL_10;
}
result = v15;
do
{
*((_BYTE *)&v19 + result) ^= *(_BYTE *)(v5 - v15 + result);
++result;
}
while ( result != a5 + v15 );
++v15;
}
while ( a5 != v15 );
LABEL_10:
if ( a5 > v14 )
return (signed __int64)memcpy(a4, &v19, a5 - 1 + 1LL);
}
v17 = (char *)&v19 + v14 - (__int64)(int)a5;
do
{
while ( 1 )
{
v18 = v17[a5];
if ( v18 == 1 )
break;
--v16;
--v17;
if ( v16 < a5 )
goto LABEL_18;
}
for ( result = (int)a5; ; v18 = v17[result] )
{
v17[result] = *(_BYTE *)(a3 + result) ^ v18;
if ( (_DWORD)--result == -1 )
break;
}
--v16;
--v17;
}
while ( v16 >= a5 );
LABEL_18:
if ( a5 )
return (signed __int64)memcpy(a4, &v19, a5 - 1 + 1LL);
return result;
}

original_code:
void arrayMul(bit *pA , bit *pB , bit *field, bit *result, unsigned int degree){
 bit temp[degree * 2];
 int i;
 for(i = 0; i < degree * 2; i++)
  temp[i] = 0;
 for(i = 0; i < degree; i++)
 {
  if(pB[i] == 1)
  {
   int j;
   int z = i;
   for(j=0; j < degree; j++)
   {
    temp[z] ^= pA[j];
    z++;
   }
  }
 }
 for(i = (degree * 2) - 1; i >= degree; i--)
 {
  if(temp[i] == 1)
  {
   int j = i;
   int z;
   for(z = degree; z >= 0; z--){
    temp[j] ^= field[z];
    j--;
   }
  }
 }
 for(i = 0; i < degree; i++)
  result[i] = temp[i];
}

canonical_original_code:
void arrayMul(unsigned int *pA, unsigned int *pB, unsigned int *field, unsigned int *result, unsigned int degree){
 unsigned int temp[-1];
 int i;
 for(i = 0; i < degree * 2; i++)
  temp[i] = 0;
 for(i = 0; i < degree; i++)
 {
  if(pB[i] == 1)
  {
   int j;
   int z = i;
   for(j=0; j < degree; j++)
   {
    temp[z] ^= pA[j];
    z++;
   }
  }
 }
 for(i = (degree * 2) - 1; i >= degree; i--)
 {
  if(temp[i] == 1)
  {
   int j = i;
   int z;
   for(z = degree; z >= 0; z--){
    temp[j] ^= field[z];
    j--;
   }
  }
 }
 for(i = 0; i < degree; i++)
  result[i] = temp[i];
}

variable_types:
field
unsigned int *

variable_types:
temp
unsigned int [-1]

variable_types: j int

variable_types: z int


arrayToByte

original_code:
int arrayToByte(bit *bits, bit *bytes, int length){
 int i;
 for(i = 0; i < length; i++)
 {
  int j = i / 8;
  bytes[j] |= bits[i];
 }
 return length/8;
}

canonical_original_code:
int arrayToByte(unsigned int *bits, unsigned int *bytes, int length){
 int i;
 for(i = 0; i < length; i++)
 {
  int j = i / 8;
  bytes[j] |= bits[i];
 }
 return length/8;
}

variable_types:
bits
unsigned int *

variable_types:
bytes
unsigned int *

variable_types: length int


rotate

decompiled_code:
void *__fastcall rotate(void *src, int a2, unsigned int a3)
{
void *result; // rax
void *v5; // rsp
unsigned int v6; // er13
unsigned int v7; // eax
size_t v8; // rdx
unsigned int v9; // er13
int v10; // ebx
_BYTE v11[48]; // [rsp+0h] [rbp-30h] BYREF

result = (void *)(16 * (((unsigned __int64)a3 + 15) >> 4));
v5 = alloca((signed __int64)result);
if ( a2 < 0 )
{
v9 = a2 + a3;
if ( __CFADD__(a2, a3) )
{
v10 = -a2;
result = memcpy(v11, (char *)src + (int)v9, (unsigned int)~a2 + 1LL);
}
else
{
v10 = 0;
}
if ( v9 )
result = memcpy(&v11[v10], src, v9);
goto LABEL_5;
}
if ( a3 <= a2 )
{
if ( a2 )
{
v7 = 0;
goto LABEL_4;
}
LABEL_5:
v6 = a3 - 1;
if ( !a3 )
return result;
goto LABEL_6;
}
v6 = a3 - 1;
memcpy(v11, (char *)src + a2, a3 - 1 - a2 + 1LL);
v7 = a3 - a2;
if ( a2 )
{
LABEL_4:
result = memcpy(&v11[v7], src, (unsigned int)(a2 - 1) + 1LL);
goto LABEL_5;
}
LABEL_6:
v8 = v6 + 1LL;
if ( !a3 )
v8 = 1LL;
return memcpy(src, v11, v8);
}

canonical_decompiled_code:
void *__fastcall func4(void *src, int a2, unsigned int a3)
{
void *result; // rax
void *v5; // rsp
unsigned int v6; // er13
unsigned int v7; // eax
size_t v8; // rdx
unsigned int v9; // er13
int v10; // ebx
_BYTE v11[48]; // [rsp+0h] [rbp-30h] BYREF

result = (void *)(16 * (((unsigned __int64)a3 + 15) >> 4));
v5 = alloca((signed __int64)result);
if ( a2 < 0 )
{
v9 = a2 + a3;
if ( __CFADD__(a2, a3) )
{
v10 = -a2;
result = memcpy(v11, (char *)src + (int)v9, (unsigned int)~a2 + 1LL);
}
else
{
v10 = 0;
}
if ( v9 )
result = memcpy(&v11[v10], src, v9);
goto LABEL_5;
}
if ( a3 <= a2 )
{
if ( a2 )
{
v7 = 0;
goto LABEL_4;
}
LABEL_5:
v6 = a3 - 1;
if ( !a3 )
return result;
goto LABEL_6;
}
v6 = a3 - 1;
memcpy(v11, (char *)src + a2, a3 - 1 - a2 + 1LL);
v7 = a3 - a2;
if ( a2 )
{
LABEL_4:
result = memcpy(&v11[v7], src, (unsigned int)(a2 - 1) + 1LL);
goto LABEL_5;
}
LABEL_6:
v8 = v6 + 1LL;
if ( !a3 )
v8 = 1LL;
return memcpy(src, v11, v8);
}

original_code:
void rotate(bit * array, int shift , unsigned int degree){
 bit buffer[degree];
 int i;
 if(shift < 0)
 {
  int j = 0;
  for(i = (degree - abs(shift)) ; i < degree; i++)
  {
   buffer[j] = array[i];
   j++;
  }
  for(i = 0; i < (degree - abs(shift)) ; i++)
  {
   buffer[j] = array[i];
   j++;
  }
 }
 else
 {
  int j = 0;
  for(i = shift ; i < degree ; i++)
  {
   buffer[j] = array[i];
   j++;
  }
  for(i = 0 ; i < shift ; i++)
  {
   buffer[j] = array[i];
   j++;
  }
 }
 for(i=0; i < degree; i++)
  array[i] = buffer[i];
}

canonical_original_code:
void rotate(unsigned int *array, int shift, unsigned int degree){
 unsigned int buffer[-1];
 int i;
 if(shift < 0)
 {
  int j = 0;
  for(i = (degree - abs(shift)) ; i < degree; i++)
  {
   buffer[j] = array[i];
   j++;
  }
  for(i = 0; i < (degree - abs(shift)) ; i++)
  {
   buffer[j] = array[i];
   j++;
  }
 }
 else
 {
  int j = 0;
  for(i = shift ; i < degree ; i++)
  {
   buffer[j] = array[i];
   j++;
  }
  for(i = 0 ; i < shift ; i++)
  {
   buffer[j] = array[i];
   j++;
  }
 }
 for(i=0; i < degree; i++)
  array[i] = buffer[i];
}

variable_types: shift int

variable_types:
buffer
unsigned int [-1]

variable_types: i int


inverteArray

decompiled_code:
void *__fastcall inverteArray(void *dest, unsigned int a2)
{
void *v2; // r9
__int64 v3; // r10
char *v4; // r8
void *v5; // rsp
char *v6; // rax
int v7; // edi
char v8; // cl
__int64 v9; // rdx
__int64 savedregs; // [rsp+0h] [rbp+0h] BYREF

v2 = dest;
v3 = a2 - 1;
v4 = (char *)dest + v3 + 1;
v5 = alloca(16 * (((unsigned __int64)a2 + 15) >> 4));
v6 = (char *)dest;
v7 = v3 + (_DWORD)dest;
do
{
v8 = *v6;
v9 = (unsigned int)(v7 - (_DWORD)v6++);
*((_BYTE *)&savedregs + v9) = v8;
}
while ( v4 != v6 );
return memcpy(v2, &savedregs, v3 + 1);
}

canonical_decompiled_code:
void *__fastcall func5(void *dest, unsigned int a2)
{
void *v2; // r9
__int64 v3; // r10
char *v4; // r8
void *v5; // rsp
char *v6; // rax
int v7; // edi
char v8; // cl
__int64 v9; // rdx
__int64 savedregs; // [rsp+0h] [rbp+0h] BYREF

v2 = dest;
v3 = a2 - 1;
v4 = (char *)dest + v3 + 1;
v5 = alloca(16 * (((unsigned __int64)a2 + 15) >> 4));
v6 = (char *)dest;
v7 = v3 + (_DWORD)dest;
do
{
v8 = *v6;
v9 = (unsigned int)(v7 - (_DWORD)v6++);
*((_BYTE *)&savedregs + v9) = v8;
}
while ( v4 != v6 );
return memcpy(v2, &savedregs, v3 + 1);
}

original_code:
void inverteArray(bit *array, unsigned int length){
 int i;
 bit buffer[length];
 length --;
 for(i = 0; i <= length; i++)
  buffer[length - i] = array[i];
 for(i = 0; i <= length; i++)
  array[i] = buffer[i];
}

canonical_original_code:
void inverteArray(unsigned int *array, unsigned int length){
 int i;
 unsigned int buffer[-1];
 length --;
 for(i = 0; i <= length; i++)
  buffer[length - i] = array[i];
 for(i = 0; i <= length; i++)
  array[i] = buffer[i];
}

variable_types:
length
unsigned int


corrHexToBinary

decompiled_code:
__int64 __fastcall corrHexToBinary(__int64 a1, const char *a2)
{
int v2; // eax
int v3; // edx
__int64 result; // rax
_BYTE *v5; // rbp
__int64 v6; // rbx
char v7; // dl
int v8; // ecx
_BYTE *v9; // rdx

v2 = strlen(a2);
v3 = 4 * v2 - 1;
result = (unsigned int)(v2 - 1);
v5 = (_BYTE *)(v3 + a1);
if ( (int)result >= 0 )
{
v6 = (int)result;
do
{
v7 = a2[v6];
switch ( v7 )
{
case '0':
v8 = 0;
break;
case '1':
v8 = 1;
break;
case '2':
v8 = 2;
break;
case '3':
v8 = 3;
break;
case '4':
v8 = 4;
break;
case '5':
v8 = 5;
break;
case '6':
v8 = 6;
break;
case '7':
v8 = 7;
break;
case '8':
v8 = 8;
break;
case '9':
v8 = 9;
break;
case 'A':
case 'a':
v8 = 10;
break;
case 'B':
case 'b':
v8 = 11;
break;
case 'C':
case 'c':
v8 = 12;
break;
case 'D':
case 'd':
v8 = 13;
break;
case 'E':
case 'e':
v8 = 14;
break;
case 'F':
case 'f':
v8 = 15;
break;
default:
printf("error hex for char %c \n\n", (unsigned int)v7);
v8 = 0;
break;
}
v9 = v5;
LODWORD(result) = 0;
do
{
if ( _bittest(&v8, result) )
*v9 = 1;
else
*v9 = 0;
result = (unsigned int)(result + 1);
--v9;
}
while ( (_DWORD)result != 4 );
--v6;
v5 -= 4;
}
while ( (int)v6 >= 0 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const char *a2)
{
int v2; // eax
int v3; // edx
__int64 result; // rax
_BYTE *v5; // rbp
__int64 v6; // rbx
char v7; // dl
int v8; // ecx
_BYTE *v9; // rdx

v2 = strlen(a2);
v3 = 4 * v2 - 1;
result = (unsigned int)(v2 - 1);
v5 = (_BYTE *)(v3 + a1);
if ( (int)result >= 0 )
{
v6 = (int)result;
do
{
v7 = a2[v6];
switch ( v7 )
{
case '0':
v8 = 0;
break;
case '1':
v8 = 1;
break;
case '2':
v8 = 2;
break;
case '3':
v8 = 3;
break;
case '4':
v8 = 4;
break;
case '5':
v8 = 5;
break;
case '6':
v8 = 6;
break;
case '7':
v8 = 7;
break;
case '8':
v8 = 8;
break;
case '9':
v8 = 9;
break;
case 'A':
case 'a':
v8 = 10;
break;
case 'B':
case 'b':
v8 = 11;
break;
case 'C':
case 'c':
v8 = 12;
break;
case 'D':
case 'd':
v8 = 13;
break;
case 'E':
case 'e':
v8 = 14;
break;
case 'F':
case 'f':
v8 = 15;
break;
default:
printf("error hex for char %c \n\n", (unsigned int)v7);
v8 = 0;
break;
}
v9 = v5;
LODWORD(result) = 0;
do
{
if ( _bittest(&v8, result) )
*v9 = 1;
else
*v9 = 0;
result = (unsigned int)(result + 1);
--v9;
}
while ( (_DWORD)result != 4 );
--v6;
v5 -= 4;
}
while ( (int)v6 >= 0 );
}
return result;
}

original_code:
void corrHexToBinary(bit * array , char * hex){
 int i, j , index = strlen(hex) * 4 - 1;
 for(i = strlen(hex) - 1; i >= 0; i--)
 {
  u_int8_t num = 0;
  switch(hex[i]){
   case '0' : num = 0; break;
   case '1' : num = 1; break;
   case '2' : num = 2; break;
   case '3' : num = 3; break;
   case '4' : num = 4; break;
   case '5' : num = 5; break;
   case '6' : num = 6; break;
   case '7' : num = 7; break;
   case '8' : num = 8; break;
   case '9' : num = 9; break;
   case 'A' : num = 10; break;
   case 'B' : num = 11; break;
   case 'C' : num = 12; break;
   case 'D' : num = 13; break;
   case 'E' : num = 14; break;
   case 'F' : num = 15; break;
   case 'a' : num = 10; break;
   case 'b' : num = 11; break;
   case 'c' : num = 12; break;
   case 'd' : num = 13; break;
   case 'e' : num = 14; break;
   case 'f' : num = 15; break;
   default : printf("error hex for char %c \n\n" , hex[i]); break;
   }
  for(j = 0; j < 4; j++)
  {
   if(num & (1 << j))
    array[index] = 1;
   else
    array[index] = 0;
   index--;
  }
 }
}

canonical_original_code:
void corrHexToBinary(unsigned int *array, char *hex){
 int i; int j; int index = strlen(hex) * 4 - 1;
 for(i = strlen(hex) - 1; i >= 0; i--)
 {
  unsigned int num = 0;
  switch(hex[i]){
   case '0' : num = 0; break;
   case '1' : num = 1; break;
   case '2' : num = 2; break;
   case '3' : num = 3; break;
   case '4' : num = 4; break;
   case '5' : num = 5; break;
   case '6' : num = 6; break;
   case '7' : num = 7; break;
   case '8' : num = 8; break;
   case '9' : num = 9; break;
   case 'A' : num = 10; break;
   case 'B' : num = 11; break;
   case 'C' : num = 12; break;
   case 'D' : num = 13; break;
   case 'E' : num = 14; break;
   case 'F' : num = 15; break;
   case 'a' : num = 10; break;
   case 'b' : num = 11; break;
   case 'c' : num = 12; break;
   case 'd' : num = 13; break;
   case 'e' : num = 14; break;
   case 'f' : num = 15; break;
   default : printf("error hex for char %c \n\n" , hex[i]); break;
   }
  for(j = 0; j < 4; j++)
  {
   if(num & (1 << j))
    array[index] = 1;
   else
    array[index] = 0;
   index--;
  }
 }
}

variable_types:
hex
char *

variable_types: index int

variable_types:
num
unsigned int