int main(){ uint32_t hh=0xf113cca1; printf("Debug: %x %x %x %x\n", hh, hash(hh), hash(hh)^0x9513aaa5, _rotr(hash(hh)^0x9513aaa5,7)); uint32_t temp=0; for(int i=0;i<10;i++){ uint32_t newtemp=hashes[i*4]<<24; newtemp|=hashes[i*4+1]<<16; newtemp|=hashes[i*4+2]<<8; newtemp|=hashes[i*4+3]<<0; printf("newtemp is %x\n", newtemp); // newtemp=_rotr(temp^hash(block), 7) // thus: // _rotl(newtemp,7)=temp^hash(block) // hash(block)=_rotl(newtemp)^temp; printf("Rotled: %x\n", _rotl(newtemp, 7)); printf("temp: %x\n", temp); printf("xored: %x\n", _rotl(newtemp, 7)^temp); uint32_t h=_rotl(newtemp, 7)^temp; printf("Finding hash for %x\n", h); find_collisions(h); temp=newtemp; } }
unsigned short sixteenbits(unsigned short seed) { /* In use, we call sixteenbits(seed) once with some nonzero seed, and from then on call it with seed value zero to get the next random value. It also works fine if you don't seed it it all, but for short runs you may want to start from different seeds. Using the same seed twice produces the same sequence of numbers.*/ register unsigned short l,c,r; if (seed) { shiftregister = seed; count = 0; return seed; } l = r = c = shiftregister; #ifndef MYMACROS //Borland compiler l = _rotr(l, 1);/* bit i of l equals bit just left of bit i in c */ r = _rotl(r, 1);/* bit i of r euqals bit just right of bit i in c */ #else //other compiler l = MYROTR(l);/* bit i of l equals bit just left of bit i in c */ r = MYROTL(r);/* bit i of r euqals bit just right of bit i in c */ #endif //MYMACROS c |= r; c ^= l; /* c = l xor (c or r), aka rule 30, named by wolfram */ c ^= count; /* rucker's trick to make reaction self-sustaining */ count++; shiftregister = c; return c; }
unsigned long __cdecl _lrotr ( unsigned long val, int shift ) { return( (unsigned long) _rotr((unsigned) val, shift) ); }
//------- Begin of function Info::init_random_seed ------// // // [unsigned] randomSeed - if given, it will be the random seed of the game. // random seed. otherwise a random seed will be // picked. // (default:0) // void Info::init_random_seed(int randomSeed) { if( randomSeed ) random_seed = randomSeed; else { randomSeed = time(NULL); randomSeed = (int) _rotr( randomSeed, 4 ); if( randomSeed < 0 ) randomSeed = ~randomSeed; if( randomSeed == 0 ) randomSeed = 1; random_seed = randomSeed; } misc.set_random_seed(random_seed); //------ write random seed --------// if( sys.testing_session ) { File fileMapSeed; fileMapSeed.file_create( "MAP.RS" ); String str(misc.format(random_seed,1)); fileMapSeed.file_write(str, str.len()); } }
inline uint32_t rot32(uint32_t x, int s) { #ifdef _MSC_VER return _rotr(x, s); #else return (x >> s) | (x << (32 - s)); #endif }
uint32_t hash(uint32_t num){ num^=0x24f50094U; num=_rotr(num, num&0xF); num+=0x2219ab34U; num=_rotl(num, num&0xF); num*=0x69a2c4feU; return num; }
unsigned int CSaveRestoreBuffer::HashString( const char *pszToken ) { unsigned int hash = 0; while( *pszToken ) hash = _rotr( hash, 4 ) ^ *pszToken++; return hash; }
DWORD Mem2Hash(BYTE *mem, int length) { DWORD dwHash; dwHash = 0; do { dwHash = _rotr((DWORD)dwHash, 13); dwHash += *mem++; } while (--length); return dwHash; }
DWORD Utils::Str2Hash(char *str, int length, int casesensitive, int incr) { DWORD dwHash; if( length==0 ) { while( str[length]!=0 || (incr>1 && str[length+1]!=0) ) length+=incr; } length/=incr; dwHash = 0; do { dwHash = _rotr( (DWORD)dwHash, 13 ); if( !casesensitive && *((BYTE *)str) >= 'a' ) dwHash += *((BYTE *)str) - 0x20; else dwHash += *((BYTE *)str); str+=incr; } while( --length ); return dwHash; }
int main(int argc, char* argv[]) { llu sum = 0; uint low = 1 << 4; uint up = 1 << 25; int subseq[TWOPOW]; for (uint i = low; i < up; i++) { for (int j = 0; j < TWOPOW; j++) subseq[j] = 0; uint ii = 2 * (up + i) + 1; uint jj = ii; for (int j = 0; j < TWOPOW; j++) { ii = _rotr(ii, 1); subseq[ii % TWOPOW]++; } int j; for (j = 0; j < TWOPOW; j++) if (subseq[j] != 1) break; if (j == TWOPOW) { sum += jj; } } printf("%llu\n", sum); return 0; }
static int EnterDict( unsigned char *bucketsP, unsigned short ndicpages, unsigned char *entry, unsigned entrylen ) { unsigned short uStartIndex; unsigned short uStep; unsigned short uStartPage; unsigned short uPageStep; unsigned short uIndex; unsigned short uPage; unsigned short n; unsigned u; unsigned nbytes; unsigned char *aP; unsigned char *zP; aP = entry; zP = aP + entrylen; // point at last char in identifier uStartPage = 0; uPageStep = 0; uStartIndex = 0; uStep = 0; u = entrylen; while ( u-- ) { uStartPage = _rotl( uStartPage, 2 ) ^ ( *aP | 0x20 ); uStep = _rotr( uStep, 2 ) ^ ( *aP++ | 0x20 ); uStartIndex = _rotr( uStartIndex, 2 ) ^ ( *zP | 0x20 ); uPageStep = _rotl( uPageStep, 2 ) ^ ( *zP-- | 0x20 ); } uStartPage %= ndicpages; uPageStep %= ndicpages; if ( uPageStep == 0 ) uPageStep++; uStartIndex %= HASHMOD; uStep %= HASHMOD; if ( uStep == 0 ) uStep++; uPage = uStartPage; uIndex = uStartIndex; // number of bytes in entry nbytes = 1 + entrylen + 2; if (entrylen > 255) nbytes += 2; while (1) { aP = &bucketsP[uPage * BUCKETPAGE]; uStartIndex = uIndex; while (1) { if ( 0 == aP[ uIndex ] ) { // n = next available position in this page n = aP[ HASHMOD ] << 1; assert(n > HASHMOD); // if off end of this page if (n + nbytes > BUCKETPAGE ) { aP[ HASHMOD ] = 0xFF; break; // next page } else { aP[ uIndex ] = n >> 1; memcpy( (aP + n), entry, nbytes ); aP[ HASHMOD ] += (nbytes + 1) >> 1; if (aP[HASHMOD] == 0) aP[HASHMOD] = 0xFF; return 1; } } uIndex += uStep; uIndex %= 0x25; /*if (uIndex > 0x25) uIndex -= 0x25;*/ if( uIndex == uStartIndex ) break; } uPage += uPageStep; if (uPage >= ndicpages) uPage -= ndicpages; if( uPage == uStartPage ) break; }
void load() { int stocks = 0; Stock tmp; FILE *save = fopen("save.ns3", "rb"); if (save == NULL) { init(); return; } fscanf(save, "%d ", &stocks); stocks = _rotr(stocks, 1); for (int i = 0; i < stocks; i++) { now = head; fscanf(save, "%d %d ", &tmp.company, &tmp.price); tmp.company = _rotr(tmp.company, 1); tmp.price = _rotr(tmp.price, 1); InsertStock(now, &tmp); } for (int i = 0; i < MAX_COMPANY; i++) { fscanf(save, "%d ", &StockPrice[i]); StockPrice[i] = _rotr(StockPrice[i], 1); } for (int i = 0; i < MAX_COMPANY; i++) { fscanf(save, "%d ", &ifGood[i]); ifGood[i] = _rotr(ifGood[i], 1); } fscanf(save, "%d %d %d %d %d %d %d %d %d", &Money, &loanMoney, &Stocks, &StockDeal, &month, &day, &hour, &viewmode, &timemode); Money = _rotr(Money, 1); loanMoney = _rotr(loanMoney, 1); Stocks = _rotr(Stocks, 1); StockDeal = _rotr(StockDeal, 1); month = _rotr(month, 1); day = _rotr(day, 1); hour = _rotr(hour, 1); fclose(save); }
inline unsigned int _rotl(unsigned int x, unsigned int y) { return _rotr(x, 32 - y); }
STextHeader* CTextHandler::FindTextPos(UInt32 dwHash[4], Bool bRemove /* = False */) { UInt32 l, r, m; STextHeader *h; l = 0; r = m_IndexCount; while (l < r) { m = (l + r) / 2; h = (STextHeader *)(_rotr((Int_Ptr)m_pIndex[m], m + 1) ^ m_Key); if (h == NULL) return NULL; if (h->Hash[0] < dwHash[0]) { l = m + 1; continue; } else if (h->Hash[0] > dwHash[0]) { r = m; continue; } if (h->Hash[1] < dwHash[1]) { l = m + 1; continue; } else if (h->Hash[1] > dwHash[1]) { r = m; continue; } if (h->Hash[2] < dwHash[2]) { l = m + 1; continue; } else if (h->Hash[2] > dwHash[2]) { r = m; continue; } if (h->Hash[3] < dwHash[3]) { l = m + 1; continue; } else if (h->Hash[3] > dwHash[3]) { r = m; continue; } if (bRemove) m_pIndex[m] = NULL; return h; } return NULL; }