ReplacingExceptionHandlersWithGravity / Redshift time hack /redshift-monodromy-webcam-detector2.html
perrabyte's picture
Upload 8 files
f46efae verified
Raw History Blame Contribute Delete
20.5 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Redshift Channel Monodromy Checker — Webcam as the Observer</title>
<style>
:root{--bg:#0b0e14;--panel:#131824;--ink:#dce2ee;--dim:#8b94a7;--acc:#4fd1a5;--warn:#f6ad55;--bad:#fc8181;}
*{box-sizing:border-box;margin:0;}
body{background:var(--bg);color:var(--ink);font:13px/1.45 ui-monospace,Menlo,Consolas,monospace;padding:14px;}
h1{font-size:16px;color:var(--acc);margin-bottom:2px;}
.sub{color:var(--dim);font-size:11px;margin-bottom:10px;max-width:1200px;}
.grid{display:grid;grid-template-columns:1fr 1fr 300px;gap:10px;align-items:start;}
.panel{background:var(--panel);border:1px solid #232b3d;border-radius:8px;padding:10px;}
.panel h2{font-size:10px;letter-spacing:.08em;text-transform:uppercase;color:var(--dim);margin-bottom:6px;}
canvas{display:block;width:100%;border-radius:6px;background:#000;}
video{display:none;}
.stat{display:flex;justify-content:space-between;gap:8px;padding:2px 0;border-bottom:1px dotted #222b40;font-size:11px;}
.stat .k{color:var(--dim);} .stat .v{color:var(--ink);text-align:right;}
.v.acc{color:var(--acc);} .v.warn{color:var(--warn);} .v.bad{color:var(--bad);}
button{background:#1c2740;color:var(--ink);border:1px solid #35446b;padding:5px 10px;border-radius:5px;font:inherit;cursor:pointer;margin:2px 4px 2px 0;font-size:11px;}
button:hover{background:#25345a;}
button.primary{border-color:var(--acc);color:var(--acc);}
button.danger{border-color:var(--bad);color:var(--bad);}
label{font-size:10px;color:var(--dim);display:block;margin-top:5px;}
input[type=range]{width:100%;margin:2px 0 6px;}
#log{height:110px;overflow-y:auto;font-size:10px;}
#log div{padding:2px 0;border-bottom:1px dotted #1c2334;}
.ok{color:var(--acc);} .warn{color:var(--warn);} .bad{color:var(--bad);} .dim{color:var(--dim);}
.big{font-size:12px;color:var(--acc);word-break:break-all;}
.meter{height:12px;background:#111;border:1px solid #2a3550;border-radius:4px;overflow:hidden;margin:3px 0 6px;}
.meter-fill{height:100%;background:linear-gradient(90deg,#2dd4bf,#a855f7,#fc8181);transition:width .08s linear;}
.verdict{padding:6px;border-radius:5px;font-size:12px;margin-top:4px;border:1px solid #2a3550;}
.verdict.flat{border-color:var(--acc);color:var(--acc);}
.verdict.sealed{border-color:var(--warn);color:var(--warn);}
.verdict.attack{border-color:var(--bad);color:var(--bad);}
.footer{margin-top:10px;color:var(--dim);font-size:10px;max-width:1200px;}
</style>
</head>
<body>
<h1>Redshift Channel Monodromy Checker — Webcam as the Observer</h1>
<div class="sub">A 2D Gaussian field is the "past," delivered through the redshift channel (aperture 1+z). Your webcam luminance sets the measurement frame (basis angle α, phase φ). Each frame the state is transported around a loop in frame space (α: 0→π/2→π→3π/2→0) and the holonomy ‖M − I‖ is checked: non-trivial transport = flat, patchable past (window open); transport → identity = the decoherence ledger has sealed the page. Toggle the redshift attack to splice the reported sheet and watch the width detector flag it.</div>
<div class="grid">
<div>
<div class="panel">
<h2>Channel (redshifted past, 2D Gaussian)</h2>
<canvas id="stage" width="320" height="320"></canvas>
<label>redshift z (aperture stretch 1+z): <span id="zVal">0.00</span></label>
<input type="range" id="zParam" min="0" max="3" step="0.05" value="0">
<label>decoherence rate Γ (ledger writing): <span id="gVal">1.0</span></label>
<input type="range" id="gamma" min="0" max="5" step="0.1" value="1">
<label>
<input type="checkbox" id="attack"> redshift attack (adversarial sheet splice)
</label>
</div>
<div class="panel" style="margin-top:8px">
<h2>Observer (webcam → measurement frame)</h2>
<canvas id="camView" width="160" height="120"></canvas>
<video id="camVideo" style="display:none;" muted playsinline></video>
<div id="camStatus" class="dim">camera idle</div>
<div style="margin-top:5px">
<button id="startBtn" class="primary">Open camera</button>
<button id="stopBtn">Stop</button>
</div>
<label><input type="radio" name="emode" value="cam" checked> webcam (real observer)</label>
<label><input type="radio" name="emode" value="sim"> synthetic observer (drifting noise)</label>
</div>
</div>
<div>
<div class="panel">
<h2>Monodromy verdict</h2>
<div class="verdict flat" id="verdict">window OPEN — transport non-trivial, past patchable</div>
<div class="stat" style="margin-top:6px"><span class="k">holonomy ‖M − I‖</span><span class="v acc" id="hol">—</span></div>
<div class="stat"><span class="k">decoherence D(t)</span><span class="v" id="dVal">0.000</span></div>
<div class="meter"><div class="meter-fill" id="dFill" style="width:0%"></div></div>
<div class="stat"><span class="k">patchability (1 − D)</span><span class="v acc" id="patch">1.000</span></div>
<div class="stat"><span class="k">ledger entropy written</span><span class="v warn" id="ent">0.00</span></div>
<div class="stat"><span class="k">frames / loops closed</span><span class="v" id="frames">0 / 0</span></div>
</div>
<div class="panel" style="margin-top:8px">
<h2>Width detector (σ vs aperture floor)</h2>
<canvas id="widthCv" width="320" height="120"></canvas>
<div class="stat"><span class="k">measured σ (channel)</span><span class="v" id="sigM">—</span></div>
<div class="stat"><span class="k">aperture floor σ₀(1+z)</span><span class="v" id="sigF">—</span></div>
<div class="stat"><span class="k">width verdict</span><span class="v" id="sigV">—</span></div>
</div>
</div>
<div>
<div class="panel">
<h2>Event log</h2>
<div id="log"></div>
</div>
<div class="panel" style="margin-top:8px">
<h2>Reading the sim</h2>
<div class="dim" style="font-size:10px">
Γ low → ledger writes slowly → webcam frame choices keep re-selecting the sheet (holonomy ≠ 0): the observer's code genuinely participates in which past is retrieved.<br><br>
Γ high → the Gaussian entangles with the "environment" (injected leakage noise), branches stop being interconvertible, transport collapses toward identity: the page is dry, the frame choice selects nothing.<br><br>
Attack mode replaces the reported channel with a re-projected splice — values plausible, width too clean for 1+z. The detector flags it by the aperture law, never by the values.
</div>
</div>
</div>
</div>
<div class="footer">Honest limits: decoherence is modeled as injected entangling noise on the state vector (a classical stand-in for the real functional); the "holonomy" is the measured transport of the reduced state around the frame loop, not a physical U(1) phase; webcam only reads luminance — it is the frame chooser, not a quantum detector. Camera needs permission; synthetic mode is provided.</div>
<script>
const $=id=>document.getElementById(id);
const log=(m,c="")=>{const d=document.createElement("div");if(c)d.className=c;d.textContent=m;const L=$("log");L.prepend(d);if(L.children.length>150)L.lastChild.remove();};
// ---------- channel state ----------
const N=64;
let psi=new Float64Array(N*N);
let env=new Float64Array(N*N);
let G=new Float64Array(N*N);
function gauss2(cx,cy,sx,sy,amp){
for(let y=0;y<N;y++)for(let x=0;x<N;x++){
const dx=(x-cx)/sx, dy=(y-cy)/sy;
G[y*N+x]+=amp*Math.exp(-(dx*dx+dy*dy)/2);
}
}
gauss2(N*0.38,N*0.5,6,6,1.0);
gauss2(N*0.62,N*0.5,6,6,0.8);
function zScale(){return 1+parseFloat($("zParam").value);}
function apertureFloor(){return SIG0*zScale();}
// ---------- observer (webcam as measurement frame) ----------
let mode="cam", video=document.getElementById("camVideo"), activeStream=null, running=true, frames=0, loops=0;
let rngSeed=(Math.random()*2**32)>>>0;
function mulberry32(a){return function(){a|=0;a=a+0x6D2B79F5|0;let t=Math.imul(a^a>>>15,1|a);t=t+Math.imul(t^t>>>7,61|t)^t;return((t^t>>>14)>>>0)/4294967296;};}
let rng=mulberry32(rngSeed);
async function shaShort(buf){
try{
const h=await crypto.subtle.digest("SHA-256",buf);
return Array.from(new Uint8Array(h)).slice(0,6).map(b=>b.toString(16).padStart(2,"0")).join("");
}catch(e){return "f0"+(frames%97).toString(16);}
}
function setVideoStatus(msg, ok){
const el=$("camStatus");
el.textContent=msg;
el.className=ok?"ok":"bad";
}
function initWebcam(){
stopCurrentVideo();
document.querySelector('input[value=cam]').checked=true;
document.querySelector('input[value=sim]').checked=false;
if(!navigator.mediaDevices||!navigator.mediaDevices.getUserMedia){
setVideoStatus("getUserMedia unavailable — synthetic observer", false);
mode="sim";
document.querySelector('input[value=cam]').checked=false;
document.querySelector('input[value=sim]').checked=true;
return;
}
navigator.mediaDevices.getUserMedia({video:{width:{ideal:640},height:{ideal:480}}})
.then(stream=>{
activeStream=stream;
// srcObject ONLY — never touch video.src while a stream is attached
video.srcObject=stream;
video.muted=true;
video.removeAttribute("loop");
const p=video.play();
if(p) p.catch(()=>{
setVideoStatus("click anywhere to start the stream", false);
const kick=()=>{video.play().catch(()=>{});window.removeEventListener("pointerdown",kick);};
window.addEventListener("pointerdown",kick);
});
video.onloadedmetadata=()=>{
setVideoStatus("webcam live: "+video.videoWidth+"×"+video.videoHeight, true);
};
mode="cam";
log("observer online: webcam luminance now selects the measurement frame","ok");
})
.catch(err=>{
setVideoStatus("camera failed: "+err.name+" — synthetic observer", false);
mode="sim";
document.querySelector('input[value=cam]').checked=false;
document.querySelector('input[value=sim]').checked=true;
log("camera unavailable: "+err.name+" — synthetic observer engaged","warn");
});
}
function stopCurrentVideo(){
if(activeStream){activeStream.getTracks().forEach(t=>t.stop());activeStream=null;}
// only revoke/reassign src if it was a blob URL — never when srcObject is set
if(video.src && String(video.src).startsWith("blob:")){
try{URL.revokeObjectURL(video.src);}catch(e){}
video.src="";
}
video.srcObject=null;
setVideoStatus("camera stopped — synthetic observer engaged", false);
$("camStatus").className="dim";
}
$("startBtn").onclick=()=>{mode="cam";initWebcam();};
$("stopBtn").onclick=()=>{mode="sim";stopCurrentVideo();};
document.querySelectorAll('input[name=emode]').forEach(r=>r.onchange=e=>{mode=e.target.value;if(mode==="sim")stopCurrentVideo();});
// don't auto-request camera on load; require a gesture
window.addEventListener("pointerdown",function once(){
window.removeEventListener("pointerdown",once);
if(mode==="cam" && !activeStream) initWebcam();
},{once:true});
// ---------- measurement frame from observer ----------
let alpha=0, phi=0, lastSheet=0;
function observerFrame(){
let a=0,p=0;
if(mode==="cam"&&video&&video.readyState>=2){
const c=document.createElement("canvas");c.width=16;c.height=12;
const x=c.getContext("2d");x.drawImage(video,0,0,16,12);
const d=x.getImageData(0,0,16,12).data;
let lr=0,cx=0,cy=0;
for(let i=0;i<16*12;i++){
const lum=0.299*d[i*4]+0.587*d[i*4+1]+0.114*d[i*4+2];
lr+=lum;cx+=lum*(i%16);cy+=lum*((i/16)|0);
}
a=(lr/(16*12))/255*Math.PI;
p=(cx/(16*12*255))*2*Math.PI;
}else{
a=(Math.sin(frames*0.013)*0.5+0.5)*Math.PI;
p=(Math.cos(frames*0.021)*0.5+0.5)*2*Math.PI;
}
alpha=alpha*0.9+a*0.1; phi=phi*0.9+p*0.1;
}
// ---------- decoherence / ledger ----------
let D=0, entropy=0, lastT=performance.now();
function ledgerStep(dt){
const gam=parseFloat($("gamma").value);
let leak=0;
for(let i=0;i<N*N;i+=4){env[i]+=Math.abs(psi[i])*gam*dt*0.01+1e-9; leak+=env[i];}
D=1-Math.exp(-gam*dt*0.25)* (1-D);
entropy+=gam*dt*0.25;
}
// ---------- transport & monodromy ----------
const LOOP=[0,Math.PI/2,Math.PI,3*Math.PI*0.75+Math.PI/4];
function measureProjection(a){
let s=0,q=0;
for(let y=0;y<N;y++)for(let x=0;x<N;x++){
const v=psi[y*N+x];
s+=v*Math.cos(a+ (x-N/2)*0.05);
q+=v*v;
}
return {s:s, norm:Math.sqrt(q)||1};
}
let holonomyResid=1;
function transportLoop(){
const start=Float64Array.from(psi);
let sheetVec=[0,0,0,0];
for(let k=0;k<4;k++){
const a=LOOP[k]+phi*0.0;
const m=measureProjection(a);
sheetVec[k]=m.s/m.norm;
const patch=1-D;
for(let i=0;i<N*N;i++){
psi[i]+= patch*0.02*Math.sin(a+((i%N)-N/2)*0.05)*psi[i];
}
}
let num=0,dA=0,dB=0;
for(let i=0;i<N*N;i++){num+=start[i]*psi[i];dA+=start[i]*start[i];dB+=psi[i]*psi[i];}
const cosSim=(dA&&dB)?num/Math.sqrt(dA*dB):1;
holonomyResid=Math.abs(1-cosSim);
loops++;
return sheetVec;
}
// ---------- attack ----------
let attackOn=false;
$("attack").onchange=e=>{
attackOn=e.target.checked;
log(attackOn?"ATTACK ON: reported sheet is re-projected — width forged, values plausible":"attack off — channel honest", attackOn?"bad":"ok");
};
// ---------- width detector ----------
const SIG0=6.0;
let sigmaMeas=SIG0, flagged=false;
function widthCheck(){
let wsum=0,xsum=0,xx=0,tot=0;
const mid=(N/2)|0;
for(let x=0;x<N;x++){
let col=0;for(let y=0;y<N;y++)col+=Math.abs(psi[y*N+x]);
wsum+=col;xsum+=col*x;xx+=col*x*x;
}
const mx=xsum/(wsum||1), vx=xx/(wsum||1)-mx*mx;
sigmaMeas=Math.sqrt(Math.max(vx,1e-6));
const floor=apertureFloor();
const reported= attackOn ? SIG0*(0.6+0.1*Math.sin(frames*0.1)) : sigmaMeas;
flagged = reported < floor*0.85 || reported > floor*1.6;
return {reported, floor, flagged};
}
// ---------- render ----------
const stage=$("stage"), sctx=stage.getContext("2d");
function render(){
const img=sctx.createImageData(N,N);
const zs=zScale();
const blur=Math.max(1, zs*1.2);
for(let y=0;y<N;y++)for(let x=0;x<N;x++){
const sx=Math.floor(N/2+(x-N/2)/zs), sy=Math.floor(N/2+(y-N/2)/zs);
let v=0,wsum=0;
for(let by=-2;by<=2;by++)for(let bx=-2;bx<=2;bx++){
const ux=Math.min(N-1,Math.max(0,sx+bx*blur|0)), uy=Math.min(N-1,Math.max(0,sy+by*blur|0));
const w=1/(1+Math.abs(bx)+Math.abs(by)); v+=psi[uy*N+ux]*w; wsum+=w;
}
v/=wsum||1;
const fade=1/(1+zs*0.6);
const r=Math.min(255, Math.abs(v)*(150+80*Math.cos(alpha))*fade*255*0.6);
const g=Math.min(255, Math.abs(v)*(150+80*Math.cos(alpha+Math.PI/2))*fade*255*0.6);
const b=Math.min(255, Math.abs(v)*(140+60*Math.sin(phi))*fade*255*0.6);
const ledger=Math.min(1, env[(y*N+x)% (N*N)]*3);
const i=(y*N+x)*4;
img.data[i]=r*(1-ledger*0.5)+ledger*90;
img.data[i+1]=g*(1-ledger*0.5)+ledger*40;
img.data[i+2]=b*(1-ledger*0.5)+ledger*60;
img.data[i+3]=255;
}
sctx.putImageData(img,0,0);
sctx.fillStyle="#ffffffcc";sctx.font="bold 10px monospace";
sctx.fillText("z="+parseFloat($("zParam").value).toFixed(2)+" α="+alpha.toFixed(2)+" φ="+phi.toFixed(2),6,14);
sctx.fillStyle= attackOn?"#fc8181":"#4fd1a5";
sctx.fillText(attackOn?"⚠ SPLICED SHEET REPORTED":"honest channel",6,28);
}
function renderWidth(rep,floor){
const cv=$("widthCv");
if(cv.width!==320||cv.height!==120){cv.width=320;cv.height=120;}
const ctx=cv.getContext("2d");
ctx.fillStyle="#05080d";ctx.fillRect(0,0,cv.width,cv.height);
const scale=v=>Math.max(0,Math.min(1,(isFinite(v)?v:0)/12));
// faint grid
ctx.strokeStyle="#1a2540";ctx.lineWidth=1;
for(let i=1;i<5;i++){const y=cv.height-cv.height*(i/5);ctx.beginPath();ctx.moveTo(0,y);ctx.lineTo(cv.width,y);ctx.stroke();}
// aperture floor band (acceptable ± range)
const lo=scale(floor*0.85)*cv.height, hi=scale(floor*1.6)*cv.height;
ctx.fillStyle="#2a355066";
ctx.fillRect(0,cv.height-hi,cv.width,Math.max(1,hi-lo));
// floor line
const yF=cv.height-scale(floor)*cv.height;
ctx.strokeStyle="#4fd1a5";ctx.lineWidth=2;ctx.setLineDash([]);
ctx.beginPath();ctx.moveTo(0,yF);ctx.lineTo(cv.width,yF);ctx.stroke();
// measured line
const yR=cv.height-scale(rep)*cv.height;
ctx.strokeStyle=flagged?"#fc8181":"#a855f7";ctx.lineWidth=4;
ctx.beginPath();ctx.moveTo(0,yR);ctx.lineTo(cv.width,yR);ctx.stroke();
// labels
ctx.fillStyle="#ffffff";ctx.font="bold 10px monospace";
ctx.fillText("measured σ vs aperture floor σ₀(1+z) — flag when outside band",6,14);
ctx.font="10px monospace";
ctx.fillStyle="#4fd1a5";ctx.fillText("floor "+floor.toFixed(2),6,Math.max(12,yF-4));
ctx.fillStyle=flagged?"#fc8181":"#a855f7";ctx.fillText("σ "+rep.toFixed(2),6,Math.min(cv.height-4,yR+12));
if(flagged){ctx.fillStyle="#fc8181";ctx.font="bold 11px monospace";ctx.fillText("⚠ FLAGGED",cv.width-95,14);}
}
// ---------- main loop ----------
let loopCounter=0, lastLoopAt=0;
async function tick(){
if(!running)return;
const now=performance.now(), dt=Math.min(0.1,(now-lastT)/1000); lastT=now;
observerFrame();
// live webcam preview onto the camView canvas so the user sees the stream
const _cv=$("camView"), _cx=_cv.getContext("2d");
if(mode==="cam" && video && video.readyState>=2){
_cx.drawImage(video,0,0,_cv.width,_cv.height);
} else {
_cx.fillStyle="#05080d";_cx.fillRect(0,0,_cv.width,_cv.height);
_cx.fillStyle="#8b94a7";_cx.font="10px monospace";
_cx.fillText(mode==="cam"?"starting camera…":"synthetic observer",8,_cv.height/2);
}
ledgerStep(dt);
for(let i=0;i<N*N;i++){
const x=i%N, y=(i/N)|0;
const l=psi[y*N+Math.max(0,x-1)], r=psi[y*N+Math.min(N-1,x+1)];
const u=psi[Math.max(0,y-1)*N+x], dn=psi[Math.min(N-1,y+1)*N+x];
psi[i]+= ( (l+r+u+dn-4*psi[i])*0.08 + (G[i]-psi[i])*0.02 )*(1-D*0.5);
psi[i]+= (1-D)*0.0006*Math.cos(alpha+phi)*Math.sin((x-N/2)*0.1+y*0.05);
}
loopCounter++;
if(loopCounter%8===0){
const sheet=transportLoop();
const hc=await shaShort(new TextEncoder().encode(sheet.join(",")+alpha.toFixed(3)));
$("hol").textContent=holonomyResid.toFixed(4);
$("hol").className= holonomyResid>0.01?"v acc":"v warn";
const V=$("verdict");
if(attackOn){V.className="verdict attack";V.textContent="ATTACK: spliced sheet — width inconsistent with aperture";log("loop "+loops+": holonomy "+holonomyResid.toFixed(4)+" · sheet hash "+hc+" · WIDTH FLAGGED","bad");}
else if(D>0.95){V.className="verdict sealed";V.textContent="WINDOW SEALED — ledger has written; frame choice selects nothing";log("loop "+loops+": transport ≈ identity (flat) — page dry, D="+D.toFixed(3),"warn");}
else {V.className="verdict flat";V.textContent="WINDOW OPEN — non-trivial transport: observer code selects the sheet";log("loop "+loops+": monodromy "+holonomyResid.toFixed(4)+" · α="+alpha.toFixed(2)+" · sheet hash "+hc,"ok");}
$("dVal").textContent=D.toFixed(3);
$("dFill").style.width=(D*100).toFixed(1)+"%";
$("patch").textContent=(1-D).toFixed(3);
$("ent").textContent=entropy.toFixed(2);
$("frames").textContent=frames+" / "+loops;
}
const wc=widthCheck();
$("sigM").textContent=wc.reported.toFixed(2)+" px";
$("sigF").textContent=wc.floor.toFixed(2)+" px";
const sv=$("sigV");
if(wc.flagged){sv.textContent="⚠ FLAGGED — too clean for aperture";sv.className="v bad";if(!flagged||frames%30===0)log("width detector: reported σ "+wc.reported.toFixed(2)+" < floor "+wc.floor.toFixed(2)+" — re-projected splice","bad");}
else{sv.textContent="consistent with channel";sv.className="v ok";}
renderWidth(wc.reported,wc.floor);
render();
frames++;
requestAnimationFrame(tick);
}
$("zParam").oninput=e=>$("zVal").textContent=parseFloat(e.target.value).toFixed(2);
$("gamma").oninput=e=>$("gVal").textContent=parseFloat(e.target.value).toFixed(1);
$("zParam").addEventListener("input",()=>{ if(frames>0)log("redshift changed: aperture floor now "+apertureFloor().toFixed(2),"dim"); });
$("gamma").addEventListener("input",()=>{ log("Γ changed: ledger rate now "+$("gamma").value+" — window trajectory updated","dim"); });
log("channel initialized: two-branch Gaussian event, D(0)=0 — past maximally patchable","dim");
log("open the camera to make your luminance the measurement frame; every loop is a delayed choice","dim");
tick();
</script>
</body>
</html>