Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -26,23 +26,55 @@ thresholds = pd.Series({
|
|
26 |
|
27 |
# === Utility functions ===
|
28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
def string_to_binary_labels(s: str) -> list[int]:
|
30 |
bits = []
|
31 |
for char in s:
|
32 |
-
|
33 |
-
char_bits = [(
|
34 |
bits.extend(char_bits)
|
35 |
return bits
|
36 |
|
37 |
def binary_labels_to_string(bits: list[int]) -> str:
|
38 |
chars = []
|
39 |
-
for i in range(0, len(bits),
|
40 |
-
|
41 |
-
if len(
|
42 |
-
|
43 |
-
|
44 |
-
chars.append(
|
45 |
return ''.join(chars)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
def clean_image(img: Image.Image, min_size: int = 256) -> Image.Image:
|
48 |
img = img.convert("RGB")
|
@@ -194,9 +226,9 @@ with tab3:
|
|
194 |
decoded_strings.append(binary_labels_to_string(bitlist))
|
195 |
|
196 |
st.subheader("Binary as Bitstrings")
|
197 |
-
for
|
198 |
st.code(b)
|
199 |
|
200 |
-
st.subheader("Decoded
|
201 |
-
for
|
202 |
-
st.write(s)
|
|
|
26 |
|
27 |
# === Utility functions ===
|
28 |
|
29 |
+
# Voyager ASCII 6-bit conversion table
|
30 |
+
voyager_table = {
|
31 |
+
i: ch for i, ch in enumerate([
|
32 |
+
' ', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
|
33 |
+
'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
|
34 |
+
'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2',
|
35 |
+
'3', '4', '5', '6', '7', '8', '9', '.', '(', ')',
|
36 |
+
'+', '-', '*', '/', '=', '$', '!', ':', '%', '"',
|
37 |
+
'#', '@', '\'', '?', '&'
|
38 |
+
])
|
39 |
+
}
|
40 |
+
reverse_voyager_table = {v: k for k, v in voyager_table.items()}
|
41 |
+
|
42 |
+
# === Utility functions ===
|
43 |
+
|
44 |
def string_to_binary_labels(s: str) -> list[int]:
|
45 |
bits = []
|
46 |
for char in s:
|
47 |
+
val = reverse_voyager_table.get(char.upper(), 0)
|
48 |
+
char_bits = [(val >> bit) & 1 for bit in range(5, -1, -1)]
|
49 |
bits.extend(char_bits)
|
50 |
return bits
|
51 |
|
52 |
def binary_labels_to_string(bits: list[int]) -> str:
|
53 |
chars = []
|
54 |
+
for i in range(0, len(bits), 6):
|
55 |
+
chunk = bits[i:i+6]
|
56 |
+
if len(chunk) < 6:
|
57 |
+
chunk += [0] * (6 - len(chunk))
|
58 |
+
val = sum(b << (5 - j) for j, b in enumerate(chunk))
|
59 |
+
chars.append(voyager_table.get(val, '?'))
|
60 |
return ''.join(chars)
|
61 |
+
# def string_to_binary_labels(s: str) -> list[int]:
|
62 |
+
# bits = []
|
63 |
+
# for char in s:
|
64 |
+
# ascii_code = ord(char)
|
65 |
+
# char_bits = [(ascii_code >> bit) & 1 for bit in range(7, -1, -1)]
|
66 |
+
# bits.extend(char_bits)
|
67 |
+
# return bits
|
68 |
+
|
69 |
+
# def binary_labels_to_string(bits: list[int]) -> str:
|
70 |
+
# chars = []
|
71 |
+
# for i in range(0, len(bits), 8):
|
72 |
+
# byte = bits[i:i+8]
|
73 |
+
# if len(byte) < 8:
|
74 |
+
# byte += [0] * (8 - len(byte))
|
75 |
+
# ascii_val = sum(b << (7 - j) for j, b in enumerate(byte))
|
76 |
+
# chars.append(chr(ascii_val))
|
77 |
+
# return ''.join(chars)
|
78 |
|
79 |
def clean_image(img: Image.Image, min_size: int = 256) -> Image.Image:
|
80 |
img = img.convert("RGB")
|
|
|
226 |
decoded_strings.append(binary_labels_to_string(bitlist))
|
227 |
|
228 |
st.subheader("Binary as Bitstrings")
|
229 |
+
for b in binary_strings:
|
230 |
st.code(b)
|
231 |
|
232 |
+
st.subheader("Decoded Voyager Strings")
|
233 |
+
for s in decoded_strings:
|
234 |
+
st.write(s)
|