aboutsummaryrefslogtreecommitdiffstats
path: root/lclipd.lua
diff options
context:
space:
mode:
authorterminaldweller <thabogre@gmail.com>2023-02-26 11:58:05 +0000
committerterminaldweller <thabogre@gmail.com>2023-02-26 11:58:05 +0000
commit977a49f20568d00ee4bb8b79e6fd34a6f8c22ec9 (patch)
tree4501099382d72d06f4f9b09b732a45930e777596 /lclipd.lua
parentwip (diff)
downloadlclip-977a49f20568d00ee4bb8b79e6fd34a6f8c22ec9.tar.gz
lclip-977a49f20568d00ee4bb8b79e6fd34a6f8c22ec9.zip
added a metric entropy function, working on a way to automatically exclude passwords, wip
Diffstat (limited to '')
-rwxr-xr-xlclipd.lua27
1 files changed, 25 insertions, 2 deletions
diff --git a/lclipd.lua b/lclipd.lua
index 3c76696..2579d38 100755
--- a/lclipd.lua
+++ b/lclipd.lua
@@ -83,6 +83,28 @@ insert into lclipd(content,dateAdded) values('XXX', unixepoch());
local pid_file = "/tmp/lclipd.pid"
local db_file_name = "/tmp/lclipd_db_name"
+--- Calculates metric entropy for a string
+local function get_string_metric_entropy(str)
+ local map = {}
+ for i = 1, #str do
+ if map[str:sub(i, i)] ~= nil then
+ map[str:sub(i, i)] = map[str:sub(i, i)] + 1
+ else
+ map[str:sub(i, i)] = 1
+ end
+ end
+
+ for k, v in pairs(map) do map[k] = v / #str end
+
+ local entropy = 0
+
+ for _, v in pairs(map) do
+ entropy = entropy + v * (math.log(v) / math.log(2))
+ end
+
+ return -entropy / #str
+end
+
--- A sleep function
local function sleep(n) os.execute("sleep " .. tonumber(n)) end
@@ -162,12 +184,13 @@ local function get_clipboard_content()
log_to_syslog(errmsg, posix_syslog.LOG_CRIT)
lclip_exit(1)
elseif pid == 0 then -- child
- -- clipnotify exits when there is a new entry on the clipboard
- -- so we do want a blocking call here
os.execute("clipnotify")
os.exit(0)
else -- parent
+ -- clipnotify exits when there is a new entry on the clipboard
+ -- so we do want a blocking call here
posix_wait.wait(pid)
+
-- we dont care whether all the calls to the different clipboard apps
-- succeed or not so we just ignore the errors.
local _, handle_x = pcall(io.popen, "xsel -ob")