int main(int argc, char *argv[]) { int i=0, j=0, k=0, l=0; if(argc != 5) { ShowUsage(); } char* pass = argv[1]; char* salt = argv[2]; int m_cost = atoi(argv[3]); int t_cost = atoi(argv[4]); double MS_EL = 0; unsigned char Hash[64]; printf("\n Password : %s", pass ); printf("\n salt : %s", salt ); printf("\n m_cost : %d", m_cost ); printf("\n t_cost : %d", t_cost ); PHS(Hash, 64, (unsigned char *)pass, strlen(pass), (unsigned char*)salt, strlen(salt), t_cost, m_cost); PrintHash("\n\n Hash : ", Hash); getchar(); return 0; }
int main() {//已经全部转换成小写。's会被统计成s, 连字符-没考虑 FILE *f_open; f_open=fopen("lower.txt","rb"); FILE *write[26]; FILE *INDEX; INDEX=fopen("index.txt","wb"); char name[26][6]; Info *hash[26]; for(int i=0;i<26;i++) { name[i][0]=i+'A'; strncpy(name[i]+1,".txt\0",5); write[i]=fopen(name[i],"wb"); hash[i]=CreateInfo(); } char c; char word[20]; char *p; int words=0; while((c=fgetc(f_open))!=EOF) { while(!isalpha(c)) if((c=fgetc(f_open))==EOF) goto toend; words++; p=word; while(isalpha(c)) { *p++=c; if((c=fgetc(f_open))==EOF) { *p='\0'; break; } } *p='\0'; assert(isalpha(word[0])); IfExsist(hash[word[0]-'a'],word); } toend:; PrintHash(hash,INDEX); for(int i=0;i<26;i++) { WordQsort(hash[i]); PrintResult(hash[i],write[i],i); } fclose(f_open); for(int i=0;i<26;i++) fclose(write[i]); fclose(INDEX); return 0; }
/* hash bit sequence */ HashReturn Hash(int hashbitlen, const BitSequence* data, DataLength databitlen, BitSequence* hashval) { HashReturn ret; hashState ctx; /* initialise */ if ((ret = Init(&ctx, hashbitlen))) return ret; #ifndef TURN_OFF_PRINTING char str[1+(databitlen+7)/8]; str[(databitlen+7)/8] = 0; memcpy(str, data, (databitlen+7)/8); printf("########################################\n\n"); printf("Groestl\n"); printf(" Message Digest Length = %d\n\n", hashbitlen); printf("########################################\n\n\n"); printf("%d-Block Message Sample\n\n", (int)(1+(databitlen+8*LENGTHFIELDLEN)/(8*ctx.statesize))); printf(" Input Message = \"%s\"\n\n", str); printf("========================================\n\n"); printf("Initial state:\n"); PrintState(&ctx, ctx.chaining); printf("\n"); #endif /* process message */ if ((ret = Update(&ctx, data, databitlen))) return ret; /* finalise */ ret = Final(&ctx, hashval); #ifndef TURN_OFF_PRINTING printf("\n----------------------------------------\n\n"); printf("Message Digest is\n"); PrintHash(hashval, hashbitlen); #endif return ret; }
int main(int argc, char **argv) { HashObjectPtr p; char * line = (char *)malloc(sizeof(char)*MAX_INPUT_LENGTH); printOptions(); while (fgets(line, MAX_INPUT_LENGTH, stdin)!=NULL) { switch (line[0]) { case 'c': if (table == NULL) { if ((table = createNewHashTable()) == NULL) { printOptions(); break; } else { printf("\n\nSuccess. What would you like to do now?\n\n"); printOptions(); } } else { FreeHashTable(table); if ((table = createNewHashTable()) == NULL) { printOptions(); break; } else { printf("\n\nSuccess. What would you like to do now?\n\n"); printOptions(); } } break; case 'l': if (table == NULL) { printf("You need to first instantiate a hashtable, use the 'c' option\n\n"); break; } else { if ((p = wordSearch(table)) != NULL) { printf("\n\nSuccess. What would you like to do now?\n\n"); printOptions(); } else { printOptions(); } } break; case 'f': if (table == NULL) { printf("You need to first instantiate a hashtable, use the 'c' option\n\n"); break; } if (uploadAndRunFile(table) != NULL) { printf("\n\nSuccess. What would you like to do now?\n\n"); printOptions(); } break; case 'p': if (table == NULL) { printf("You need to first instantiate a hashtable, use the 'c' option\n\n"); break; } printf("\n\nPrinting Hash Table\n\n"); PrintHash(table); printf("\n\nSuccess. What would you like to do now?\n\n"); printOptions(); break; case 'r': if (table == NULL) { printf("You need to first instantiate a hashtable, use the 'c' option\n\n"); break; } removeThings(); break; case 'q': FreeHashTable(table); free(line); printf("\n\nGoodbye\n\n"); return 0; case 's': if (table == NULL) { printf("You need to first instantiate a hashtable, use the 'c' option\n\n"); break; } break; default: printf("%s\n", "That is an unrecognized entry, please try again\n\n"); printOptions(); break; } } free(line); return 0; }
// Does the NSEC3 in "ncr" covers the "name" ? // hashName is hash of the "name" and b32Name is the base32 encoded equivalent. mDNSlocal mDNSBool NSEC3CoversName(mDNS *const m, CacheRecord *ncr, const mDNSu8 *hashName, int hashLen, const mDNSu8 *b32Name, int b32len) { mDNSu8 *nxtName; int nxtLength; int ret, ret1, ret2; const mDNSu8 b32nxtname[NSEC3_MAX_B32_LEN+1]; int b32nxtlen; NSEC3Parse(&ncr->resrec, mDNSNULL, &nxtLength, &nxtName, mDNSNULL, mDNSNULL); if (nxtLength != hashLen || ncr->resrec.name->c[0] != b32len) return mDNSfalse; // Compare the owner names and the "nxt" names. // // Owner name is base32 encoded and hence use the base32 encoded name b32name. // nxt name is binary and hence use the binary value in hashName. ret1 = NSEC3SameName(&ncr->resrec.name->c[1], ncr->resrec.name->c[0], b32Name, b32len); ret2 = DNSMemCmp(nxtName, hashName, hashLen); #if NSEC3_DEBUG { char nxtbuf1[50]; char nxtbuf2[50]; PrintHash(nxtName, nxtLength, nxtbuf1, sizeof(nxtbuf1)); PrintHash((mDNSu8 *)hashName, hashLen, nxtbuf2, sizeof(nxtbuf2)); LogMsg("NSEC3CoversName: Owner name %s, name %s", &ncr->resrec.name->c[1], b32Name); LogMsg("NSEC3CoversName: Nxt hash name %s, name %s", nxtbuf1, nxtbuf2); } #endif // "name" is greater than the owner name and smaller than nxtName. This also implies // that nxtName > owner name implying that it is normal NSEC3. if (ret1 < 0 && ret2 > 0) { LogDNSSEC("NSEC3CoversName: NSEC3 %s covers %s (Normal)", CRDisplayString(m, ncr), b32Name); return mDNStrue; } // Need to compare the owner name and "nxt" to see if this is the last // NSEC3 in the zone. Only the owner name is in base32 and hence we need to // convert the nxtName to base32. b32nxtlen = baseEncode((char *)b32nxtname, sizeof(b32nxtname), nxtName, nxtLength, ENC_BASE32); if (!b32nxtlen) { LogDNSSEC("NSEC3CoversName: baseEncode of nxtName of %s failed", CRDisplayString(m, ncr)); return mDNSfalse; } if (b32len != b32nxtlen) { LogDNSSEC("NSEC3CoversName: baseEncode of nxtName for %s resulted in wrong length b32nxtlen %d, b32len %d", CRDisplayString(m, ncr), b32len, b32nxtlen); return mDNSfalse; } LogDNSSEC("NSEC3CoversName: Owner name %s, b32nxtname %s, ret1 %d, ret2 %d", &ncr->resrec.name->c[1], b32nxtname, ret1, ret2); // If it is the last NSEC3 in the zone nxt < "name" and NSEC3SameName returns -1. // // - ret1 < 0 means "name > owner" // - ret2 > 0 means "name < nxt" // // Note: We also handle the case of only NSEC3 in the zone where NSEC3SameName returns zero. ret = NSEC3SameName(b32nxtname, b32nxtlen, &ncr->resrec.name->c[1], ncr->resrec.name->c[0]); if (ret <= 0 && (ret1 < 0 || ret2 > 0)) { LogDNSSEC("NSEC3CoversName: NSEC3 %s covers %s (Last), ret1 %d, ret2 %d", CRDisplayString(m, ncr), b32Name, ret1, ret2); return mDNStrue; } return mDNSfalse; }