jxnczyp的专栏

–本功能依赖于本博客Lua基本库另一篇文章,,ZZMathBitZZRc4 = {}function ZZRc4.encrypt(text,key)local function KSA(key)local keyLen = string.len(key)local schedule = {}local keyByte = {}for i = 0, 255 doschedule[i] = iendfor i = 1, keyLen dokeyByte[i – 1] = string.byte(key, i, i)endlocal j = 0for i = 0, 255 doj = (j + schedule[i] + keyByte[ i % keyLen]) % 256schedule[i], schedule[j] = schedule[j], schedule[i]endreturn scheduleendlocal function PRGA(schedule, textLen)local i = 0local j = 0local k = {}for n = 1, textLen doi = (i + 1) % 256j = (j + schedule[i]) % 256schedule[i], schedule[j] = schedule[j], schedule[i]k[n] = schedule[(schedule[i] + schedule[j]) % 256]endreturn kendlocal function output(schedule, text)local len = string.len(text)local c = nillocal res = {}for i = 1, len doc = string.byte(text, i,i)res[i] = string.char(ZZMathBit.xorOp(schedule[i], c))endreturn table.concat(res)endlocal textLen = string.len(text)local schedule = KSA(key)local k = PRGA(schedule, textLen)return output(k, text)endfunction ZZRc4.test()require("math/ZZMathBit")local encrypt = ZZRc4.encrypt("abcde1235","zyp")print(string.len(encrypt))local decrypt = ZZRc4.encrypt(encrypt, "zyp")print(decrypt)endZZRc4.test()

一个有信念者所开发出的力量,大于99个只有兴趣者。

jxnczyp的专栏

相关文章:

你感兴趣的文章:

标签云: