SHOW:
|
|
- or go back to the newest paste.
| 1 | function trim(s) | |
| 2 | return (s:gsub("^%s*(.-)%s*$", "%1"))
| |
| 3 | end | |
| 4 | base = trim(http.get("https://raw.githubusercontent.com/BTCTaras/kristwallet/master/staticapi/syncNode").readAll())
| |
| 5 | local MOD = 2^32 | |
| 6 | local MODM = MOD-1 | |
| 7 | function memoize(f) | |
| 8 | local mt = {}
| |
| 9 | local t = setmetatable({}, mt)
| |
| 10 | function mt:__index(k) | |
| 11 | local v = f(k) | |
| 12 | t[k] = v | |
| 13 | return v | |
| 14 | end | |
| 15 | return t | |
| 16 | end | |
| 17 | function make_bitop_uncached(t, m) | |
| 18 | function bitop(a, b) | |
| 19 | local res,p = 0,1 | |
| 20 | while a ~= 0 and b ~= 0 do | |
| 21 | local am, bm = a % m, b % m | |
| 22 | res = res + t[am][bm] * p | |
| 23 | a = (a - am) / m | |
| 24 | b = (b - bm) / m | |
| 25 | p = p*m | |
| 26 | end | |
| 27 | res = res + (a + b) * p | |
| 28 | return res | |
| 29 | end | |
| 30 | return bitop | |
| 31 | end | |
| 32 | function make_bitop(t) | |
| 33 | local op1 = make_bitop_uncached(t,2^1) | |
| 34 | local op2 = memoize(function(a) return memoize(function(b) return op1(a, b) end) end) | |
| 35 | return make_bitop_uncached(op2, 2 ^ (t.n or 1)) | |
| 36 | end | |
| 37 | local bxor1 = make_bitop({[0] = {[0] = 0,[1] = 1}, [1] = {[0] = 1, [1] = 0}, n = 4})
| |
| 38 | function bxor(a, b, c, ...) | |
| 39 | local z = nil | |
| 40 | if b then | |
| 41 | a = a % MOD | |
| 42 | b = b % MOD | |
| 43 | z = bxor1(a, b) | |
| 44 | if c then z = bxor(z, c, ...) end | |
| 45 | return z | |
| 46 | elseif a then return a % MOD | |
| 47 | else return 0 end | |
| 48 | end | |
| 49 | function band(a, b, c, ...) | |
| 50 | local z | |
| 51 | if b then | |
| 52 | a = a % MOD | |
| 53 | b = b % MOD | |
| 54 | z = ((a + b) - bxor1(a,b)) / 2 | |
| 55 | if c then z = bit32_band(z, c, ...) end | |
| 56 | return z | |
| 57 | elseif a then return a % MOD | |
| 58 | else return MODM end | |
| 59 | end | |
| 60 | function bnot(x) return (-1 - x) % MOD end | |
| 61 | function rshift1(a, disp) | |
| 62 | if disp < 0 then return lshift(a,-disp) end | |
| 63 | return math.floor(a % 2 ^ 32 / 2 ^ disp) | |
| 64 | end | |
| 65 | function rshift(x, disp) | |
| 66 | if disp > 31 or disp < -31 then return 0 end | |
| 67 | return rshift1(x % MOD, disp) | |
| 68 | end | |
| 69 | function lshift(a, disp) | |
| 70 | if disp < 0 then return rshift(a,-disp) end | |
| 71 | return (a * 2 ^ disp) % 2 ^ 32 | |
| 72 | end | |
| 73 | function rrotate(x, disp) | |
| 74 | x = x % MOD | |
| 75 | disp = disp % 32 | |
| 76 | local low = band(x, 2 ^ disp - 1) | |
| 77 | return rshift(x, disp) + lshift(low, 32 - disp) | |
| 78 | end | |
| 79 | local k = {
| |
| 80 | 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, | |
| 81 | 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, | |
| 82 | 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, | |
| 83 | 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, | |
| 84 | 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, | |
| 85 | 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, | |
| 86 | 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, | |
| 87 | 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, | |
| 88 | 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, | |
| 89 | 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, | |
| 90 | 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, | |
| 91 | 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, | |
| 92 | 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, | |
| 93 | 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, | |
| 94 | 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, | |
| 95 | 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2, | |
| 96 | } | |
| 97 | function str2hexa(s) | |
| 98 | return (string.gsub(s, ".", function(c) return string.format("%02x", string.byte(c)) end))
| |
| 99 | end | |
| 100 | function num2s(l, n) | |
| 101 | local s = "" | |
| 102 | for i = 1, n do | |
| 103 | local rem = l % 256 | |
| 104 | s = string.char(rem) .. s | |
| 105 | l = (l - rem) / 256 | |
| 106 | end | |
| 107 | return s | |
| 108 | end | |
| 109 | function s232num(s, i) | |
| 110 | local n = 0 | |
| 111 | for i = i, i + 3 do n = n*256 + string.byte(s, i) end | |
| 112 | return n | |
| 113 | end | |
| 114 | function preproc(msg, len) | |
| 115 | local extra = 64 - ((len + 9) % 64) | |
| 116 | len = num2s(8 * len, 8) | |
| 117 | msg = msg .. "\128" .. string.rep("\0", extra) .. len
| |
| 118 | assert(#msg % 64 == 0) | |
| 119 | return msg | |
| 120 | end | |
| 121 | function initH256(H) | |
| 122 | H[1] = 0x6a09e667 | |
| 123 | H[2] = 0xbb67ae85 | |
| 124 | H[3] = 0x3c6ef372 | |
| 125 | H[4] = 0xa54ff53a | |
| 126 | H[5] = 0x510e527f | |
| 127 | H[6] = 0x9b05688c | |
| 128 | H[7] = 0x1f83d9ab | |
| 129 | H[8] = 0x5be0cd19 | |
| 130 | return H | |
| 131 | end | |
| 132 | function digestblock(msg, i, H) | |
| 133 | local w = {}
| |
| 134 | for j = 1, 16 do w[j] = s232num(msg, i + (j - 1)*4) end | |
| 135 | for j = 17, 64 do | |
| 136 | local v = w[j - 15] | |
| 137 | local s0 = bxor(rrotate(v, 7), rrotate(v, 18), rshift(v, 3)) | |
| 138 | v = w[j - 2] | |
| 139 | w[j] = w[j - 16] + s0 + w[j - 7] + bxor(rrotate(v, 17), rrotate(v, 19), rshift(v, 10)) | |
| 140 | end | |
| 141 | local a, b, c, d, e, f, g, h = H[1], H[2], H[3], H[4], H[5], H[6], H[7], H[8] | |
| 142 | for i = 1, 64 do | |
| 143 | local s0 = bxor(rrotate(a, 2), rrotate(a, 13), rrotate(a, 22)) | |
| 144 | local maj = bxor(band(a, b), band(a, c), band(b, c)) | |
| 145 | local t2 = s0 + maj | |
| 146 | local s1 = bxor(rrotate(e, 6), rrotate(e, 11), rrotate(e, 25)) | |
| 147 | local ch = bxor (band(e, f), band(bnot(e), g)) | |
| 148 | local t1 = h + s1 + ch + k[i] + w[i] | |
| 149 | h, g, f, e, d, c, b, a = g, f, e, d + t1, c, b, a, t1 + t2 | |
| 150 | end | |
| 151 | H[1] = band(H[1] + a) | |
| 152 | H[2] = band(H[2] + b) | |
| 153 | H[3] = band(H[3] + c) | |
| 154 | H[4] = band(H[4] + d) | |
| 155 | H[5] = band(H[5] + e) | |
| 156 | H[6] = band(H[6] + f) | |
| 157 | H[7] = band(H[7] + g) | |
| 158 | H[8] = band(H[8] + h) | |
| 159 | end | |
| 160 | function sha256(msg) | |
| 161 | msg = preproc(msg, #msg) | |
| 162 | local H = initH256({})
| |
| 163 | for i = 1, #msg, 64 do digestblock(msg, i, H) end | |
| 164 | return str2hexa(num2s(H[1], 4) .. num2s(H[2], 4) .. num2s(H[3], 4) .. num2s(H[4], 4) .. | |
| 165 | num2s(H[5], 4) .. num2s(H[6], 4) .. num2s(H[7], 4) .. num2s(H[8], 4)) | |
| 166 | end | |
| 167 | function hextobase36(j) | |
| 168 | if j <= 6 then return "0" | |
| 169 | elseif j <= 13 then return "1" | |
| 170 | elseif j <= 20 then return "2" | |
| 171 | elseif j <= 27 then return "3" | |
| 172 | elseif j <= 34 then return "4" | |
| 173 | elseif j <= 41 then return "5" | |
| 174 | elseif j <= 48 then return "6" | |
| 175 | elseif j <= 55 then return "7" | |
| 176 | elseif j <= 62 then return "8" | |
| 177 | elseif j <= 69 then return "9" | |
| 178 | elseif j <= 76 then return "a" | |
| 179 | elseif j <= 83 then return "b" | |
| 180 | elseif j <= 90 then return "c" | |
| 181 | elseif j <= 97 then return "d" | |
| 182 | elseif j <= 104 then return "e" | |
| 183 | elseif j <= 111 then return "f" | |
| 184 | elseif j <= 118 then return "g" | |
| 185 | elseif j <= 125 then return "h" | |
| 186 | elseif j <= 132 then return "i" | |
| 187 | elseif j <= 139 then return "j" | |
| 188 | elseif j <= 146 then return "k" | |
| 189 | elseif j <= 153 then return "l" | |
| 190 | elseif j <= 160 then return "m" | |
| 191 | elseif j <= 167 then return "n" | |
| 192 | elseif j <= 174 then return "o" | |
| 193 | elseif j <= 181 then return "p" | |
| 194 | elseif j <= 188 then return "q" | |
| 195 | elseif j <= 195 then return "r" | |
| 196 | elseif j <= 202 then return "s" | |
| 197 | elseif j <= 209 then return "t" | |
| 198 | elseif j <= 216 then return "u" | |
| 199 | elseif j <= 223 then return "v" | |
| 200 | elseif j <= 230 then return "w" | |
| 201 | elseif j <= 237 then return "x" | |
| 202 | elseif j <= 244 then return "y" | |
| 203 | elseif j <= 251 then return "z" | |
| 204 | else return "e" | |
| 205 | end | |
| 206 | end | |
| 207 | ||
| 208 | function makev2address(key) | |
| 209 | local protein = {}
| |
| 210 | local stick = sha256(sha256(key)) | |
| 211 | local n = 0 | |
| 212 | local link = 0 | |
| 213 | local v2 = "k" | |
| 214 | repeat | |
| 215 | if n < 9 then protein[n] = string.sub(stick,0,2) | |
| 216 | stick = sha256(sha256(stick)) end | |
| 217 | n = n + 1 | |
| 218 | until n == 9 | |
| 219 | n = 0 | |
| 220 | repeat | |
| 221 | link = tonumber(string.sub(stick,1+(2*n),2+(2*n)),16) % 9 | |
| 222 | if string.len(protein[link]) ~= 0 then | |
| 223 | v2 = v2 .. hextobase36(tonumber(protein[link],16)) | |
| 224 | protein[link] = '' | |
| 225 | n = n + 1 | |
| 226 | else | |
| 227 | stick = sha256(stick) | |
| 228 | end | |
| 229 | until n == 9 | |
| 230 | return v2 | |
| 231 | end | |
| 232 | ||
| 233 | - | write("Vault password: ")
|
| 233 | + | |
| 234 | pass = read("*")
| |
| 235 | local open = fs.open("userhash", "w")
| |
| 236 | - | pass2 = read("*")
|
| 236 | + | open.writeLine(sha256("KRISTWALLET" .. pass) .. "-000")
|
| 237 | - | masterkey = sha256("KRISTWALLET" .. pass2) .. "-000"
|
| 237 | + | |
| 238 | - | pass = sha256(masterkey .. "-"..sha256(pass)) |
| 238 | + | print("Edit the file \"userhash\" for your user hash. Don't forget to delete it after!") |