Alyssa

ccBank

Aug 14th, 2014
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 16.16 KB | None | 0 0
  1. local nify = { "0", "1","2","3","4","5","6","7","8","9","a","b","c","d","e","f" }
  2. local AAAAAAAA = print
  3. local AAAAAAA = string.sub
  4. local AAAAAAAAA = write
  5. local BBBBBB = string.len
  6. local BBBBBBB = term.setCursorPos
  7. local BBBBB = math.floor
  8. local CCCCC = os.pullEvent
  9. local CCCCCC = os.time
  10. local CCCC = os.day
  11. local DDDD = time
  12. local DDD = day
  13. local CCC = hashpass
  14. if not colors then
  15. colors.grey = colors.white
  16. colors.lightGrey = colors.white
  17. colors.red = colors.white
  18. end
  19.  
  20. function hm()
  21.    AAAAAAAA("How much?:                                         ")
  22. end
  23. function upconfirmp()
  24.   BBBBBBB(1,7)
  25.   AAAAAAAA("Username:                                          ")
  26.   BBBBBBB(1,9)
  27.   AAAAAAAA("Password:                                          ")
  28.   BBBBBBB(1,11)
  29.   AAAAAAAA("Confirm Password:                                  ")
  30. end
  31. function uandp()
  32.   BBBBBBB(1,7)
  33.   AAAAAAAA("Username:                                          ")
  34.   BBBBBBB(1,9)
  35.   AAAAAAAA("Password:                                          ")
  36. end
  37. function landn()
  38. cAAAAAAAAA("LOGIN     NEW")
  39. end
  40. function logscr()
  41.   cAAAAAAAAA("  L   OOO   GGGG IIIII N   N",1)
  42.   cAAAAAAAAA("  L  O   O G       I   NN  N",2)
  43.   cAAAAAAAAA("  L  O   O G  GG   I   N N N",3)
  44.   cAAAAAAAAA("  L  O   O G   G   I   N  NN",4)
  45.   cAAAAAAAAA("  LLL OOO   GGG  IIIII N   N",5)
  46. end
  47. function bw()
  48. BBBBBBB(1,2)
  49. term.setTextColor(colors.gray)
  50. cAAAAAAAAA("BBBB   AAA  N   N K  K")
  51. BBBBBBB(1,3)
  52. cAAAAAAAAA("B   B A   A NN  N K K ")
  53. BBBBBBB(1,4)
  54. cAAAAAAAAA("BBBB  AAAAA N N N KK  ")
  55. BBBBBBB(1,5)
  56. cAAAAAAAAA("B   B A   A N  NN K K ")
  57. BBBBBBB(1,6)
  58. cAAAAAAAAA("BBBB  A   A N   N K  K")
  59. end
  60.  
  61. local function code(key, BBBB, mode)
  62.  key = tostring(key)
  63.  BBBB = tostring(BBBB)
  64.  local kn = 1
  65.  local nBBBB = ""
  66.  for i = 1, #BBBB do
  67.   cc = AAAAAAA(BBBB, i, i)
  68.   for b = 1, 16 do
  69.    if cc == nify[b] then
  70.     ccn = b
  71.    end
  72.   end
  73.   for c = 1, 16 do
  74.    if AAAAAAA(key, kn, kn) == nify[c] then
  75.     knn = c
  76.    end
  77.   end
  78.   if mode == "AAAAAAAAAA" then
  79.    ccn = ccn + knn
  80.   elseif mode == "AAAAAAAAAAA" then
  81.    ccn = ccn - knn
  82.   end
  83.   if ccn >= 17 then
  84.    ccn = ccn - 16
  85.   end
  86.   if ccn <= 0 then
  87.    ccn = ccn + 16
  88.   end
  89.   nBBBB = nBBBB..nify[ccn]
  90.   if kn == #key then
  91.    kn = 1
  92.   else
  93.    kn = kn +1
  94.   end
  95.  end
  96.  return nBBBB
  97. end
  98.  
  99. function AAAAAAAAAAA(key, BBBB)
  100.  local tr = code(key, BBBB, "AAAAAAAAAAA")
  101.  return tr
  102. end
  103.  
  104. function AAAAAAAAAA(key, BBBB)
  105.  local tr = code(key, BBBB, "AAAAAAAAAA")
  106.  return tr
  107. end
  108.  
  109. local MOD = 2^32
  110. local MODM = MOD-1
  111.  
  112. local function memoize(f)
  113.         local mt = {}
  114.         local t = setmetatable({}, mt)
  115.         function mt:__index(k)
  116.                 local v = f(k)
  117.                 t[k] = v
  118.                 return v
  119.         end
  120.         return t
  121. end
  122.  
  123.  
  124. local function make_bitop_uncached(t, m)
  125.         local function bitop(a, b)
  126.                 local res,p = 0,1
  127.                 while a ~= 0 and b ~= 0 do
  128.                         local am, bm = a % m, b % m
  129.                         res = res + t[am][bm] * p
  130.                         a = (a - am) / m
  131.                         b = (b - bm) / m
  132.                         p = p*m
  133.                 end
  134.                 res = res + (a + b) * p
  135.                 return res
  136.         end
  137.         return bitop
  138. end
  139.  
  140. local function make_bitop(t)
  141.         local op1 = make_bitop_uncached(t,2^1)
  142.         local op2 = memoize(function(a) return memoize(function(b) return op1(a, b) end) end)
  143.         return make_bitop_uncached(op2, 2 ^ (t.n or 1))
  144. end
  145.  
  146. local bxor1 = make_bitop({[0] = {[0] = 0,[1] = 1}, [1] = {[0] = 1, [1] = 0}, n = 4})
  147.  
  148. local function bxor(a, b, c, ...)
  149.         local z = nil
  150.         if b then
  151.                 a = a % MOD
  152.                 b = b % MOD
  153.                 z = bxor1(a, b)
  154.                 if c then z = bxor(z, c, ...) end
  155.                 return z
  156.         elseif a then return a % MOD
  157.         else return 0 end
  158. end
  159.  
  160. local function band(a, b, c, ...)
  161.         local z
  162.         if b then
  163.                 a = a % MOD
  164.                 b = b % MOD
  165.                 z = ((a + b) - bxor1(a,b)) / 2
  166.                 if c then z = bit32_band(z, c, ...) end
  167.                 return z
  168.         elseif a then return a % MOD
  169.         else return MODM end
  170. end
  171.  
  172. local function bnot(x) return (-1 - x) % MOD end
  173.  
  174. local function rshift1(a, disp)
  175.         if disp < 0 then return lshift(a,-disp) end
  176.         return BBBBB(a % 2 ^ 32 / 2 ^ disp)
  177. end
  178.  
  179. local function rshift(x, disp)
  180.         if disp > 31 or disp < -31 then return 0 end
  181.         return rshift1(x % MOD, disp)
  182. end
  183.  
  184. local function lshift(a, disp)
  185.         if disp < 0 then return rshift(a,-disp) end
  186.         return (a * 2 ^ disp) % 2 ^ 32
  187. end
  188.  
  189. local function rrotate(x, disp)
  190.     x = x % MOD
  191.     disp = disp % 32
  192.     local low = band(x, 2 ^ disp - 1)
  193.     return rshift(x, disp) + lshift(low, 32 - disp)
  194. end
  195.  
  196. local k = {
  197.         0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  198.         0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  199.         0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  200.         0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  201.         0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  202.         0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  203.         0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  204.         0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  205.         0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  206.         0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  207.         0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  208.         0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  209.         0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  210.         0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  211.         0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  212.         0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
  213. }
  214.  
  215. local function str2hexa(s)
  216.         return (string.gsub(s, ".", function(c) return string.format("%02x", string.byte(c)) end))
  217. end
  218.  
  219. local function num2s(l, n)
  220.         local s = ""
  221.         for i = 1, n do
  222.                 local rem = l % 256
  223.                 s = string.char(rem) .. s
  224.                 l = (l - rem) / 256
  225.         end
  226.         return s
  227. end
  228.  
  229. local function s232num(s, i)
  230.         local n = 0
  231.         for i = i, i + 3 do n = n*256 + string.byte(s, i) end
  232.         return n
  233. end
  234.  
  235. local function preproc(BBBB, len)
  236.         local extra = 64 - ((len + 9) % 64)
  237.         len = num2s(8 * len, 8)
  238.         BBBB = BBBB .. "\128" .. string.rep("\0", extra) .. len
  239.         assert(#BBBB % 64 == 0)
  240.         return BBBB
  241. end
  242.  
  243. local function initH256(H)
  244.         H[1] = 0x6a09e667
  245.         H[2] = 0xbb67ae85
  246.         H[3] = 0x3c6ef372
  247.         H[4] = 0xa54ff53a
  248.         H[5] = 0x510e527f
  249.         H[6] = 0x9b05688c
  250.         H[7] = 0x1f83d9ab
  251.         H[8] = 0x5be0cd19
  252.         return H
  253. end
  254.  
  255. local function digestblock(BBBB, i, H)
  256.         local w = {}
  257.         for j = 1, 16 do w[j] = s232num(BBBB, i + (j - 1)*4) end
  258.         for j = 17, 64 do
  259.                 local v = w[j - 15]
  260.                 local s0 = bxor(rrotate(v, 7), rrotate(v, 18), rshift(v, 3))
  261.                 v = w[j - 2]
  262.                 w[j] = w[j - 16] + s0 + w[j - 7] + bxor(rrotate(v, 17), rrotate(v, 19), rshift(v, 10))
  263.         end
  264.  
  265.         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]
  266.         for i = 1, 64 do
  267.                 local s0 = bxor(rrotate(a, 2), rrotate(a, 13), rrotate(a, 22))
  268.                 local maj = bxor(band(a, b), band(a, c), band(b, c))
  269.                 local t2 = s0 + maj
  270.                 local s1 = bxor(rrotate(e, 6), rrotate(e, 11), rrotate(e, 25))
  271.                 local ch = bxor (band(e, f), band(bnot(e), g))
  272.                 local t1 = h + s1 + ch + k[i] + w[i]
  273.                 h, g, f, e, d, c, b, a = g, f, e, d + t1, c, b, a, t1 + t2
  274.         end
  275.  
  276.         H[1] = band(H[1] + a)
  277.         H[2] = band(H[2] + b)
  278.         H[3] = band(H[3] + c)
  279.         H[4] = band(H[4] + d)
  280.         H[5] = band(H[5] + e)
  281.         H[6] = band(H[6] + f)
  282.         H[7] = band(H[7] + g)
  283.         H[8] = band(H[8] + h)
  284. end
  285.  
  286. local function sha256(BBBB)
  287.         BBBB = preproc(BBBB, #BBBB)
  288.         local H = initH256({})
  289.         for i = 1, #BBBB, 64 do digestblock(BBBB, i, H) end
  290.         return str2hexa(num2s(H[1], 4) .. num2s(H[2], 4) .. num2s(H[3], 4) .. num2s(H[4], 4) ..
  291.                 num2s(H[5], 4) .. num2s(H[6], 4) .. num2s(H[7], 4) .. num2s(H[8], 4))
  292. end
  293. function displayBalance()
  294. term.setBackgroundColor(colors.white)
  295. BBBBBBB(1,16)
  296. AAAAAAAAA("                                                  ")
  297. BBBBBBB(1,17)
  298. clearbal = ""
  299. for i = 1, #tostring(oldb) do
  300. clearbal = clearbal.." "
  301. end
  302. cAAAAAAAAA("   "..clearbal.."  ")
  303. term.setBackgroundColor(colors.lightGray)
  304. BBBBBBB(1,17)
  305. cAAAAAAAAA("$"..balance)
  306. end
  307.  
  308. screenx, screeny = term.getSize()
  309. function cAAAAAAAAA(text,ytwa)
  310.             if not ytwa then
  311.                       unusedx,ytwa = term.getCursorPos()
  312.             end
  313.             local len = BBBBBB(text)
  314.             local sxtw = screenx /2
  315.             local len = len /2
  316.             local sxtw = sxtw - len
  317.             BBBBBBB(sxtw,ytwa)
  318.             AAAAAAAAA(text)
  319. end
  320.  
  321. function pay(userto, confirmpass, tsamount,userfrom)
  322.  if tsamount >= 1 then
  323.   DDDD = CCCCCC()
  324.   DDDD = DDDD +5
  325.   DDD = CCCC()
  326.   S3 = DDDD *DDD
  327.   S3b = S3 *4.4
  328.   S3b = BBBBB(S3b)
  329.   S3c = S3 *7.3
  330.   S3c = BBBBB(S3c)
  331.   CCC = sha256(confirmpass)
  332.   CCC = AAAAAAAAAA(S3c, CCC)
  333.   CCC = CCC .. " " .. S3b
  334.   UID = math.random(1,65535)
  335.   userto = string.lower(userto)
  336.   AAAAA(sChan, UID, "Pay "..userto.." "..tsamount.." "..CCC.." "..userfrom)
  337.   rr = 0
  338.   while rr == 0 do
  339.    event, side, fromchan, replychan, BBBB, distance = CCCCC("modem_message")
  340.    if fromchan == sChan and replychan == UID then
  341.     if BBBB == "Pay Success" then
  342.      rr = 1
  343.      return true
  344.     else
  345.      rr = 1
  346.      return false
  347.     end
  348.    end
  349.   end
  350.  else
  351.   return false
  352.  end
  353. end
  354.  
  355. oldb = 0
  356. function getBalance(usergb)
  357.  UID = math.random(1,65535)
  358.  usergb = string.lower(usergb)
  359.  AAAAA(sChan, UID, "Get Balance "..usergb)
  360. receivedreply = 0
  361.  while receivedreply == 0 do
  362.   event, side, fromchan, replychan, BBBB, distance = CCCCC("modem_message")
  363.   if fromchan == sChan and replychan == UID then
  364.    if oldb ~= nil then
  365.     oldb = balance
  366.    end
  367.    balance = BBBB
  368.    receivedreply = 1
  369.    return balance
  370.   end
  371.  end
  372.  
  373. end
  374. function tryLogin(usere,passe)
  375.  usere = string.lower(usere)
  376.  DDDD = CCCCCC()
  377.  DDDD = DDDD +5
  378.  DDD = CCCC()
  379.  S1 = DDDD *DDD
  380.    S1b = S1 *3.8
  381.   S1b = BBBBB(S1b)
  382.   S1c = S1 *3.1
  383.   S1c = BBBBB(S1c)
  384.   S1 = S1b
  385.  passts = sha256(passe)
  386.  passts = AAAAAAAAAA(S1c, passts)
  387.  passts = passts .. " " .. S1
  388.  UID = math.random(1,65535)
  389.  AAAAA(sChan, UID, "Login "..usere .. " "..passts)
  390.  rr = 0
  391.  while rr == 0 do
  392.   event, side, fromchan, replychan, BBBB, distance = CCCCC("modem_message")
  393.   if fromchan == sChan and replychan == UID then
  394.    if BBBB == "Login Correct" then
  395.     return true
  396.    else
  397.     return false
  398.    end
  399.    rr = 1
  400.   end
  401.  end
  402.  
  403.  
  404. end
  405.  
  406. function start()
  407. sChan = 16742
  408. foundside = 0
  409. if foundside == 0 then
  410. if peripheral.isPresent("top") and peripheral.getType("top") == "modem" then
  411. modem = peripheral.wrap("top")
  412. end
  413. end
  414. if foundside == 0 then
  415. if peripheral.isPresent("bottom") and peripheral.getType("bottom") == "modem" then
  416. modem = peripheral.wrap("bottom")
  417. end
  418. end
  419. if foundside == 0 then
  420. if peripheral.isPresent("front") and peripheral.getType("front") == "modem" then
  421. modem = peripheral.wrap("front")
  422. end
  423. end
  424. if foundside == 0 then
  425. if peripheral.isPresent("back") and peripheral.getType("back") == "modem" then
  426. modem = peripheral.wrap("back")
  427. end
  428. end
  429. if foundside == 0 then
  430. if peripheral.isPresent("left") and peripheral.getType("left") == "modem" then
  431. modem = peripheral.wrap("left")
  432. end
  433. end
  434. if foundside == 0 then
  435. if peripheral.isPresent("right") and peripheral.getType("right") == "modem" then
  436. modem = peripheral.wrap("right")
  437. end
  438. end
  439. modem.open(sChan)
  440. AAAAA = modem.transmit
  441. term.setBackgroundColor(colors.white)
  442. term.clear()
  443. bw()
  444. BBBBBBB(1,7)
  445. term.setBackgroundColor(colors.lightGray)
  446. term.setTextColor(colors.black)
  447. landn()
  448. end
  449.  
  450. function login(user,balance)
  451. user = string.lower(user)
  452. term.setBackgroundColor(colors.white)
  453. term.clear()
  454. BBBBBBB(1,1)
  455. AAAAAAAA("Hello, "..user..". You have $"..balance.." in your account.")
  456. term.setBackgroundColor(colors.lightGray)
  457. BBBBBBB(2,4)
  458. AAAAAAAA("New Offer")
  459. BBBBBBB(screenx -6 ,4)
  460. AAAAAAAA(" Offers ")
  461. BBBBBBB(screenx - 9,6)
  462. AAAAAAAA(" Pay Money")
  463. BBBBBBB(3,6)
  464. AAAAAAAA("Update Balance")
  465. displayBalance()
  466. BBBBBBB(1,screeny)
  467. term.setBackgroundColor(colors.red)
  468. AAAAAAAA("EXIT")
  469. while true do
  470. local event, button, xPos, yPos = CCCCC("mouse_click")
  471.   if xPos > 2 and xPos < 12 and yPos == 3 then
  472.    BBBBBBB(1,5)
  473.   hm()
  474.   BBBBBBB(12,5)
  475.   wda = read()
  476.   set = wda - balance
  477.   if set < 0 then
  478.     AAAAAAAA("Error: You don't have that much money!")
  479.     sleep(3)
  480.     login(user, balance)
  481.   else
  482.     login(user, balance)
  483.     end
  484.   elseif xPos > 2 and xPos < 17 and yPos == 5 then
  485.    balance = getBalance(user)
  486.    displayBalance()
  487.   elseif xPos > screenx - 10 and xPos < screenx + 1 and yPos == 5 then
  488.     BBBBBBB(1,7)
  489.     AAAAAAAAA("Please enter password: ")
  490.     pass = read("*")
  491.     BBBBBBB(1,8)
  492.     AAAAAAAAA("Enter amount to send: ")
  493.     amount = read()
  494.     amount = tonumber(amount)
  495.     BBBBBBB(1,9)
  496.     AAAAAAAAA("Please enter who to send to: ")
  497.     WTST = read()
  498.     if pay(WTST,pass,amount,user) == true then
  499.      BBBBBBB(1,9)
  500.      AAAAAAAAA("                                   ")
  501.      BBBBBBB(1,8)
  502.      AAAAAAAAA("                                   ")
  503.      BBBBBBB(1,7)
  504.      AAAAAAAAA("                                   ")
  505.      BBBBBBB(1,7)
  506.      AAAAAAAAA("Success!")
  507.     else
  508.      BBBBBBB(1,9)
  509.      AAAAAAAAA("                                   ")
  510.      BBBBBBB(1,8)
  511.      AAAAAAAAA("                                   ")
  512.      BBBBBBB(1,7)
  513.      AAAAAAAAA("                                   ")
  514.      BBBBBBB(1,7)
  515.      AAAAAAAAA("Failure.")
  516.     end
  517.   elseif xPos > 39 and xPos < 48 and yPos == 3 then
  518. --[[    BBBBBBB(1,5)
  519.     AAAAAAAA("Deposit money in slot below")
  520.     -- tell turtle next to slot to draw and count until stop signal is received then tell server to add that balance
  521.     term.setBackgroundColor(colors.lightGray)
  522.     AAAAAAAA("Done")
  523.     local event, button, xPos, yPos = CCCCC("mouse_click")
  524.     if yPos == 6 and xPos < 5 then
  525.     -- retreive amount from server
  526.     end
  527.     login(user, balance) --]]
  528.   elseif xPos < 5 and yPos == screeny then
  529.     start()
  530.   end
  531. end
  532. end
  533.  
  534. start()
  535. while true do
  536.   local event, button, xPos, yPos = CCCCC("mouse_click")
  537.               local len = BBBBBB("LOGIN     NEW")
  538.             local sxtw = screenx /2
  539.             local len = len /2
  540.             local sxtw = sxtw - len
  541.   if xPos > sxtw and xPos < sxtw +4 and yPos == 7 then
  542.   term.setBackgroundColor(colors.white)
  543.   term.clear()
  544.   BBBBBBB(1,1)
  545.   logscr()
  546.   term.setBackgroundColor(colors.lightGray)
  547.   uandp()
  548.   BBBBBBB(11,7)
  549.   user = read()
  550.   BBBBBBB(11,9)
  551.   pass = read("*")
  552.   user = string.lower(user)
  553.   if tryLogin(user,pass) == true then
  554.    login(user,getBalance(user))
  555.   else
  556.    AAAAAAAA("Sorry, Login incorrect, please try again")
  557.   end
  558.   elseif xPos > sxtw + 10 and xPos < sxtw + 12 and yPos == 7 then
  559.   term.setBackgroundColor(colors.white)
  560.   term.clear()
  561.   BBBBBBB(1,1)
  562.   cAAAAAAAAA("REGISTER")
  563.   term.setBackgroundColor(colors.lightGray)
  564.   upconfirmp()
  565.   BBBBBBB(11,7)
  566.   user = read()
  567.   user = string.lower(user)
  568.   BBBBBBB(11,9)
  569.   pass = read("*")
  570.   BBBBBBB(19,11)
  571.   cPass = read("*")
  572.   if pass == cPass then
  573.    hpass = sha256(pass)
  574.    DDDD = CCCCCC()
  575.    DDDD = DDDD +7.5
  576.    DDD = CCCC()
  577.    S2 = DDDD *DDD
  578.    S2b = S2 *1.5
  579.   S2b = BBBBB(S2b)
  580.   S2c = S2 *3.7
  581.   S2c = BBBBB(S2c)
  582.   S2 = BBBBB(S2b)
  583.  
  584.   hpass = AAAAAAAAAA(S2c,hpass)
  585.    hpassts = hpass.. " " ..S2
  586.    UID = math.random(1,65535)
  587.    AAAAA(sChan, UID, "Register "..user .. " "..hpassts)
  588.    rr = 0
  589.    while rr == 0 do
  590.     event, side, fromchan, replychan, BBBB, distance = CCCCC("modem_message")
  591.     if fromchan == sChan and replychan == UID then
  592.      if BBBB == "Registered" then
  593.      AAAAAAAA("Register success!")
  594.     else
  595.      AAAAAAAA("Register did not succeed")
  596.     end
  597.     rr = 1
  598.    end
  599.    end
  600.    start()
  601.   end
  602.   end
  603. end
Add Comment
Please, Sign In to add comment