| 
			
				|  | VFP 愛用者社區 本討論區為 Visual Foxpro 愛用者經驗交流的地方, 請多多利用"搜尋"的功能, 先查看看有無前例可循, 如果還有不懂的再發問. 部份主題有附加檔案, 須先註冊成為社區居民才可以下載.
 
 |  
 
	
		| 上一篇主題 :: 下一篇主題 |  
		| 發表人 | 內容 |  
		| bx1166 
 
 
 註冊時間: 2011-12-06
 文章: 273
 
 
 第 1 樓
 
 | 
			
				|  發表於: 星期五 十二月 18, 2015 5:04 pm    文章主題: Enigma 密碼機的編碼方式 |   |  
				| 
 |  
				| 前兩天 HBO 演了一部影片 The imitation game. 模仿遊戲 談到 Alan Turing 亞倫圖靈 對於二次大戰德軍密碼機 Enigma解碼的經過
 以前讀過一本商務書局出版的 碼書 有提到這個故事
 影片很感人 也很感傷 閒來沒事 寫了一段prg 模凝一下 Enigma
 請各位先進指導一下 謝謝 !
 
 para k1,k2
 do case
 case pcount()=0
 k1=1
 k2=2
 case pcount()=1
 k2=39
 endcase
 public oString,eString,rstring,nno,key1,key2,key3,key4,key5,key6
 *sele 1
 *use mallkey
 *k1=mod(k1,100)
 *go k1
 *key1=A.qkey
 *go 100
 *key6=A.qkey
 
 key1="4,395%'a`krKW[Gj<&?]I=uUeDXl^)Bc>Q;!$60bZzHw(tAx|YJFO-fC*sV.mP1qLdMpT 2ygoh:i#8\/+{SRE7}Nv@n"
 key6="eDXl^)Bc>Q;!$60bZzHw4,395%'a`krKW[Gj<&?]I=uU(P1qLdMpT 2ygoh:i#8\/tAx|YJFO-fC*sV.m+{SRE7}Nv@n"
 nno=92
 *nfile=getfile("txt","Brow text file:")
 *=adir(bokfile,nfile)
 **qq=bokfile[1,2]
 *? ".......Reading:"+nfile
 *gnFileHandle = fopen(nfile)
 *if gnFileHandle<0
 *	wait "檔案無法開啟 !"
 *	retu
 *endif
 *= fseek(gnFileHandle, 0, 0)              && Move pointer to BOF
 *oString = fread(gnFileHandle, qq)
 *=fclose(gnFileHandle)
 cString="The Enigma machines were a series of electro-mechanical rotor cipher machines developed and used in the early- to mid-twentieth century to protect commercial secrets."
 ? cstring
 estring=mc1(cString)
 ?
 ? eString
 ?
 rstring=deco1(estring)
 ?
 ? rstring
 ?
 retu
 ******************
 func deco1
 para pstring
 qstring=''
 for x=1 to len(pString)
 ypoc=substr(pString,x,1)
 ypos=at(ypoc,key6)
 ypos=ypos-k2-x
 do while ypos<=0
 ypos=ypos+nno
 enddo
 ctext=substr(key1,ypos,1)
 qstring=qstring+ctext
 next x
 retu qstring
 endf
 *****************
 func mc1
 para pString
 qString=''
 for x=1 to len(pString)
 spos=substr(pString,x,1)
 if asc(spos)<32
 spos=" "
 endif
 xpos=at(spos,key1)
 xpos=xpos+k2+x
 do while xpos>nno
 xpos=xpos-nno
 enddo
 etext=substr(key6,xpos,1)
 qString=qString+etext
 next x
 retu qstring
 endf
 *************
 |  |  
		| 回頂端 |  |  
		|  |  
		|  |  
  
  	| 
 
 | 您 無法 在這個版面發表文章 您 無法 在這個版面回覆文章
 您 無法 在這個版面編輯文章
 您 無法 在這個版面刪除文章
 您 無法 在這個版面進行投票
 您 無法 在這個版面附加檔案
 您 無法 在這個版面下載檔案
 
 |  |