Last active
August 5, 2022 22:30
-
-
Save Mijyuoon/7d848d0874f2d27bbe09254ab523f3b5 to your computer and use it in GitHub Desktop.
Encryption™
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
me.lorenz = {} | |
me.lorenz.wk = { | |
chi = { | |
"11001110011111110101101111101001110111100", | |
"1010111001010110101101010010110", | |
"01010100011100111101101000011", | |
"00100001011111011000010111", | |
"10111110100000110101100", | |
}; | |
mu = { | |
"0010000111111010101110000100011010011", | |
"0011001110001111000110000011000000101110110100011111111100010", | |
}; | |
psi = { | |
"1111110101111101000011100100110110100100101", | |
"11000000101010010011111011111110100100100100110", | |
"110110011010100100001011011010011101001011000110011", | |
"10100000011011011100100100111100101110100011101100100", | |
"11100111011010000100111010000110011011111000110011010001010", | |
}; | |
} | |
me.lorenz.iv = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} | |
-- χ¹..χ⁵ μ37 μ61 ψ¹..ψ⁵ | |
-- {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} | |
-- χ adj: 1 2 3 4 5 3 1 4 | |
-- ψ adj: 1 2 3 4 5 2 5 1 | |
me.lorenz.iter = function(n,iv,wk) | |
local function wbit(w,i) | |
return w:byte(i+1) > 48 | |
end | |
local count = 0 | |
return function() | |
count = count + 1 | |
if count > n then | |
return nil | |
end | |
local byte = 0 | |
byte = byte ~ (wbit(wk.chi[1], iv[1]) and (1 << 0) or 0) | |
byte = byte ~ (wbit(wk.chi[2], iv[2]) and (1 << 1) or 0) | |
byte = byte ~ (wbit(wk.chi[3], iv[3]) and (1 << 2) or 0) | |
byte = byte ~ (wbit(wk.chi[4], iv[4]) and (1 << 3) or 0) | |
byte = byte ~ (wbit(wk.chi[5], iv[5]) and (1 << 4) or 0) | |
byte = byte ~ (wbit(wk.chi[3], iv[3]) and (1 << 5) or 0) | |
byte = byte ~ (wbit(wk.chi[1], iv[1]) and (1 << 6) or 0) | |
byte = byte ~ (wbit(wk.chi[4], iv[4]) and (1 << 7) or 0) | |
byte = byte ~ (wbit(wk.psi[1], iv[1]) and (1 << 0) or 0) | |
byte = byte ~ (wbit(wk.psi[2], iv[2]) and (1 << 1) or 0) | |
byte = byte ~ (wbit(wk.psi[3], iv[3]) and (1 << 2) or 0) | |
byte = byte ~ (wbit(wk.psi[4], iv[4]) and (1 << 3) or 0) | |
byte = byte ~ (wbit(wk.psi[5], iv[5]) and (1 << 4) or 0) | |
byte = byte ~ (wbit(wk.psi[2], iv[2]) and (1 << 5) or 0) | |
byte = byte ~ (wbit(wk.psi[5], iv[5]) and (1 << 6) or 0) | |
byte = byte ~ (wbit(wk.psi[1], iv[1]) and (1 << 7) or 0) | |
iv[1] = (iv[1] + 1) % #wk.chi[1] | |
iv[2] = (iv[2] + 1) % #wk.chi[2] | |
iv[3] = (iv[3] + 1) % #wk.chi[3] | |
iv[4] = (iv[4] + 1) % #wk.chi[4] | |
iv[5] = (iv[5] + 1) % #wk.chi[5] | |
if wbit(wk.mu[2], iv[7]) then | |
iv[ 8] = (iv[ 8] + 1) % #wk.psi[1] | |
iv[ 9] = (iv[ 9] + 1) % #wk.psi[2] | |
iv[10] = (iv[10] + 1) % #wk.psi[3] | |
iv[11] = (iv[11] + 1) % #wk.psi[4] | |
iv[12] = (iv[12] + 1) % #wk.psi[5] | |
end | |
if wbit(wk.mu[1], iv[6]) then | |
iv[7] = (iv[7] + 1) % #wk.mu[2] | |
end | |
iv[6] = (iv[6] + 1) % #wk.mu[1] | |
return byte, count | |
end | |
end | |
me.lorenz.cipher = function(s,iv,wk) | |
local iter = me.lorenz.iter(#s,iv,wk) | |
s = s:gsub("(.)", | |
function(b) | |
local k = b:byte() ~ (iter()) | |
return string.char(k) | |
end) | |
return s | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment