Ejemplo n.º 1
0
extern int *dhash_it(
  BOOLEAN xlate_dna,			/* database is DNA and motifs protein */
  int alen,				/* length of alphabet */
  char *sequence,			/* sequence of sample */
  long length 				/* length of sequence */
)
{
  long i;
  int *hash_seq = NULL;			/* hashed sequence */
  int *h;				/* pointer in hash_seq */
  char *s;				/* pointer in sequence */
  long len;				/* length of sequence */
  int inc;				/* distance to next letter in hashed */

  /*
    Hash sequence from letters to positions in alphabet.
    Three adjacent letters (codons) are hashed if translating DNA. 
  */
  Resize(hash_seq, length+3, int);		/* leave room for padding */
  len = xlate_dna ? length - 2 : length;	/* last full letter or codon */
  for (i=0,s=sequence,h=hash_seq; i<len; i++,s++,h++) 
    *h = chash(xlate_dna, FALSE, s);
  for ( ; i<len+3; i++,h++) *h = alen;		/* pad with alen */

  /*
    Hash sequence to "double letter" logodds alphabet.
  */
  inc = xlate_dna ? 3 : 1;			/* distance to next letter */
  for (i=0, h=hash_seq; i<len; i++,h++) *h = dhash(*h, *(h+inc), alen);

  return hash_seq;
} /* dhash_it */
Ejemplo n.º 2
0
 int hout(void){
   int i,j,tmp=0;
  arrayul p;
  array16 t;
  set s;
  arrayn nn;
  array16 a16;

  
  seed();
  p=crand(password);
  //  for(i=1;i<8*8;i++)
  // printf("%u\n",p.d[i]);
  //  exit(1);
  s=session(p.d);
  //for(i=0;i<NN;i++)
  //printf("%d\n",s.b[i]);
  //  exit(1);
    nn=chash(s.b);
  //  t=hash(argc,argv);
    for(j=0;j<16;j++){
      for(i=4*j;i<4*j+4;i++)
	tmp^=(nn.ar[i]<<(8*i));
	      
	      a16.h[j]=tmp;
	      tmp=0;
    }
 

  for(i=0;i<16;i++)
    printf("%08x ",a16.h[i]);
  printf("\n");

  return 0;
}
Ejemplo n.º 3
0
array16 hash(int argc,char *argv[]){
  int i,j,n;
  array16 h;
  unsigned char buf[N];
  FILE *fp;
  arrayn a;

  fp=fopen(argv[1],"rb");
  if(fp==NULL){
    printf("no file\n");
    exit(1);
  }
  memset(h.h,0,sizeof(h.h));
  while((n=fread(buf,1,N,fp))>0){
    a=chash(buf);
    /*
    for(i=0;i<N;i++){
      printf("%x,",a.ar[i]);
      if(i>0 && i%4==0)
	printf("\n");
    }
    */
      for(i=0;i<16;i++){
	for(j=0;j<4;j++){
	  h.h[i]^=a.ar[i*4+j];
	  if(j!=3)
	  h.h[i]=(h.h[i]<<8);
	}
      }
  }

      return h;
  }
Ejemplo n.º 4
0
/* Legt eine neue Verzauberung an. Sollte es schon einen Zauber
 * dieses Typs geben, gibt es den bestehenden zurück.
 */
static curse *make_curse(unit * mage, attrib ** ap, const curse_type * ct,
  float vigour, int duration, float effect, int men)
{
  curse *c;
  attrib *a;

  a = a_new(&at_curse);
  a_add(ap, a);
  c = (curse *) a->data.v;

  c->type = ct;
  c->flags = 0;
  c->vigour = vigour;
  c->duration = duration;
  c->effect = effect;
  c->magician = mage;

  c->no = newunitid();
  chash(c);

  switch (c->type->typ) {
    case CURSETYP_NORM:
      break;

    case CURSETYP_UNIT:
    {
      c->data.i = men;
      break;
    }

  }
  return c;
}
Ejemplo n.º 5
0
QByteArray AuthorizationManager::pubkeyForMd5(QString md5_base64){
  QByteArray md5 = QByteArray::fromBase64( md5_base64.toLocal8Bit() );

QStringList keys; //Format: "RegisteredCerts/<user>/<key>" (value is full text)
    //Read all user's certs (since we only need checksums)
    keys = CONFIG->allKeys().filter("RegisteredCerts/");
  keys.sort();
  QJsonArray arr;
  QCryptographicHash chash(QCryptographicHash::Md5);
  //qDebug() << "MD5 Generation:";
  for(int i=0; i<keys.length(); i++){
    //qDebug() << "User:"******"/",1,1);
    QByteArray key = QByteArray::fromBase64( keys[i].section("/",2,-1).toLocal8Bit() ); //remember that the keys are stored internally as base64-encoded strings
    //qDebug() << " - Key:" << key;
    chash.addData( key );
    QByteArray res = chash.result();
    //qDebug() << " - md5:" << res;
    chash.reset();
    if(res==md5){
      //qDebug() << "Found key for MD5:" << key;
      return key;
    }
  }
  return ""; //fallback - no matching key found
}
Ejemplo n.º 6
0
arrayul crand(unsigned char u[N]){
//  unsigned char crand(unsigned char u[N]){
  arrayn a;
  int i,j;
  arrayul b;

  a=chash(u);
  j=0;
  for(i=0;i<sizeof(b.u);i++)
    b.u[i]=0;
  
  for(i=0;i<N;i++)
    b.d[i]^=a.ar[i];
  
  
  return b;
}
Ejemplo n.º 7
0
void AuthorizationManager::ListCertificateChecksums(QJsonObject *out){
 QStringList keys; //Format: "RegisteredCerts/<user>/<key>" (value is full text)
    //Read all user's certs (since we only need checksums)
    keys = CONFIG->allKeys().filter("RegisteredCerts/");
  keys.sort();
  QJsonArray arr;
  QCryptographicHash chash(QCryptographicHash::Md5);
  //qDebug() << "MD5 Generation:";
  for(int i=0; i<keys.length(); i++){
    //qDebug() << "User:"******"/",1,1);
    QByteArray key = QByteArray::fromBase64( keys[i].section("/",2,-1).toLocal8Bit() ); //remember that the keys are stored internally as base64-encoded strings
    //qDebug() << " - Key:" << key;
    chash.addData( key );
    QByteArray res = chash.result();
    //qDebug() << " - md5:" << res;
    chash.reset();
    //qDebug() << " - base64:" << res.toBase64();
    arr << QString(res.toBase64());
  }
  out->insert("md5_keys", arr);
}
Ejemplo n.º 8
0
int main(int argc,char *argv[]){
  int i,j,k,count=0;
  unsigned char inv_x[N],o;
  unsigned char a[N],b[N],inv_b[N],c[N];
  time_t t;
  FILE *fp,*fo;
  set fai;
  arrayn p,aa;
  array8 q;

  
  unsigned char cipher[4];
  unsigned char temp[N];
  unsigned char inv_c[16][N];
  
  unsigned char test[32]={1,1,1,1,0,0,0,0,1,0,1,0,1,0,1,0,1,1,1,1,0,0,0,0,1,0,1,0,1,0,1,0};
  unsigned char ee[4];
  unsigned int t2=0,l=0;
  char m[1];

  unsigned char u[N/2],tmp[N],tmb[N];
  unsigned char inv_t[16][N];
  unsigned char nx[N];

  arrayul pp;
  array16 tt;

  seed();
  pp=crand(password);
  for(i=0;i<8;i++)
    printf("%llu\n",pp.u[i]);

  hout();

  //  mainga(argc,argv);
  exit(1);

  
  tt=hash(argc,argv);
  for(i=0;i<16/2;i++)
    printf("%08x ",tt.h[i]);
  printf("\n");

  

  srand(time(&t));

  //    chksalt();
       gendata();
  exit(1);
  
  for(i=0;i<N/2;i++){
    u[i]=rand()%256;
    printf("%u\n",u[i]);
  }


  printf("input mode\n");
  scanf("%s",&m);

  if(strcmp(m,"k")==0)
    keygen();
  if(strcmp(m,"d")==0){
    fp=fopen("braidsec.key","rb");
    fread(nx,1,N,fp);
    fclose(fp);
  }
  if(strcmp(m,"e")==0){
    fp=fopen("braidpub.key","rb");
    fread(pr,1,N,fp);
    fread(ps,1,N,fp);
    /*
   for(i=0;i<N;i++)
     printf("%d,",s[i]);
   printf("\n");
   */
    fclose(fp);
  }


  char file[100],out[100];
  int f;
  unsigned char buf[64];
  unsigned char h[N],rr[N];
  
  for(i=0;i<N;i++)
    h[i]= r[i];
  
  printf("\ninput file name\n");
  scanf("%s",&file);
  fp=fopen(file,"rb");
  printf("input outfile name\n");
  scanf("%s",&out);
  fo=fopen(out,"wb");
 

  j=0;

  if(strcmp("d",m)==0){
    for(i=0;i<N;i++)
      inv_b[nx[i]]=i;
    for(i=0;i<N;i++)
      pr[i]=nx[r[inv_b[i]]];
    for(i=0;i<N;i++)
      ps[i]=nx[s[inv_b[i]]];
  }

  for(i=0;i<N;i++)
    rr[i]=rand()%256;


  if(strcmp(m,"e")==0){
    fai=session(rr);
    
    for(i=0;i<N;i++)
      printf("%d,",fai.b[i]);
    printf("\n");
    
    fwrite(fai.a,1,64,fo);
  }


  if(strcmp(m,"d")==0){
    fread(fai.a,1,64,fp);
    for(k=0;k<N;k++){
      c[k]=nx[fai.a[inv_b[k]]];
      printf("%d,",c[k]);
    }
    printf("aaa\n");
  }

while((f=fread(buf,1,64,fp))>0){

  if(strcmp("e",m)==0){
    p=chash(fai.b);
    /*
    for(i=0;i<N;i++)
      printf("%d,",p.ar[i]);
    printf("\n");
    */
    for(k=0;k<N;k++)
      rr[k]=p.ar[k];
    fai=session(rr);
    for(k=0;k<N;k++)
      buf[k]^=p.ar[k];
  }
  if(strcmp("d",m)==0){
  /*
    for(i=0;i<N;i++)
      printf("%d,",c[i]);
    printf("vv\n");
    //        exit(1);
    */
    p=chash(c);
    
    for(k=0;k<N;k++){
      buf[k]^=p.ar[k];
      rr[k]=p.ar[k];
    }
    fai=session(rr);
    /*
    for(i=0;i<N;i++)
      printf("%d,",p.ar[i]);
    printf("bb\n");
    */
    //    exit(1);
    for(k=0;k<N;k++)
      c[k]=fai.b[k];
    
  }
  fwrite(buf,1,f,fo);

 }

 fclose(fp);
 fclose(fo);


return 0;
}
Ejemplo n.º 9
0
int curse_read(attrib * a, void *owner, struct storage *store)
{
  curse *c = (curse *) a->data.v;
  int ur;
  char cursename[64];
  int n;
  int flags;
  float flt;

  READ_INT(store, &c->no);
  chash(c);
  READ_TOK(store, cursename, sizeof(cursename));
  READ_INT(store, &flags);
  READ_INT(store, &c->duration);
  if (global.data_version >= CURSEVIGOURISFLOAT_VERSION) {
    READ_FLT(store, &flt);
    c->vigour = flt;
  } else {
    READ_INT(store, &n);
    c->vigour = (float)n;
  }
  if (global.data_version < INTPAK_VERSION) {
    ur = read_reference(&c->magician, store, read_int, resolve_unit);
  } else {
    ur = read_reference(&c->magician, store, read_unit_reference, resolve_unit);
  }
  if (global.data_version < CURSEFLOAT_VERSION) {
    READ_INT(store, &n);
    c->effect = (float)n;
  } else {
    READ_FLT(store, &flt);
    c->effect = flt;
  }
  c->type = ct_find(cursename);
  if (c->type == NULL) {
    int result = read_ccompat(cursename, store);
    if (result != 0) {
      log_error("missing curse %s, no compatibility code either.\n", cursename);
    }
    assert(result == 0);
    return AT_READ_FAIL;
  }
  if (global.data_version < CURSEFLAGS_VERSION) {
    c_setflag(c, flags);
  } else {
    c->flags = flags;
  }
  c_clearflag(c, CURSE_ISNEW);

  if (c->type->read)
    c->type->read(store, c, owner);
  else if (c->type->typ == CURSETYP_UNIT) {
    READ_INT(store, &c->data.i);
  }
  if (c->type->typ == CURSETYP_REGION) {
    int rr =
      read_reference(&c->data.v, store, read_region_reference,
      RESOLVE_REGION(global.data_version));
    if (ur == 0 && rr == 0 && !c->data.v) {
      return AT_READ_FAIL;
    }
  }

  return AT_READ_OK;
}
Ejemplo n.º 10
0
uint64_t ResizeEvent::hash() const {
    return chash();
}