aboutsummaryrefslogtreecommitdiff
path: root/furry
blob: 1a91646ab8a714f5b3cf3013c384892746735da5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env lua
-- (C) 2022 Flecken-chan
-- Dis progwam comes with ABSOLUTELY NO WAWWANTY
-- Dis iz fwee software, and your'e welcome to redistwibute it under certain conditions
-- MIT License

local u = {
	"u", "ü", "ǘ", "ú", "ù", "ǜ", "o", "ö", "ø", "ó", "ò", "ð",
	"U", "Ü", "Ǘ", "Ú", "Ù", "Ǜ", "O", "Ö", "Ø", "Ó", "Ò", 
}

local w = {
	"w", "W",
}

local words = {"nya", "rawr", "ara", "awoo"}

math.randomseed(69420)

function string:randomcase()
	local s = ""

	for i = 1, #self do
		local c = self:sub(i, i)

		if math.random() < 0.5 then
			c = c:upper()
		end

		s = s .. c
	end

	return s
end

local encode = {}
local decode = {}

for i = 0, 255 do
	local c

	repeat
		if math.random() < 0.5 then
			c =
				u[math.random(#u)] ..
				w[math.random(#w)] ..
				u[math.random(#u)]
		else
			c = words[math.random(#words)]:randomcase()
		end

		if math.random() < 0.5 then
			c = c .. "~"
		end
	until not decode[c]

	encode[i] = c
	decode[c] = i
end

if arg[1] == "encode" then
	local buf
	local num = 0

	while true do
		local c = io.read(1)

		if buf and c ~= buf then
			local e = encode[buf:byte(1)] .. " "
		
			if num == 1 then
				io.write(e)
			else
				io.write("" .. num .. "x " .. e)
			end

			num = 1
		else
			num = num + 1
		end

		buf = c

		if not c then
			break
		end
	end
elseif arg[1] == "decode" then
	local buf = ""
	local num = 1

	while true do
		local c = io.read(1)

		if not c then
			break
		end

		if c == " " then
			local n = buf:sub(-1) == "x" and tonumber(buf:sub(1, -2))

			if n then
				num = n
			else
				if not decode[buf] then
					error("decode error")
				end
			
				local d = string.char(decode[buf])

				for i = 1, num do
					io.write(d)
				end

				num = 1
			end

			buf = ""
		else
			buf = buf .. c
		end
	end

	if buf ~= "" then
		error("trailing data")
	end
else
	print("Usage: " .. arg[0] .. " encode|decode")
	os.exit(1)
end