]> git.lizzy.rs Git - furry-encoder.git/blob - furry
owo
[furry-encoder.git] / furry
1 #!/usr/bin/env lua
2 -- (C) 2022 Flecken-chan
3 -- Dis progwam comes with ABSOLUTELY NO WAWWANTY
4 -- Dis iz fwee software, and your'e welcome to redistwibute it under certain conditions
5 -- MIT License
6
7 local u = {
8         "u", "ü", "ǘ", "ú", "ù", "ǜ", "o", "ö", "ø", "ó", "ò", "ð",
9         "U", "Ü", "Ǘ", "Ú", "Ù", "Ǜ", "O", "Ö", "Ø", "Ó", "Ò", 
10 }
11
12 local w = {
13         "w", "W",
14 }
15
16 local words = {"nya", "rawr", "ara", "awoo"}
17
18 math.randomseed(69420)
19
20 function string:randomcase()
21         local s = ""
22
23         for i = 1, #self do
24                 local c = self:sub(i, i)
25
26                 if math.random() < 0.5 then
27                         c = c:upper()
28                 end
29
30                 s = s .. c
31         end
32
33         return s
34 end
35
36 local encode = {}
37 local decode = {}
38
39 for i = 0, 255 do
40         local c
41
42         repeat
43                 if math.random() < 0.5 then
44                         c =
45                                 u[math.random(#u)] ..
46                                 w[math.random(#w)] ..
47                                 u[math.random(#u)]
48                 else
49                         c = words[math.random(#words)]:randomcase()
50                 end
51
52                 if math.random() < 0.5 then
53                         c = c .. "~"
54                 end
55         until not decode[c]
56
57         encode[i] = c
58         decode[c] = i
59 end
60
61 if arg[1] == "encode" then
62         local buf
63         local num = 0
64
65         while true do
66                 local c = io.read(1)
67
68                 if buf and c ~= buf then
69                         local e = encode[buf:byte(1)] .. " "
70                 
71                         if num == 1 then
72                                 io.write(e)
73                         else
74                                 io.write("" .. num .. "x " .. e)
75                         end
76
77                         num = 1
78                 else
79                         num = num + 1
80                 end
81
82                 buf = c
83
84                 if not c then
85                         break
86                 end
87         end
88 elseif arg[1] == "decode" then
89         local buf = ""
90         local num = 1
91
92         while true do
93                 local c = io.read(1)
94
95                 if not c then
96                         break
97                 end
98
99                 if c == " " then
100                         local n = buf:sub(-1) == "x" and tonumber(buf:sub(1, -2))
101
102                         if n then
103                                 num = n
104                         else
105                                 if not decode[buf] then
106                                         error("decode error")
107                                 end
108                         
109                                 local d = string.char(decode[buf])
110
111                                 for i = 1, num do
112                                         io.write(d)
113                                 end
114
115                                 num = 1
116                         end
117
118                         buf = ""
119                 else
120                         buf = buf .. c
121                 end
122         end
123
124         if buf ~= "" then
125                 error("trailing data")
126         end
127 else
128         print("Usage: " .. arg[0] .. " encode|decode")
129         os.exit(1)
130 end