Fix crypto.mask() to encode with correct mask (#1677) (#1678)

Thank you.
This commit is contained in:
kicer 2016-12-24 01:03:02 +08:00 committed by Philip Gladstone
parent 1452fbfd13
commit 118acb808e
1 changed files with 7 additions and 1 deletions

View File

@ -124,13 +124,19 @@ static int crypto_mask( lua_State* L )
int len, mask_len;
const char* msg = luaL_checklstring(L, 1, &len);
const char* mask = luaL_checklstring(L, 2, &mask_len);
if(mask_len <= 0)
return luaL_error(L, "invalid argument: mask");
int i;
char* copy = (char*)c_malloc(len);
for (i = 0; i < len; i++) {
copy[i] = msg[i] ^ mask[i % 4];
copy[i] = msg[i] ^ mask[i % mask_len];
}
lua_pushlstring(L, copy, len);
c_free(copy);
return 1;
}