[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <8f6a58a30701050154t5293a09eq4d2f4119f3cab6f5@mail.gmail.com>
Date: Fri, 5 Jan 2007 10:54:14 +0100
From: "Slythers Bro" <slythers@...il.com>
To: full-disclosure@...ts.grok.org.uk
Subject: code release: cryptographic attack tool
i release my private librairy "qbytes" (quantique bytes)
this is a mathematic tool where all bits of a double word have 3 states :
one , zero and unknow
i implemented the addition , multiplication (with an integer), a new concept
"fusion" (equivalent to = ) , and all basic booleean functions (binary
version of xor, or, no , and)
there are some utilities like error detection, error depth etc ...
i used this lib for coding fuckmd5.cpp
if you want to use multithreading the code need modification
i think this tool is good for easy recomputation and error detection in the
case of a cryptographic attack
quantique.h : structure definition
qbyte.h : class definition
qbyte.cpp : all the functions
download link :
http://81.57.125.106/~slythers/qbyte%20and%20md5%20recomputation.rar
the quantique.h
-----------------------------------------------------------------------------
/*
(c) b4d coder
Malloc(0) Wicked Attitude
Copyright (c) 2006, overdose : slythers@...il.com
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Malloc(0) Wicked Attitude nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#define PARAM_LIST_SIZE_BASE (sizeof(unsigned int)+sizeof(unsigned
char)+sizeof(char)+sizeof(bool))
#define MAX_ADD (255)
struct quantique
{
unsigned int value;
unsigned int know;
};
struct quantparam{
unsigned int size;
char type;
unsigned char nb;
bool error;
struct quantique *wesh[2];
};
the qbyte.h
-----------------------------------------------------------------------------
/*
B4d coder (c)
Quantique Bytes librairy (cryptographic attack tool)
coded by overdose/slythers@...il.com
Malloc(0) Wicked Attitude
http://malloczerowickedattitude.new.fr
created:10/03/2006
*/
#include <iostream.h>
#include "quantique.h"
class qbyte
{
public:
qbyte();
bool error;
unsigned int value;
unsigned int know;
static unsigned int ldepth;
static unsigned int hdepth;
bool multi(qbyte &un,unsigned int entier);
bool add(qbyte &un,qbyte &deux);
bool xor(qbyte &un,qbyte &deux);
bool and(qbyte &un,qbyte &deux);
bool or(qbyte &un,qbyte &deux);
bool no(qbyte &un);
void no();
bool fusion(qbyte &of);
void copy(qbyte &a);
bool existbit(unsigned int number);
void setbit(unsigned int number,bool value);
void disablebit(unsigned int number);
bool getbit(unsigned int number);
void copyrealvalue();
void setvalue();
void setvalue(unsigned int v);
void leftrotation(unsigned int nb);
void rightrotation(unsigned int nb);
void leftdecalage(unsigned int nb);
void rightdecalage(unsigned int nb);
//systeme de profondeur des erreur
bool enabledepth();
bool depthisenable();
bool disabledepth();
void reinitdepth();
unsigned int getldepth();
unsigned int gethdepth();
unsigned int getredzone();
bool depthsaved();
bool enablecopyerror();
bool disablecopyerror();
//surcharge des opérateurs, be aware to memory leak
struct quantparam * operator * (unsigned int constante);
struct quantparam * operator + (qbyte &a);
struct quantparam * operator + (struct quantparam * list);
struct quantparam * operator | (qbyte &a);
struct quantparam * operator | (struct quantparam * list);
struct quantparam * operator & (qbyte &a);
struct quantparam * operator & (struct quantparam * list);
struct quantparam * operator ^ (qbyte &a);
struct quantparam * operator ^ (struct quantparam * list);
bool operator = (struct quantparam *list);
bool operator = (qbyte &a);
//machin amie
friend ostream &operator << (ostream &sortie, qbyte &a)
{
sortie << "Quantique Bytes value: "<<hex<<a.me.value<<" Mask: "<<
a.me.know<<dec<<" Error:"<<a.error<<endl;
return sortie;
}
struct quantique me;
private:
bool checkbitforadd(struct quantique *x,struct quantique *y,struct
quantique *z);
bool checkbitforxor(struct quantique *x,struct quantique *y,struct
quantique *z);
bool checkbitforand(struct quantique *x,struct quantique *y,struct
quantique *z);
bool checkbitforor(struct quantique *x,struct quantique *y,struct
quantique *z);
bool checkfusion(struct quantique *x,struct quantique *y);
bool checkmulti(struct quantique *x,unsigned int entier,struct quantique
*z);
bool pyramide(struct quantparam *list,char type);
struct quantparam *addtolist(struct quantparam * list,char type);
struct quantparam *newlist(qbyte &a,char type);
void increment();
void savedepth();
void savedepth(bool b);
static unsigned int compteur;
static unsigned int compteur2;
static unsigned int profondeur;
static unsigned int profondeur2;
static unsigned int redzone;
static bool copyerror;
static bool enable;
static bool initialised;
static bool saved;
};
the qbyte.cpp
-----------------------------------------------------------------------------
/*
(c) B4d coder
Malloc(0) Wicked Attitude
Copyright (c) 2006, overdose : slythers@...il.com
All rights reserved.
private stuff
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "qbyte.h"
bool qbyte::initialised = 0;
unsigned int qbyte::ldepth;
unsigned int qbyte::hdepth;
unsigned int qbyte::compteur;
unsigned int qbyte::compteur2;
unsigned int qbyte::profondeur;
unsigned int qbyte::profondeur2;
unsigned int qbyte::redzone;
bool qbyte::copyerror;
bool qbyte::enable;
bool qbyte::saved;
qbyte::qbyte()
{
this->value = 0x00;
this->know = 0x00;
me.value = 0x00;
me.know = 0x00;
error = 0;
if(!initialised)
{
initialised = 1;
copyerror = 1;
disabledepth();
}
}
bool qbyte::checkbitforadd(struct quantique *x,struct quantique *y,struct
quantique *z)
{
bool modified=0;
bool retenuemodified =0;
bool retmod=0;
unsigned int flagerror = 0x00;
unsigned int mask;
struct quantique save1,save2,save3;
save1 = *x;
save2 = *y;
save3 = *z;
struct quantique retenue;
retenue.value = 0x00;
retenue.know = 0x00;
increment();
do{
if(modified)
retmod = 1;
modified = 0;
retenuemodified = 0;
mask = 0x01;
for(unsigned char cpt = 0;cpt <32;cpt++)
{
//si on connait toute les valeurs on calcul la retenue et on se casse pas
if((z->know & mask) && (x->know & mask) && (y->know & mask) && !(
retenue.know & mask))
{
/*if(retenue.know & mask)
continue;*/
if(!cpt)
{
retenuemodified = 1;
retenue.know |= mask;
if((x->value & mask) && (y->value & mask))
retenue.value |= mask;
else
retenue.value &= ~mask;
}
else if(retenue.know & (mask>>1))
{
retenuemodified = 1;
retenue.know |= mask;
if( ((x->value & mask) || (y->value & mask)) && ( ((x->value & mask)
&& (y->value & mask)) || (retenue.value & (mask>>1)) ) )
retenue.value |= mask;
else
retenue.value &= ~mask;
}
else if(((x->value & mask) && (y->value & mask)))
{
retenuemodified = 1;
retenue.know |= mask;
retenue.value |= mask;
};
//continue;
}
//premier bit pas de retenue
if(!cpt)
{
//au cas ou on connait la retenue
if((retenue.know & mask) && (!(x->know & mask) || !(y->know & mask)) &&
(retenue.value & mask))
{
modified = 1;
y->know |= mask;
x->know |= mask;
y->value |= mask;
x->value |= mask;
}
else if((retenue.know & mask) && !(x->know & mask) && (y->know & mask)
&& (y->value & mask) && !(retenue.value & mask))
{
modified = 1;
x->know |= mask;
x->value &= ~mask;
}
else if((retenue.know & mask) && !(y->know & mask) && (x->know & mask)
&& (x->value & mask) && !(retenue.value & mask))
{
modified = 1;
y->know |= mask;
y->value &= ~mask;
};
//si on connait le bit du resultat
if(z->know & mask)
{
//si on connait le bit de x a 1 et pas y
if((x->know & mask) && (x->value & mask) && !(y->know & mask))
{
modified = 1;
y->know |= mask;
//on met y a 0
if(z->value & mask)
y->value &= ~mask;
else
y->value |= mask;
}
else if((x->know & mask) && !(x->value & mask) && !(y->know & mask))//
bit de x a 0
{
modified = 1;
y->know |= mask;
if(z->value & mask)
y->value |= mask;
else
y->value &= ~mask;
}
//on connait y et pas x
else if((y->know & mask) && (y->value & mask) && !(x->know & mask))
{
modified = 1;
x->know |= mask;
//on met y a 0
if(z->value & mask)
x->value &= ~mask;
else
x->value |= mask;
}
else if((y->know & mask) && !(y->value & mask) && !(x->know & mask) )//
bit de x a 0
{
modified = 1;
x->know |= mask;
if(z->value & mask)
x->value |= mask;
else
x->value &= ~mask;
}
}
//si on connait les deux !
else if((x->know & mask) && (y->know & mask) && !(z->know & mask))
{
modified = 1;
z->know |= mask;
if( (x->value & mask) ^ (y->value & mask) )
z->value |= mask;
else
z->value &= ~mask;
};
//calcul de la retenue
if((x->know & mask) && (y->know & mask) && !(retenue.know & mask))
{
retenuemodified = 1;
retenue.know |= mask;
if((x->value & mask) && (y->value & mask))
retenue.value |= mask;
else
retenue.value &= ~mask;
}
//on verifie les erreurs
if((z->know & mask) && (x->know & mask) && (y->know & mask))
{
if(( (x->value & mask) ^ (y->value & mask) ) != (z->value & mask))
{
if(!(flagerror & mask))
{
flagerror |= mask;
savedepth(1);
}
error = 1;
}
}
}
else
{
//au cas ou on connait la retenue courante et peut etre la precedente
pas z mais !a | !b
if((retenue.know & mask) && (!(x->know & mask) || !(y->know & mask))/*
&& !(z->know & mask)*/)
{
if((retenue.value & mask) && (retenue.know & (mask>>1)) && !(
retenue.value & (mask>>1)))
{
modified = 1;
y->know |= mask;
x->know |= mask;
y->value |= mask;
x->value |= mask;
}
else if((retenue.value & mask) && (retenue.know & (mask>>1)) && (
retenue.value & (mask>>1)))
{
if((x->know & mask) && !(x->value & mask) && !(y->know & mask))
{
modified = 1;
y->know |= mask;
y->value |= mask;
}
else if((y->know & mask) && !(y->value & mask) && !(x->know & mask))
{
modified = 1;
x->know |= mask;
x->value |= mask;
};
}
else if((retenue.know & (mask>>1)) && (retenue.value & (mask>>1)) && !(
retenue.value & mask))
{
modified = 1;
y->know |= mask;
x->know |= mask;
y->value &= ~mask;
x->value &= ~mask;
}
else if((retenue.know & (mask>>1)) && !(retenue.value & (mask>>1)) &&
!(retenue.value & mask))
{
if((y->know & mask) && (y->value & mask) && !(x->know & mask))
{
modified = 1;
x->know |= mask;
x->value &= ~mask;
}
else if((x->know & mask) && (x->value & mask) && !(y->know & mask))
{
modified = 1;
y->know |= mask;
y->value &= ~mask;
};
}
//au cas ou on connait pas la précendente valeur
else if(!(retenue.know & (mask>>1)))
{
if((retenue.value & mask) && (x->know & mask) && !(x->value & mask))
{
modified = 1;
y->know |= mask;
y->value |= mask;
}
else if((retenue.value & mask) && (y->know & mask) && !(y->value &
mask))
{
modified = 1;
x->know |= mask;
x->value |= mask;
};
};
}
//calcul avec retenue precedente inconnu wesh
if(!(retenue.know & (mask >> 1)))
{
if((retenue.know & mask) && (z->know & mask) && !(retenue.value & mask)
&& !(z->value & mask))
{
//cout <<"debug ret"<<endl;
retenuemodified = 1;
retenue.know |= (mask>>1);
retenue.value &= ~(mask>>1);
}
//calcul de la retenu precedente
if((x->know & mask) && (y->know & mask) && (z->know & mask))
{
retenuemodified = 1;
retenue.know |= (mask >> 1);
if( ((x->value & mask) ^ (y->value & mask)) ^ (z->value & mask))
retenue.value |= (mask >> 1);
else
retenue.value &= ~(mask >> 1);
}
//on connait la retenue actuel et x et y
else if((x->know & mask) && (y->know & mask) && (retenue.know & mask))
{
//si Rx=1 et !(x&&y) alors rx-1 = 1
if((retenue.value & mask) && !((x->value & mask) && (y->value &
mask)))
{
//cout <<"debug 17"<<endl;
retenuemodified = 1;
retenue.know |= (mask>>1);
retenue.value |= (mask>>1);
}
// si rx = 0 et x||y rx-1 = 0
else if(!(retenue.value & mask) && ((x->value & mask) || (y->value &
mask)) )
{
retenuemodified = 1;
retenue.know |= (mask>>1);
retenue.value &= ~(mask>>1);
};
};
}
//calcul avec retenue precedente connu
else if( retenue.know & (mask >> 1))
{
if((x->know & mask) && (y->know & mask) && !(z->know & mask))
{
modified = 1;
z->know |= mask;
if((x->value & mask) ^ (y->value & mask) ^ ((retenue.value &
(mask>>1))<<1))
z->value |= mask;
else
z->value &= ~mask;
}
else if((x->know & mask) && !(y->know & mask) && (z->know & mask))
{
modified = 1;
y->know |= mask;
if((x->value & mask) ^ (z->value & mask) ^ ((retenue.value &
(mask>>1))<<1))
y->value |= mask;
else
y->value &= ~mask;
}
else if(!(x->know & mask) && (y->know & mask) && (z->know & mask))
{
modified = 1;
x->know |= mask;
if((z->value & mask) ^ (y->value & mask) ^ ((retenue.value &
(mask>>1))<<1))
x->value |= mask;
else
x->value &= ~mask;
};
//calcul retenu
if(!(retenue.know & mask) && (x->know & mask) && !(y->know & mask) &&
!(z->know & mask) )
{
if(!(retenue.value & (mask>>1)) && !(x->value & mask))
{
retenuemodified = 1;
retenue.know |= mask;
retenue.value &= ~mask;
}
else if((retenue.value & (mask>>1)) && (x->value & mask))
{
retenuemodified = 1;
retenue.know |= mask;
retenue.value |= mask;
};
}
else if(!(retenue.know & mask) && (y->know & mask) && !(x->know & mask)
&& !(z->know & mask))
{
if(!(retenue.value & (mask>>1)) && !(y->value & mask))
{
retenuemodified = 1;
retenue.know |= mask;
retenue.value &= ~mask;
}
else if((retenue.value & (mask>>1)) && (y->value & mask))
{
retenuemodified = 1;
retenue.know |= mask;
retenue.value |= mask;
};
};
}
//calcul de la retenu
if(!(retenue.know & mask) && (retenue.know & (mask>>1)) && (x->know &
mask) && (y->know & mask))
{
retenuemodified = 1;
retenue.know |= mask;
if( ((x->value & mask) && (y->value & mask)) || ((x->value & mask) && (
retenue.value & (mask>>1))) || ((retenue.value & (mask>>1)) && (y->value &
mask)) )
retenue.value |= mask;
else
retenue.value &= ~mask;
}
else if(!(retenue.know & mask) && !(retenue.know & (mask>>1)) &&
(x->know & mask) && (y->know & mask) && (x->value & mask) && (y->value &
mask))
{
retenuemodified = 1;
retenue.know |= mask;
retenue.value |= mask;
}
else if(!(retenue.know & mask) && (retenue.know & (mask>>1)) && (x->know
& mask) && !(y->know & mask) && !(retenue.value & (mask>>1)) && !(x->value &
mask))
{
retenuemodified = 1;
retenue.know |= mask;
retenue.value &= ~mask;
}
else if(!(retenue.know & mask) && (retenue.know & (mask>>1)) &&
!(x->know & mask) && (y->know & mask) && !(retenue.value & (mask>>1)) &&
!(y->value & mask))
{
retenuemodified = 1;
retenue.know |= mask;
retenue.value &= ~mask;
};
if((x->know & mask) && (y->know & mask) && !(x->value & mask) &&
!(y->value & mask) && !(retenue.know & mask) )
{
//cout <<"debug ret 2"<<endl;
retenuemodified = 1;
retenue.know |= mask;
retenue.value &= ~mask;
}
else if((x->know & mask) && (y->know & mask) && (x->value & mask) &&
(y->value & mask) && !(retenue.know & mask) )
{
//cout <<"debug ret 3"<<endl;
retenuemodified = 1;
retenue.know |= mask;
retenue.value |= mask;
}
}
//on verifie les erreurs
if((z->know & mask) && (x->know & mask) && (y->know & mask) && cpt && (
retenue.know & (mask>>1)))
{
if(( (x->value & mask) ^ (y->value & mask) ^ ((retenue.value &
(mask>>1))<<1) ) != (z->value & mask))
{
if(!(flagerror & mask))
{
flagerror |= mask;
savedepth(1);
}
error = 1;
}
}
mask = mask <<1;
}
}while(modified || retenuemodified);
//verification des erreur
if(!(~(x->know)) && !(~(y->know)) && !(~(z->know)))
{
if((x->value + y->value) != z->value)
{
savedepth();
error = 1;
}
}
if((save1.value & save1.know) != (x->value & save1.know))
{
savedepth();
error = 1;
}
if((save2.value & save2.know) != (y->value & save2.know))
{
savedepth();
error = 1;
}
if((save3.value & save3.know) != (z->value & save3.know))
{
savedepth();
error = 1;
}
return retmod;
}
//version fast ...
bool qbyte::checkmulti(struct quantique *x,unsigned int entier,struct
quantique *z)
{
struct quantique pile[32];
struct quantique palier;
struct quantique copiedex;
struct quantique cx,cz;
unsigned int mask;
unsigned char cpt,nb,max;
bool modified=0;
cx = *x;
cz = *z;
palier.value = 0x00;
palier.know = 0x00;
nb = 0;
increment();
for(cpt =0; cpt<32;cpt++)
{
pile[cpt].value = 0x00;
pile[cpt].know = 0x00;
}
for(max =31;!((0x01<<max) & entier) && max ;max--);
pile[0].know = 0xffffffff;
do{
modified = 0;
mask = 0x01<<31;
nb = 0;
for(cpt=0;cpt<32;cpt++)
{
if(mask & entier)
{
palier.value = x->value << (31-cpt);
palier.know = (x->know << (31-cpt)) | ((cpt == 31) ? 0x00 : (0xffffffff
>> (cpt+1)) );
if(checkbitforadd(&(pile[nb]),&palier, (cpt == max)? z : &(pile[nb+1])
))
modified = 1;
nb++;
palier.value = palier.value >> (31-cpt);
palier.know = palier.know >> (31-cpt);
copiedex.know = x->know;
if(checkfusion(&palier,x))
{
if(copiedex.know != x->know)
modified = 1;
}
}
mask = mask >>1;
}
//on refait dans l'autre sens
for(;cpt;cpt--)
{
if(mask & entier)
{
palier.value = (x->value) << (31-(cpt-1));
palier.know = (x->know) << (31-(cpt-1)) | ((cpt == 32) ? 0x00 :
(0xffffffff >> (cpt)) );
if(checkbitforadd(&(pile[nb]),&palier, (cpt == (max+1))? z :
&(pile[nb+1]) ))
modified = 1;
nb--;
palier.value = (palier.value) >> (31-(cpt-1));
palier.know = (palier.know) >> (31-(cpt-1));
copiedex.know = x->know;
if(checkfusion(&palier,x))
{
if(copiedex.know != x->know)
modified = 1;
}
}
mask = mask <<1;
}
}while(modified && !error);
//verification erreur
if(cx.value != (x->value & cx.know))
{
savedepth();
error = 1;
}
if(cz.value != (z->value & cz.know))
{
savedepth();
error = 1;
}
if((cz.know != z->know) || (cx.know != x->know))
return 1;
return 0;
}
bool qbyte::checkbitforxor(struct quantique *x,struct quantique *y,struct
quantique *z)
{
bool modified=0;
unsigned int mask=0x01;
unsigned int tmp;
unsigned int flagerror=0x00;
increment();
tmp = z->know & x->know & y->know;
if((z->value & tmp) != ((x->value & tmp) ^ (y->value & tmp)))
{
savedepth();
error = 1;
}
for(unsigned int cpt = 0;cpt<32;cpt++)
{
if(z->know & mask)
{
if(z->value & mask)
{
if((x->know & mask) && (x->value & mask))
{
//cout <<"debug 1"<<endl;
if(!(y->know & mask))
modified = 1;
y->know |= mask;
y->value &= ~mask;
}
else if((y->know & mask) && (y->value & mask))
{
//cout <<"debug 2"<<endl;
if(!(x->know & mask))
modified = 1;
x->know |= mask;
x->value &= ~mask;
};
}
else
{
if(x->know & mask)
{
//cout <<"debug 3"<<endl;
if(!(y->know & mask))
modified = 1;
y->know |= mask;
if(x->value&mask)
y->value |= mask;
else
y->value &= ~mask;
}
else if(y->know & mask)
{
//cout <<"debug 4"<<endl;
//inutile ici mais bon =)
if(!(x->know & mask))
modified = 1;
x->know |= mask;
if(y->value&mask)
x->value |= mask;
else
x->value &= ~mask;
};
}
}
else if((x->know & mask) && (y->know & mask))
{
//cout <<"debug 5"<<endl;
modified = 1;
z->know |= mask;
if((x->value & mask) ^ (y->value & mask))
z->value |= mask;
else
z->value &= ~mask;
};
//on check les erreur
if((z->know & mask) && (x->know & mask) && (y->know & mask))
{
if((z->value & mask) != ((x->value & mask) ^ (y->value & mask)))
{
if(!(flagerror & mask))
{
flagerror |= mask;
savedepth(1);
}
error = 1;
}
}
mask = mask << 1;
}
return modified;
}
bool qbyte::checkbitforand(struct quantique *x,struct quantique *y,struct
quantique *z)
{
bool modified=0;
unsigned int mask=0x01;
unsigned int flagerror = 0x00;
unsigned int tmp;
increment();
tmp = z->know & x->know & y->know;
if((z->value & tmp) != ((x->value & tmp) & (y->value & tmp)))
{
savedepth();
error = 1;
}
for(unsigned int cpt = 0;cpt<32;cpt++)
{
if((z->know & mask) && (z->value & mask))
{
if(!((x->know & mask) && (y->know & mask)) )
modified = 1;
x->know |= mask;
y->know |= mask;
x->value |= mask;
y->value |= mask;
}
else if((z->know & mask) && !(z->value & mask))
{
if((x->know & mask)&&(x->value & mask))
{
if(!(y->know & mask))
modified = 1;
y->know |= mask;
y->value &= ~mask;
}
else if((y->know & mask)&&(y->value & mask))
{
if(!(x->know & mask))
modified = 1;
x->know |= mask;
x->value &= ~mask;
};
}
else if(!(z->know & mask) && ((x->know & mask) || (y->know & mask)))
{
if((x->know & mask) && !(x->value & mask))
{
modified = 1;
z->know |= mask;
z->value &= ~mask;
}
else if((y->know & mask) && !(y->value & mask))
{
modified = 1;
z->know |= mask;
z->value &= ~mask;
}
else if((x->know & mask) && (y->know & mask))// normelement les deux sont
a 1
{
modified = 1;
z->know |= mask;
z->value |= mask;
}
};
//on check les erreur
if((z->know & mask) && (x->know & mask) && (y->know & mask))
{
if((z->value & mask) != ((x->value & mask) & (y->value & mask)))
{
if(!(flagerror & mask))
{
flagerror |= mask;
savedepth(1);
}
error = 1;
}
}
mask = mask<<1;
}
return modified;
}
bool qbyte::checkbitforor(struct quantique *x,struct quantique *y,struct
quantique *z)
{
bool modified=0;
unsigned int mask=0x01;
unsigned int tmp;
unsigned int flagerror = 0x00;
increment();
tmp = z->know & x->know & y->know;
if((z->value & tmp) != ((x->value & tmp) | (y->value & tmp)))
{
savedepth();
error = 1;
}
for(unsigned int cpt = 0;cpt<32;cpt++)
{
if((z->know & mask) && !(z->value & mask))
{
if(!((x->know & mask) && (y->know & mask)) )
modified = 1;
x->know |= mask;
y->know |= mask;
x->value &= ~mask;
y->value &= ~mask;
}
else if((z->know & mask) && (z->value & mask))
{
if((x->know & mask) && !(x->value & mask))
{
if(!(y->know & mask))
modified = 1;
y->know |= mask;
y->value |= mask;
}
else if((y->know & mask) && !(y->value & mask))
{
if(!(x->know & mask))
modified = 1;
x->know |= mask;
x->value |= mask;
};
}
else if(!(z->know & mask) && ((x->know & mask) || (y->know & mask)))
{
if((x->know & mask) && (x->value & mask))
{
modified = 1;
z->know |= mask;
z->value |= mask;
}
else if((y->know & mask) && (y->value & mask))
{
modified = 1;
z->know |= mask;
z->value |= mask;
}
else if((x->know & mask) && (y->know & mask))// normelement le deux sont
a 0
{
modified = 1;
z->know |= mask;
z->value &= ~mask;
}
};
//on check les erreur
if((z->know & mask) && (x->know & mask) && (y->know & mask))
{
if((z->value & mask) != ((x->value & mask) | (y->value & mask)))
{
if(!(flagerror & mask))
{
flagerror |= mask;
savedepth(1);
}
error = 1;
}
}
mask = mask<<1;
}
return modified;
}
bool qbyte::multi(qbyte &un,unsigned int entier)
{
bool ret;
error |= un.error ;
if(error)
return 0;
ret = checkmulti(&(un.me),entier,&(this->me));
copyrealvalue();
return ret;
}
bool qbyte::add(qbyte &un,qbyte &deux)
{
bool ret;
error |= un.error | deux.error;
/*if(error)
return 0;*/
ret = checkbitforadd(&(un.me),&(deux.me),&(this->me));
copyrealvalue();
return ret;
}
bool qbyte::xor(qbyte &un,qbyte &deux)
{
bool ret;
error |= un.error | deux.error;
/*if(error)
return 0;*/
ret = checkbitforxor(&(un.me),&(deux.me),&(this->me));
copyrealvalue();
return ret;
}
bool qbyte::and(qbyte &un,qbyte &deux)
{
bool ret;
error |= un.error | deux.error;
/*if(error)
return 0;*/
ret = checkbitforand(&(un.me),&(deux.me),&(this->me));
copyrealvalue();
return ret;
}
bool qbyte::or(qbyte &un,qbyte &deux)
{
bool ret;
error |= un.error | deux.error;
/*if(error)
return 0;*/
ret = checkbitforor(&(un.me),&(deux.me),&(this->me));
copyrealvalue();
return ret;
}
bool qbyte::no(qbyte &un)
{
bool modified=0;
unsigned int mask=0x01;
unsigned int tmp;
struct quantique *x;
increment();
x = &(un.me);
tmp = me.know & x->know;
if((me.value & tmp) != (~(x->value) & tmp) )
{
savedepth();
error = 1;
}
for(unsigned int cpt = 0;cpt<32;cpt++)
{
if((me.know & mask) && !(x->know & mask))
{
modified = 1;
x->know |= mask;
if(me.value & mask)
x->value &= ~mask;
else
x->value |= mask;
}
else if(!(me.know & mask) && (x->know & mask))
{
modified = 1;
x->know |= mask;
if(x->value & mask)
me.value &= ~mask;
else
me.value |= mask;
};
if( (me.know & mask) && (x->know & mask) && ((me.value & mask) !=
(~(x->value) & mask)) )
{
savedepth(1);
error = 1;
}
mask = mask << 1;
}
copyrealvalue();
return modified;
}
void qbyte::no()
{
me.value = ~(me.value);
me.value &= me.know;
copyrealvalue();
}
bool qbyte::checkfusion(struct quantique *x,struct quantique *y)
{
bool modified=0;
unsigned int mask=0x01;
increment();
for(unsigned int cpt = 0;cpt<32;cpt++)
{
if(x->know & mask)
{
if((y->know & mask) && ((x->value & mask) != (y->value & mask)) )
{
savedepth(1);
error = 1;
}
if(!(y->know & mask))
modified = 1;
y->know |= mask;
if(x->value & mask)
y->value |= mask;
else
y->value &= ~mask;
}
else if(y->know & mask)
{
modified = 1;
x->know |= mask;
if(y->value & mask)
x->value |= mask;
else
x->value &= ~mask;
}
mask = mask << 1;
}
return modified;
}
bool qbyte::fusion(qbyte &of)
{
bool modified=0;
modified = checkfusion(&(of.me),&(this->me));
copyrealvalue();
return modified;
}
void qbyte::copy(qbyte &a)
{
me.value = a.me.value;
me.know = a.me.know;
if(copyerror)
this->error = a.error;
copyrealvalue();
}
void qbyte::setbit(unsigned int number,bool value)
{
me.know |= (0x01<<number);
if(value)
me.value |= (0x01<<number);
else
me.value &= ~(0x01<<number);
copyrealvalue();
}
bool qbyte::existbit(unsigned int number)
{
return (me.know & (0x01<<number));
}
void qbyte::disablebit(unsigned int number)
{
me.know &= ~(0x01<<number);
me.value &= me.know;
copyrealvalue();
}
bool qbyte::getbit(unsigned int number)
{
return (me.value & (0x01<<number));
}
void qbyte::copyrealvalue()
{
this->value = me.value;
this->know = me.know;
}
void qbyte::setvalue()
{
me.value = this->value & this->know ;
me.know = this->know;
}
void qbyte::setvalue(unsigned int v)
{
me.value = v;
me.know = 0xffffffff;
}
void qbyte::leftrotation(unsigned int nb)
{
if(!(nb %32))
return;
me.value = ( ((me.value) << (nb)) | ((me.value) >> (32-(nb))) );
me.know = ( ((me.know) << (nb)) | ((me.know) >> (32-(nb))) );
copyrealvalue();
}
void qbyte::rightrotation(unsigned int nb)
{
if(!(nb %32))
return;
me.value = (((me.value) >> (nb)) | ((me.value) << (32-(nb))));
me.know = (((me.know) >> (nb)) | ((me.know) << (32-(nb))));
copyrealvalue();
}
void qbyte::leftdecalage(unsigned int nb)
{
me.value = me.value << nb;
me.know = me.know << nb;
copyrealvalue();
}
void qbyte::rightdecalage(unsigned int nb)
{
me.value = me.value >> nb;
me.know = me.know >> nb;
copyrealvalue();
}
//surcharge des operateurs
//a debugguer ... surtout le return modif faut checker que les entrée/sorie
qui pourrait avoir changer
bool qbyte::pyramide(struct quantparam *list,char type)
{
struct quantique abc[MAX_ADD][MAX_ADD/2];
unsigned char endessous[MAX_ADD];
unsigned char nbporte[MAX_ADD];
unsigned char cpt,ptr,hauteur,tmp;
bool modified=0;
bool ret;
ret =0;
if(list->nb < 3)
{
switch(type)
{
case '+':
return checkbitforadd(list->wesh[0],list->wesh[1],&(this->me));
case '|':
return checkbitforor(list->wesh[0],list->wesh[1],&(this->me));
case '&':
return checkbitforand(list->wesh[0],list->wesh[1],&(this->me));
case '^':
return checkbitforxor(list->wesh[0],list->wesh[1],&(this->me));
case '*':
return checkmulti(list->wesh[0],(unsigned int)
list->wesh[1],&(this->me));
}
return 0;
}
for(cpt=0;cpt<MAX_ADD;cpt++)
{
endessous[cpt] = 0xff;
for(ptr=0;ptr < (MAX_ADD/2);ptr++)
{
abc[cpt][ptr].know = 0x00;
abc[cpt][ptr].value = 0x00;
}
}
do{
if(modified)
ret = 1;
modified = 0;
//on divise une premere fois par deux
hauteur = list->nb/2;
if(hauteur %2)
hauteur++;
hauteur -= 2;
hauteur = hauteur/2;
tmp = list->nb;
if(tmp%2)
{
abc[(tmp/2)+1][0] = *(list->wesh[tmp]);
endessous[0] = tmp;
tmp = tmp /2;
nbporte[0] = tmp;
tmp++;
}
else
{
tmp = tmp /2;
nbporte[0] = tmp;
}
for(unsigned char ok=0;ok < list->nb;ok+=2)
{
switch(type)
{
case '+':
checkbitforadd(list->wesh[ok],list->wesh[ok+1],&(abc[ok/2][0]));
break;
case '|':
checkbitforor(list->wesh[ok],list->wesh[ok+1],&(abc[ok/2][0]));
break;
case '&':
checkbitforand(list->wesh[ok],list->wesh[ok+1],&(abc[ok/2][0]));
break;
case '^':
checkbitforxor(list->wesh[ok],list->wesh[ok+1],&(abc[ok/2][0]));
break;
}
}
for(cpt = 0;cpt < hauteur;cpt++)
{
if(tmp%2)
{
abc[(tmp/2)+1][cpt+1] = abc[tmp][cpt];
endessous[cpt+1] = tmp;
tmp = tmp /2;
nbporte[cpt+1] = tmp;
tmp++;
}
else
{
tmp = tmp /2;
nbporte[cpt+1] = tmp;
}
for(ptr=0;ptr < nbporte[cpt+1];ptr++)
{
switch(type)
{
case '+':
checkbitforadd(&(abc[ptr*2][cpt]),&(abc[(ptr*2)+1][cpt]),&(abc[ptr][cpt+1]));
break;
case '|':
checkbitforor(&(abc[ptr*2][cpt]),&(abc[(ptr*2)+1][cpt]),&(abc[ptr][cpt+1]));
break;
case '&':
checkbitforand(&(abc[ptr*2][cpt]),&(abc[(ptr*2)+1][cpt]),&(abc[ptr][cpt+1]));
break;
case '^':
checkbitforxor(&(abc[ptr*2][cpt]),&(abc[(ptr*2)+1][cpt]),&(abc[ptr][cpt+1]));
break;
}
}
}
switch(type)
{
case '+':
if(checkbitforadd(&(abc[0][cpt]),&(abc[1][cpt]),&(this->me)))
modified = 1;
break;
case '|':
if(checkbitforor(&(abc[0][cpt]),&(abc[1][cpt]),&(this->me)))
modified = 1;
break;
case '&':
if(checkbitforand(&(abc[0][cpt]),&(abc[1][cpt]),&(this->me)))
modified = 1;
break;
case '^':
if(checkbitforxor(&(abc[0][cpt]),&(abc[1][cpt]),&(this->me)))
modified = 1;
break;
}
//on refait dans l'autre sens peut etre on aura pas besoin de boucler ^^ a
verifier
if(endessous[cpt] != 0xff)
abc[endessous[cpt]][cpt-1] = abc[1][cpt];
for(;cpt;cpt--)
{
for(ptr=0; ptr < nbporte[cpt];ptr++)
{
switch(type)
{
case '+':
checkbitforadd(&(abc[ptr*2][cpt-1]),&(abc[(ptr*2)+1][cpt-1]),&(abc[ptr][cpt]));
break;
case '|':
checkbitforor(&(abc[ptr*2][cpt-1]),&(abc[(ptr*2)+1][cpt-1]),&(abc[ptr][cpt]));
break;
case '&':
checkbitforand(&(abc[ptr*2][cpt-1]),&(abc[(ptr*2)+1][cpt-1]),&(abc[ptr][cpt]));
break;
case '^':
checkbitforxor(&(abc[ptr*2][cpt-1]),&(abc[(ptr*2)+1][cpt-1]),&(abc[ptr][cpt]));
break;
}
}
if(endessous[cpt] != 0xff)
abc[endessous[cpt]][cpt-1] = abc[ptr+1][cpt];
}
if(endessous[0] != 0xff)
*(list->wesh[tmp]) = abc[nbporte[cpt]][0];
for(unsigned char ok=0;ok < list->nb;ok+=2)
{
switch(type)
{
case '+':
if(checkbitforadd(list->wesh[ok],list->wesh[ok+1],&(abc[ok/2][0])))
modified = 1;
break;
case '|':
if(checkbitforor(list->wesh[ok],list->wesh[ok+1],&(abc[ok/2][0])))
modified = 1;
break;
case '&':
if(checkbitforand(list->wesh[ok],list->wesh[ok+1],&(abc[ok/2][0])))
modified = 1;
break;
case '^':
if(checkbitforxor(list->wesh[ok],list->wesh[ok+1],&(abc[ok/2][0])))
modified = 1;
break;
}
}
}while(modified);
delete[] (char *)list;
return ret;
}
struct quantparam *qbyte::newlist(qbyte &a,char type)
{
struct quantparam *abc;
abc = (struct quantparam *) new char[PARAM_LIST_SIZE_BASE + (sizeof(struct
quantique *)*2)];
abc->size = PARAM_LIST_SIZE_BASE + (sizeof(struct quantique *)*2);
abc->type = type;
abc->nb = 2;
abc->error = this->error | a.error;
abc->wesh[0] = &(this->me);
abc->wesh[1] = &(a.me);
return abc;
}
struct quantparam *qbyte::addtolist(struct quantparam * list,char type)
{
struct quantparam *tmp;
if(type != list->type)
{
cout <<"wesh lascar, on supporte pas trop les melange sur ste version
modif ton code la lib fait un exit(0); la:P"<<endl;
exit(0);
}
tmp = (struct quantparam *) new char[list->size + sizeof(struct quantique
*)];
memcpy(tmp,list,list->size);
tmp->wesh[list->nb] = &(this->me);
delete[] (char *)list;
tmp->nb++;
return tmp;
}
struct quantparam * qbyte::operator + (qbyte &a)
{
return newlist(a,'+');
}
struct quantparam * qbyte::operator + (struct quantparam * list)
{
return addtolist(list,'+');
}
bool qbyte::operator = (struct quantparam *list)
{
return pyramide(list,list->type);
}
bool qbyte::operator = (qbyte &a)
{
return fusion(a);
}
struct quantparam * qbyte::operator | (qbyte &a)
{
return newlist(a,'|');
}
struct quantparam * qbyte::operator | (struct quantparam * list)
{
return addtolist(list,'|');
}
struct quantparam * qbyte::operator & (qbyte &a)
{
return newlist(a,'&');
}
struct quantparam * qbyte::operator & (struct quantparam * list)
{
return addtolist(list,'&');
}
struct quantparam * qbyte::operator ^ (qbyte &a)
{
return newlist(a,'^');
}
struct quantparam * qbyte::operator ^ (struct quantparam * list)
{
return addtolist(list,'^');
}
struct quantparam * qbyte::operator * (unsigned int constante)
{
struct quantparam *abc;
abc = (struct quantparam *) new char[PARAM_LIST_SIZE_BASE + (sizeof(struct
quantique *)*2)];
abc->size = PARAM_LIST_SIZE_BASE + (sizeof(struct quantique *)*2);
abc->type = '*';
abc->nb = 2;
abc->error = this->error ;
abc->wesh[0] = &(this->me);
abc->wesh[1] = (struct quantique *) constante;
return abc;
}
//profondeur d'erreur ...
void qbyte::increment()
{
if(!enable)
return;
if(saved)
{
//redzone++;
return ;
}
if(compteur == ~0x00)
compteur2++;
compteur++;
}
void qbyte::savedepth()
{
savedepth(0);
}
void qbyte::savedepth(bool b)
{
if(!enable)
return;
if(saved)
{
if(b)
redzone++;
return;
}
profondeur = compteur;
profondeur2 = compteur2;
ldepth = compteur;
hdepth = compteur2;
saved = 1;
redzone = 1;
}
bool qbyte::enabledepth()
{
reinitdepth();
if(enable)
return 0;
enable = 1;
return 1;
}
bool qbyte::depthisenable()
{
return enable;
}
bool qbyte::disabledepth()
{
if(!enable)
return 0;
enable = 0;
reinitdepth();
return 1;
}
void qbyte::reinitdepth()
{
compteur = 0;
compteur2 = 0;
profondeur = 0;
profondeur2 = 0;
ldepth = 0;
hdepth = 0;
redzone = 0;
saved = 0;
}
unsigned int qbyte::getldepth()
{
if(saved)
return profondeur;
else
return compteur;
}
unsigned int qbyte::gethdepth()
{
if(saved)
return profondeur2;
else
return compteur2;
}
unsigned int qbyte::getredzone()
{
return redzone;
}
bool qbyte::depthsaved()
{
return saved;
}
bool qbyte::enablecopyerror()
{
if(copyerror)
return 0;
copyerror = 1;
return 1;
}
bool qbyte::disablecopyerror()
{
if(!copyerror)
return 0;
copyerror = 0;
return 1;
}
Content of type "text/html" skipped
_______________________________________________
Full-Disclosure - We believe in it.
Charter: http://lists.grok.org.uk/full-disclosure-charter.html
Hosted and sponsored by Secunia - http://secunia.com/
Powered by blists - more mailing lists