myPolybius={11:'A',12:'B',13:'C',14:'D',15:'E',\ 21:'F',22:'G',23:'H',24:'I',25:'K',\ 31:'L',32:'M',33:'N',34:'O',35:'P',\ 41:'Q',42:'R',43:'S',44:'T',45:'U',\ 51:'V',52:'W',53:'X',54:'Y',55:'Z'} myPolybiusR=dict([v,k] for [k,v] in myPolybius.items()) def strip1(wort): result='' for bs in wort: if bs not in result: result=result+bs return result def strip2(wort): result='' for k in range(65,91): if chr(k) not in wort: result=result+chr(k) return result def preCode(key): w1=(strip1(key)+strip2(key)).replace('J','I') return w1 def mkConverter(key): L=[[chr(x),'#']for x in range(65,91)] clearKey=strip1(key) rest=strip2(clearKey) gAlphabet=list(clearKey+rest) for k in range(26): L[k][1]=gAlphabet[k] return L def fixPhrase(zk): zk=zk.upper() zk=zk.replace('J','I') res='' for bs in zk: if ord(bs)>64 and ord(bs)<91: res=res+bs return res def encode(botschaft,wbuch): botschaft=fixPhrase(botschaft) chiffrat='' for bs in botschaft: chiffrat=chiffrat+str(wbuch[bs]) return chiffrat def decode(chiffre,wbuch): res='' while not chiffre=='': ch=chiffre[0:2] chiffre=chiffre[2:] res=res+wbuch[int(ch)] return res def schreibeDatei(datei,text): f=open(datei,'w') f.write(text) f.close()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question