8KB以内の任意のファイルを、音声信号に変換して、プチコン3号のマイク入力経由で復号させる。
※2回に1回程度の成功率です。過度な期待はしないでください。あしからず。
Version 0.2.1 (November 27, 2014)
Powered by
md5.js
base64.js
' ' TXT:QPSK_DEM Programmed by OBONO ' _TH=20 ' Threshold _CE=1 ' Coefficient (1 or -1) ' INITIALIZE DIM _W%[261760] DIM _VF[4],_VP[6,4],_MR[3],_MC[7] READ _HS$ FOR _I=0 TO 5:FOR _J=0 TO 3 READ _VP[_I,_J] NEXT:NEXT FOR _I=0 TO 2:READ _MR[_I]:NEXT FOR _I=0 TO 6:READ _MC[_I]:NEXT DEF _GETW(_I):RETURN (_W%[_I]-&H80)*_CE:END ' RECORD FROM MIC ? "<<< QPSK Demodulater ver 0.2 >>>" ? "Push to start recording." XON MIC:REPEAT:VSYNC 1:UNTIL BUTTON(1)==16 MICSTART 0,0,32:? "Recording... ( to stop)" REPEAT:UNTIL BUTTON(1)==32 || MICPOS==261759 MICSTOP:_WS=MICPOS+1:MICSAVE 0,_WS,_W% XOFF MIC:? "Got ";_WS;" samples." 'LOAD"DAT:WAVE",_W%:_WS=261760 ' DEMODULATION _WP=0:_VL=0:_VE=0:_CK=0:_TV=_TH/2 GOSUB @PRE ' SYNCHRONIZE @SYNC _HL=0:_HS=0:_HC=0 REPEAT _W=_GETW(_WP) _HP=_HS*3+(_W>=_TH)-(_W<=-_TH)+1 _HS=ASC(MID$(_HS$,_HP,1))-65 _HC=(_HC+1)*(_HS>=10) _HS=_HS MOD 10:_HL=_HL+1:_WP=_WP+1 IF _VL && _HL>=1024 || _WP>=_WS THEN @BAIL UNTIL !_HS && _HC>=256 _VB=0:_VC=0:_VU=0 ' OBTAIN DATA REPEAT GOSUB @GETV IF _VR>=_TV THEN GOSUB @MATCH IF _VM<4 THEN _VB=_VB OR _VM<<(12-_VC*2) _VC=(_VC+1) MOD 7:_VU=1 IF !_VC THEN GOSUB @DEC:GOSUB @BYTE _CK=_CK+(Z XOR _VL*23 AND &HFF) _VL=_VL+1:_VB=0 IF _VL MOD 512==0 THEN @SYNC ENDIF ENDIF ENDIF _WP=_WP+4 UNTIL _WP>=_WS-4 || _VR<_TV ' FINISH @BAIL GOSUB @POST IF _VL>0 THEN PRINT "Demodulated ";_VL;" bytes." PRINT "(Corrected ";_VE;" bits)" PRINT "Checksum: ";_CK ENDIF END ' SUB ROUTINES ' GET A SIGNAL @GETV _VR=0:FOR _I=0 TO 3 _VF[_I]=_GETW(_WP+_I):_VR=_VR+POW(_VF[_I],2) NEXT:_VR=SQR(_VR) IF _VR>0 THEN FOR _I=0 TO 3:_VF[_I]=_VF[_I]*2/_VR:NEXT ENDIF:RETURN ' JUDGE PHASE @MATCH FOR _I=0 TO 5-_VU*2:_D=0:FOR _J=0 TO 3 _D=_D+POW(_VF[_J]-_VP[_I,_J],2) NEXT:IF !_I || _VD>_D THEN _VM=_I:_VD=_D NEXT:RETURN ' DECODE A BYTE @DEC FOR _I=0 TO 1 _N=0 FOR _J=0 TO 2 _B=0:_R=_VB>>_I*7 AND _MR[_J] FOR _K=0 TO 6:_B=_B XOR _R>>_K AND 1:NEXT _N=_N OR _B<<_J NEXT IF _N THEN _VB=_VB XOR 1<<_MC[_N-1]+_I*7:_VE=_VE+1 ENDIF NEXT Z=(_VB>>6 AND &HF0) OR (_VB>>3 AND &H0F) RETURN ' DATA DATA "AALAAMAANAOPQABQEFRAASAAKKA" DATA -1,-1, 1, 1, 1,-1,-1, 1, -1, 1, 1,-1 DATA 1, 1,-1,-1, 1, 1, 1, 1, -1,-1,-1,-1 DATA &H39,&H6A,&H5C,0,1,5,2,4,6,3 ' PROCEDURE @PRE COLOR 7:RETURN @BYTE IF Z>=&H20 && Z<&H7F THEN PRINT CHR$(Z); IF Z==&HA THEN PRINT RETURN @POST PRINT:COLOR 15:RETURN ' EOF