File size: 9,849 Bytes
926dae2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25f5d0a
 
926dae2
 
 
 
 
 
 
 
 
 
 
 
 
25f5d0a
926dae2
 
 
 
 
 
ba090b1
 
 
51fbf66
 
ba090b1
 
51fbf66
ba090b1
 
 
51fbf66
ba090b1
 
 
51fbf66
 
 
ba090b1
 
51fbf66
 
 
 
 
ba090b1
51fbf66
 
 
 
 
 
ba090b1
 
bb1bb3b
 
 
bdd03a2
 
 
 
 
 
 
bb1bb3b
 
bdd03a2
bb1bb3b
 
bdd03a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
926dae2
 
25f5d0a
 
926dae2
 
 
 
 
25f5d0a
926dae2
 
25f5d0a
926dae2
 
 
25f5d0a
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Shitposter Cipher - Secure Web Terminal</title>
    <script src="https://cdn.jsdelivr.net/pyodide/v0.25.0/full/pyodide.js"></script>
    <style>
        body {
            font-family: 'Courier New', Courier, monospace;
            background-color: #1a1a1a;
            color: #d4d4d4;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            margin: 0;
        }
        .container {
            width: 90%;
            max-width: 800px;
            background-color: #252526;
            padding: 2rem;
            border-radius: 8px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.5);
            border: 1px solid #333;
        }
        h1 {
            text-align: center;
            color: #569cd6;
            margin-bottom: 1.5rem;
            border-bottom: 1px solid #333;
            padding-bottom: 0.5rem;
        }
        .status {
            text-align: center;
            font-size: 0.8rem;
            margin-bottom: 1rem;
            color: #ce9178;
        }
        textarea, input {
            width: 100%;
            background-color: #1e1e1e;
            border: 1px solid #3c3c3c;
            color: #d4d4d4;
            padding: 0.8rem;
            margin-bottom: 1rem;
            border-radius: 4px;
            box-sizing: border-box;
        }
        textarea { height: 120px; resize: vertical; }
        .controls {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 10px;
            margin-bottom: 1rem;
        }
        button {
            background-color: #0e639c;
            color: white;
            border: none;
            padding: 0.8rem;
            border-radius: 4px;
            cursor: pointer;
            font-weight: bold;
            transition: background 0.2s;
        }
        button:hover { background-color: #1177bb; }
        button:disabled { background-color: #333; cursor: not-allowed; }
        .label { font-size: 0.9rem; margin-bottom: 0.3rem; color: #9cdcfe; }
        .output-container {
            margin-top: 1.5rem;
            padding-top: 1.5rem;
            border-top: 1px solid #333;
        }
        #output {
            background-color: #000;
            color: #4ec9b0;
            padding: 1rem;
            border-radius: 4px;
            white-space: pre-wrap;
            word-break: break-all;
            min-height: 50px;
        }
        .copy-btn { margin-top: 0.5rem; font-size: 0.7rem; padding: 0.3rem; width: auto; float: right; }
    </style>
</head>
<body>
    <div class="container">
        <h1>SHITPOSTER TERMINAL</h1>
        <div id="status" class="status">Initializing WebAssembly environment...</div>

        <div class="label">Identity / Key File (JSON or Channel Words)</div>
        <textarea id="keyInput" placeholder="Paste your session.json or channel words here..."></textarea>

        <div class="label">Input Text (Message to Encrypt, Shitpost to Decrypt, or Peer Key to Derive)</div>
        <textarea id="mainInput" placeholder="Enter message, shitpost, or Peer Public Key..."></textarea>

        <div class="controls">
            <button id="btnEncrypt" onclick="doAction('encrypt')" disabled>ENCRYPT (STEALTH)</button>
            <button id="btnDecrypt" onclick="doAction('decrypt')" disabled>DECRYPT</button>
        </div>
        
        <div class="controls">
            <button id="btnKeygen" onclick="doAction('keygen')" disabled>GENERATE IDENTITY</button>
            <button id="btnDerive" onclick="doAction('derive')" disabled>DERIVE SESSION</button>
        </div>

        <div class="output-container">
            <div class="label">Console Output</div>
            <div id="output">System ready.</div>
            <button class="copy-btn" onclick="copyOutput()">COPY TO CLIPBOARD</button>
        </div>
    </div>

    <script>
        let pyodide;
        const statusEl = document.getElementById('status');
        const outputEl = document.getElementById('output');

        async function initPyodide() {
            try {
                console.log("Starting Pyodide initialization...");
                statusEl.innerText = "Downloading WebAssembly (Pyodide)...";
                pyodide = await loadPyodide();
                
                console.log("Pyodide loaded. Installing micropip...");
                statusEl.innerText = "Installing package manager (micropip)...";
                await pyodide.loadPackage(["micropip"]);
                
                console.log("Installing cryptography...");
                statusEl.innerText = "Installing security modules (cryptography)...";
                const micropip = pyodide.pyimport("micropip");
                await micropip.install('cryptography');
                
                console.log("Fetching local cipher logic...");
                statusEl.innerText = "Downloading cipher logic files...";
                
                // Fetch our local files and write them to Pyodide FS
                const files = ['crypto.py', 'steg.py', 'stealth.py', 'fingerprint.py'];
                const timestamp = new Date().getTime();
                for (const f of files) {
                    console.log(`Fetching ${f}...`);
                    const resp = await fetch(`${f}?v=${timestamp}`);
                    if (!resp.ok) throw new Error(`Failed to fetch ${f}: ${resp.status}`);
                    const text = await resp.text();
                    pyodide.FS.writeFile(f, text);
                }

                console.log("Initializing Python bridge...");
                statusEl.innerText = "Configuring secure bridge...";
                pyodide.runPython(`
import sys
print("Python Bridge Loading...")
import json
import base64
from crypto import ShitposterCrypto
from steg import encode_bytes, decode_string
from stealth import generate_stealth_text
from fingerprint import get_fingerprint

print("Imports successful.")

CRYPTO = ShitposterCrypto()
# ... (rest of the code is same, no changes needed to logic)


def bridge_keygen():
    priv, pub_bytes = CRYPTO.generate_keypair()
    priv_bytes = CRYPTO.get_private_bytes(priv)
    return json.dumps({
        "private_key_b64": base64.b64encode(priv_bytes).decode('utf-8'),
        "public_signal": encode_bytes(pub_bytes)
    })

def bridge_derive(peer_signal, my_priv_b64):
    priv_bytes = base64.b64decode(my_priv_b64)
    priv_key = CRYPTO.load_private_key(priv_bytes)
    
    # Try Base64 input first
    try:
        if " " not in peer_signal.strip():
            # Add padding just in case
            b64_str = peer_signal.strip()
            missing_padding = len(b64_str) % 4
            if missing_padding:
                b64_str += '=' * (4 - missing_padding)
            peer_pub = base64.b64decode(b64_str)
            
            # Handle 33-byte keys (leading null byte)
            if len(peer_pub) == 33 and peer_pub[0] == 0:
                peer_pub = peer_pub[1:]
        else:
            raise ValueError("Not Base64")
    except Exception as e:
        # Fallback to shitpost decoding if not base64
        try:
            peer_pub = decode_string(peer_signal)
        except:
            raise ValueError(f"Failed to decode key: {e}")
            
    if len(peer_pub) != 32:
        # Convert to hex for debug
        hex_val = "".join("{:02x}".format(x) for x in peer_pub)
        raise ValueError(f"Invalid Key Length: Got {len(peer_pub)} bytes. Expected 32. Hex: {hex_val}")
    
    keys = CRYPTO.derive_shared_secret(priv_key, peer_pub)
    
    fp = get_fingerprint(keys)
    
    return json.dumps({
        "tx": base64.b64encode(keys['tx']).decode('utf-8'),
        "rx": base64.b64encode(keys['rx']).decode('utf-8'),
        "fingerprint": fp
    })

def bridge_encrypt(msg, key_json_or_words):
    try:
        data = json.loads(key_json_or_words)
        key = base64.b64decode(data['tx'])
    except:
        key = decode_string(key_json_or_words)
    
    payload = CRYPTO.encrypt_message(key, msg)
    from steg import WORDLIST
    words = [WORDLIST[b] for b in payload]
    return generate_stealth_text(words)

def bridge_decrypt(shitpost, key_json_or_words):
    try:
        data = json.loads(key_json_or_words)
        key = base64.b64decode(data['rx'])
    except:
        key = decode_string(key_json_or_words)
        
    payload = decode_string(shitpost)
    return CRYPTO.decrypt_message(key, payload)
                `);

                statusEl.innerText = "WASM Secure Terminal Online";
                statusEl.style.color = "#4ec9b0";
                document.querySelectorAll('button').forEach(b => b.disabled = false);

            } catch (err) {
                console.error(err);
                statusEl.innerText = "Initialization Failed: " + err.message;
                statusEl.style.color = "#f44747";
            }
        }

        async function doAction(action) {
            const input = document.getElementById('mainInput').value.trim();
            const key = document.getElementById('keyInput').value.trim();
            outputEl.innerText = "Processing...";

            try {
                let result;
                if (action === 'keygen') {
                    // ...
                } 
                else if (action === 'derive') {
                    if (!input) throw new Error("Please paste the Peer's Public Key into the 'Input Text' box below.");
                    const myPriv = prompt("Enter your Private Key (Base64):");
                    if (!myPriv) return;
                    result = pyodide.globals.get('bridge_derive')(input, myPriv);
                    // ...