--[[ *Apokalypsys, Dimus *http://minecrafting[paste][/paste]ru/ *http://minecrafting[paste][/paste]ru/forum/viewtopic[paste][/paste]php?f=32&t=5331]]local hex_char = "0123456789abcdef"local function to_equal_length(x, y) x_len = x:len() y_len = y:len() if x_len > y_len then y = string[paste][/paste]rep("0", x_len-y_len)[paste][/paste][paste][/paste]y elseif y_len > x_len then x = string[paste][/paste]rep("0", y_len-x_len)[paste][/paste][paste][/paste]x end return x, yendfunction bit[paste][/paste]bin_to_dec(x) if x:len() > 32 then x = x:sub(x:len() - 31) end if tonumber(x:sub(1, 1)) == 1 then return -4294967296 + tonumber(x, 2) else return tonumber(x, 2) endendfunction bit[paste][/paste]add(x, y) local remember_bit = 0 local z = "" x, y = to_equal_length(x, y) for i = x:len(),1,-1 do z = bit[paste][/paste]bxor(bit[paste][/paste]bxor(tonumber(x:sub(i, i)), tonumber(y:sub(i, i))), remember_bit)[paste][/paste][paste][/paste]z remember_bit = bit[paste][/paste]brshift(tonumber(x:sub(i, i)) + tonumber(y:sub(i, i) + remember_bit), 1) end if remember_bit == 1 then if z:len() == 32 then z = string[paste][/paste]rep("0", 32) else z = "1"[paste][/paste][paste][/paste]z end end return zendfunction bit[paste][/paste]_bnot() endfunction bit[paste][/paste]dec_to_bin(x) local sign = false if type(x) ~= "number" then return nil elseif x == 0 then return string[paste][/paste]rep("0", 32) elseif x < 0 then sign = true x = -x end y = "" while x > 0 do if (x % 2 == 1) then y = "1"[paste][/paste][paste][/paste]y else y = "0"[paste][/paste][paste][/paste]y end x = math[paste][/paste]floor(x / 2) end for i = 32 - y:len(), 1, -1 do y = "0"[paste][/paste][paste][/paste]y end if sign then y = bit[paste][/paste]add(bit[paste][/paste]_bnot(y), bit[paste][/paste]dec_to_bin(1)) end return yendfunction bit[paste][/paste]_bnot(x) if type(x) == "number" then x = bit[paste][/paste]dec_to_bin(x) end local y = "" for i = 1, x:len() do y = y[paste][/paste][paste][/paste](1 - tonumber(x:sub(i, i))) end return yendfunction bit[paste][/paste]_band(x, y) x = bit[paste][/paste]dec_to_bin(x) y = bit[paste][/paste]dec_to_bin(y) local z = "" x, y = to_equal_length(x, y) for i = 1, x:len() do if tonumber(x:sub(i, i))+tonumber(y:sub(i, i)) == 2 then z = z[paste][/paste][paste][/paste]"1" else z = z[paste][/paste][paste][/paste]"0" end end return bit[paste][/paste]bin_to_dec(z)endfunction bit[paste][/paste]_bor(x, y) x = bit[paste][/paste]dec_to_bin(x) y = bit[paste][/paste]dec_to_bin(y) local z = "" x, y = to_equal_length(x, y) for i = 1, x:len() do if tonumber(x:sub(i, i))+tonumber(y:sub(i, i)) > 0 then z = z[paste][/paste][paste][/paste]"1" else z = z[paste][/paste][paste][/paste]"0" end end return bit[paste][/paste]bin_to_dec(z)endfunction bit[paste][/paste]_blshift(x, y) return bit[paste][/paste]_band(x * (2 ^ y), 4294967295)endfunction bit[paste][/paste]_brshift(x, y) return bit[paste][/paste]_band(math[paste][/paste]floor(x / (2 ^ y)), 4294967295)endfunction string[paste][/paste]charAt(str_self, x) return str_self:sub(x, x)endlocal function getHex(seed) local str = "" for i = 0, 3 do local ind1, ind2 = bit[paste][/paste]_band(bit[paste][/paste]_brshift(seed, i * 8 + 4), 15) + 1, bit[paste][/paste]_band(bit[paste][/paste]_brshift(seed, i * 8), 15) + 1 str = str[paste][/paste][paste][/paste] hex_char:sub(ind1, ind1)[paste][/paste][paste][/paste] hex_char:sub(ind2, ind2) end return strendlocal function string_to_blks(str) local nblk = bit[paste][/paste]_brshift((str:len() + 8), 6) + 1 local blks = {} local len = str:len() for i = 0, nblk * 16 - 1 do blks[i] = 0 end for i = 0, str:len() - 1 do blks[bit[paste][/paste]_brshift(i, 2)] = bit[paste][/paste]_bor( blks[bit[paste][/paste]_brshift(i, 2)], bit[paste][/paste]_blshift( str:byte(i+1), (((i) % 4) * 8) ) ) end blks[bit[paste][/paste]_brshift(len, 2)] = bit[paste][/paste]_bor( blks[bit[paste][/paste]_brshift(len, 2)], bit[paste][/paste]_blshift( 128, (((len) % 4) * 8) ) ) blks[nblk * 16 - 2] = len * 8 return blksendlocal function add(x, y) local lsw = bit[paste][/paste]_band(x, 0xFFFF) + bit[paste][/paste]_band(y, 0xFFFF) local msw = bit[paste][/paste]_brshift(x, 16) + bit[paste][/paste]_brshift(y, 16) + bit[paste][/paste]_brshift(lsw, 16) return bit[paste][/paste]_bor(bit[paste][/paste]_blshift(msw, 16), bit[paste][/paste]_band(lsw, 0xFFFF))endlocal function rol(number, count) return bit[paste][/paste]_bor(bit[paste][/paste]_blshift(number, count), bit[paste][/paste]blogic_rshift(number, (32 - count)))endlocal function X(a, b, c, x, s, t) return add(rol(add(add(b, a), add(x, t)), s), c)endlocal function F(a, b, c, d, x, s, t) return X(bit[paste][/paste]_bor(bit[paste][/paste]_band(b, c), bit[paste][/paste]_band(bit[paste][/paste]bin_to_dec(bit[paste][/paste]_bnot(b)), d)), a, b, x, s, t)endlocal function G(a, b, c, d, x, s, t) return X(bit[paste][/paste]_bor(bit[paste][/paste]_band(b, d), bit[paste][/paste]_band(c, bit[paste][/paste]bin_to_dec(bit[paste][/paste]_bnot(d)))), a, b, x, s, t)endlocal function H(a, b, c, d, x, s, t) return X(bit[paste][/paste]bxor(bit[paste][/paste]bxor(b, c), d), a, b, x, s, t)endlocal function I(a, b, c, d, x, s, t) return X(bit[paste][/paste]bxor(c, bit[paste][/paste]_bor(b, bit[paste][/paste]bin_to_dec(bit[paste][/paste]_bnot(d)))), a, b, x, s, t)endfunction count(table) local i, k = 1, -1 while true do if (math[paste][/paste]abs(i-k) ~= 1) then if (table[i] == nil) then i = math[paste][/paste]ceil((i + k) / 2) else k = i i = i * 2 end elseif (table[i] == nil) then return k else k = i i = i * 2 end endendfunction encode(encoding_string) blks = string_to_blks(encoding_string) a = 1732584193 b = -271733879 c = -1732584194 d = 271733878 for i = 0, count(blks)-1, 16 do local olda, oldb, oldc, oldd = a, b, c, d a = F(a, b, c, d, blks[i+ 0], 7, -680876936) d = F(d, a, b, c, blks[i+ 1], 12, -389564586) c = F(c, d, a, b, blks[i+ 2], 17, 606105819) b = F(b, c, d, a, blks[i+ 3], 22, -1044525330) a = F(a, b, c, d, blks[i+ 4], 7, -176418897) d = F(d, a, b, c, blks[i+ 5], 12, 1200080426) c = F(c, d, a, b, blks[i+ 6], 17, -1473231341) b = F(b, c, d, a, blks[i+ 7], 22, -45705983) a = F(a, b, c, d, blks[i+ 8], 7, 1770035416) d = F(d, a, b, c, blks[i+ 9], 12, -1958414417) c = F(c, d, a, b, blks[i+10], 17, -42063) b = F(b, c, d, a, blks[i+11], 22, -1990404162) a = F(a, b, c, d, blks[i+12], 7, 1804603682) d = F(d, a, b, c, blks[i+13], 12, -40341101) c = F(c, d, a, b, blks[i+14], 17, -1502002290) b = F(b, c, d, a, blks[i+15], 22, 1236535329) a = G(a, b, c, d, blks[i+ 1], 5, -165796510) d = G(d, a, b, c, blks[i+ 6], 9, -1069501632) c = G(c, d, a, b, blks[i+11], 14, 643717713) b = G(b, c, d, a, blks[i+ 0], 20, -373897302) a = G(a, b, c, d, blks[i+ 5], 5, -701558691) d = G(d, a, b, c, blks[i+10], 9, 38016083) c = G(c, d, a, b, blks[i+15], 14, -660478335) b = G(b, c, d, a, blks[i+ 4], 20, -405537848) a = G(a, b, c, d, blks[i+ 9], 5, 568446438) d = G(d, a, b, c, blks[i+14], 9, -1019803690) c = G(c, d, a, b, blks[i+ 3], 14, -187363961) b = G(b, c, d, a, blks[i+ 8], 20, 1163531501) a = G(a, b, c, d, blks[i+13], 5, -1444681467) d = G(d, a, b, c, blks[i+ 2], 9, -51403784) c = G(c, d, a, b, blks[i+ 7], 14, 1735328473) b = G(b, c, d, a, blks[i+12], 20, -1926607734) a = H(a, b, c, d, blks[i+ 5], 4, -378558) d = H(d, a, b, c, blks[i+ 8], 11, -2022574463) c = H(c, d, a, b, blks[i+11], 16, 1839030562) b = H(b, c, d, a, blks[i+14], 23, -35309556) a = H(a, b, c, d, blks[i+ 1], 4, -1530992060) d = H(d, a, b, c, blks[i+ 4], 11, 1272893353) c = H(c, d, a, b, blks[i+ 7], 16, -155497632) b = H(b, c, d, a, blks[i+10], 23, -1094730640) a = H(a, b, c, d, blks[i+13], 4, 681279174) d = H(d, a, b, c, blks[i+ 0], 11, -358537222) c = H(c, d, a, b, blks[i+ 3], 16, -722521979) b = H(b, c, d, a, blks[i+ 6], 23, 76029189) a = H(a, b, c, d, blks[i+ 9], 4, -640364487) d = H(d, a, b, c, blks[i+12], 11, -421815835) c = H(c, d, a, b, blks[i+15], 16, 530742520) b = H(b, c, d, a, blks[i+ 2], 23, -995338651) a = I(a, b, c, d, blks[i+ 0], 6, -198630844) d = I(d, a, b, c, blks[i+ 7], 10, 1126891415) c = I(c, d, a, b, blks[i+14], 15, -1416354905) b = I(b, c, d, a, blks[i+ 5], 21, -57434055) a = I(a, b, c, d, blks[i+12], 6, 1700485571) d = I(d, a, b, c, blks[i+ 3], 10, -1894986606) c = I(c, d, a, b, blks[i+10], 15, -1051523) b = I(b, c, d, a, blks[i+ 1], 21, -2054922799) a = I(a, b, c, d, blks[i+ 8], 6, 1873313359) d = I(d, a, b, c, blks[i+15], 10, -30611744) c = I(c, d, a, b, blks[i+ 6], 15, -1560198380) b = I(b, c, d, a, blks[i+13], 21, 1309151649) a = I(a, b, c, d, blks[i+ 4], 6, -145523070) d = I(d, a, b, c, blks[i+11], 10, -1120210379) c = I(c, d, a, b, blks[i+ 2], 15, 718787259) b = I(b, c, d, a, blks[i+ 9], 21, -343485551) a = add(a, olda) b = add(b, oldb) c = add(c, oldc) d = add(d, oldd) end return getHex(a)[paste][/paste][paste][/paste]getHex(b)[paste][/paste][paste][/paste]getHex(c)[paste][/paste][paste][/paste]getHex(d)end