加密:lua实现 (lua有的版本没有位运算, lua位运算详细可以推荐这个帖子Lua位运算环境)
local bit = require “bit”; --加载bit库
funcation GetEncodeUserID(userId)
local enCodeUserId = userId + 999999;
enCodeUserId = bit.bxor(43690, enCodeUserId);
return enCodeUserId;
end
解密:
funcation GetDeCodeUserID(enCodeUserId)
local uId = bit.bxor(43690, enCodeUserId);
uId = uId - 999999;
return uId;
end
C#
//加密
public static ulong GetEncodeUserID(ulong userId)
{
ulong enCodeUserId = userId + 999999;
enCodeUserId ^= 43690;
return enCodeUserId;
}
//解密
public static ulong GetDecodeUserID(ulong enCodeUserId)
{
ulong uId = enCodeUserId ^ 43690;
uId = uId - 999999;
return uId;
}