RainBow Table
160 字
1 分钟
RainBow Table
题面

答案
#include <cuda_runtime.h>
__device__ unsigned int fnv1a_hash(unsigned int input) { const unsigned int FNV_PRIME = 16777619; const unsigned int OFFSET_BASIS = 2166136261;
unsigned int hash = OFFSET_BASIS;
for (int byte_pos = 0; byte_pos < 4; byte_pos++) { unsigned char byte = (input >> (byte_pos * 8)) & 0xFFu; hash = (hash ^ byte) * FNV_PRIME; }
return hash;}
__global__ void fnv1a_hash_kernel(const int* input, unsigned int* output, int N, int R) { int idx = blockDim.x * blockIdx.x + threadIdx.x; if (idx >= N) return;
unsigned int val = static_cast<unsigned int>(input[idx]);
for (int r = 0; r < R; r++) { val = fnv1a_hash(val); }
output[idx] = val;}
// input, output are device pointers (i.e. pointers to memory on the GPU)extern "C" void solve(const int* input, unsigned int* output, int N, int R) { int threadsPerBlock = 256; int blocksPerGrid = (N + threadsPerBlock - 1) / threadsPerBlock;
fnv1a_hash_kernel<<<blocksPerGrid, threadsPerBlock>>>(input, output, N, R); cudaDeviceSynchronize();}


