aboutsummaryrefslogtreecommitdiff
path: root/src/hash/loselose.c
blob: f3350f564ccd3864527217a70d6eff79e5093bef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "../util.h"
#include "../crypto.h"
#include <stdio.h>
#include <stdint.h>

uint64_t loselose(uint8_t* in, size_t len){
    uint64_t hash = 0;

    for(int i = 0; i != len; i++){
        hash += (uint64_t)*in;
        in++;
    }

    return hash;
}

int l_loselose(lua_State* L){ 
  size_t len = 0;
  uint8_t* a = (uint8_t*)luaL_checklstring(L, 1, &len);

  char digest[64];

  uint64_t u = loselose(a, len);
  sprintf(digest,"%08lx",u);
  lua_pushstring(L, digest);
  return 1;
}