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