works:programmer:cpp:achash
Простейшая функция хеширование строки
#include <iostream> #include <cstring> using namespace std; void cHash(const char* in, char* out) { const char allowed_chars[] = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"; const int allowed_len = strlen(allowed_chars); const int inlen = strlen(in); char last = 254; for (int i=0; i<inlen; i++) { char c = in[i]; out[i] = allowed_chars[(c+last) % allowed_len]; last = c; } } int main() { char buffer[] = "Hello world!"; char* next = (char*) malloc(strlen(buffer)*sizeof(char)); cHash(buffer, next); cout << next << endl; free(next); return 0; }
works/programmer/cpp/achash.txt · Последнее изменение: 2021/08/06 07:34 — 127.0.0.1