bx1166
註冊時間: 2011-12-06 文章: 273
第 1 樓
|
發表於: 星期五 十二月 18, 2015 7:53 pm 文章主題: Enigma 密碼機的編碼方式中文裡的替代方式 |
|
|
中文常常會夾雜著英文跟數字
所以必須換個方式處理, 以下為中英文混用的編碼prg
請大家指教 謝謝 !
***Chinese coding
para kp
if pcount()=0
kp=1
endif
*sele 1
*use mallkey
*go kp
*if .not. eof()
*key6=A.qkey
*else
key6="F>MEBK:V6#g|j\*ot=zO_UZW ePCw<5u(3@Hd[4RIGhi0v,lca!$.}T'^`J2978QyArX)1qNm;/pfb{+kY%?Lx]-DSns"
*endif
cstring='英國女王伊莉莎白二世Elizabeth II赦免了阿蘭圖靈於上世紀因同性戀行為而被定的罪。今天不少媒體也有報導這件事,亦有介紹圖靈生前的主要事跡。二戰時破解了德軍的EnigmaCode , 破解了這套令德軍引以為傲的密碼系統。'
nno=len(cstring)
clear
kqc=cencode(cstring)
? kqc
?
krc=cdecode(kqc)
? krc
?
retu
*****************************
function cencode
para pstring
cc=''
for x=1 to nno
ctext=substr(cstring,x,1)
if asc(ctext)>127
ctext=substr(cstring,x,1)
ncc=asc(ctext)+1000
cc=cc+substr(str(ncc,4),2,3)
dtext=substr(cstring,x+1,1)
ncc=asc(dtext)+1000
cc=cc+substr(str(ncc,4),2,3)
x=x+1
else
ncc=asc(ctext)+1000000
cc=cc+substr(str(ncc,7),2,6)
endif
next x
ucc=''
for x=1 to len(cc)
ypos=val(substr(cc,x,1))
if ypos=0
ypos=10
endif
y=mod(x , && 8
if y=0
y=8
endif
key1=substr(key6,(y*8+1),10)
ucc=ucc+substr(key1,ypos,1)
next x
retu ucc
********************
function cdecode
para ucc
scc=''
for x=1 to len(ucc)
ypoc=substr(ucc,x,1)
y=mod( x, && 8
if y=0
y=8
endif
key1=substr(key6,(y*8+1),10)
xpos=at(ypoc,key1)
if xpos=10
xpos=0
endif
scc=scc+str(xpos,1)
next x
kcc=''
for x= 1 to len(scc)
knc1=val(substr(scc,x,3))
knc2=val(substr(scc,x+3,3))
if knc1>0
kcc=kcc+chr(knc1)+chr(knc2)
else
kcc=kcc+chr(knc2)
endif
x=x+5
next x
retu kcc
endfunc
************** |
|