Denkfehler? - Anfänger braucht Hilfe
Verfasst: Freitag 8. Mai 2009, 16:51
Ich will zu üben ein kleines Pythonprogramm schreiben, das einen text ohne umlaute durch Buchstabenvertauschen verschlüsseln kann. Bedient wird es im Moment von Python Card aus. Nur habe ich jetzt ein Probem. die Buchstaben a, b und c werden nicht verschlüsselt. Ich glaube, dass mein Problem in den Listen liegt, in denen die Buchstaben abgespeichert sind. Ich glaube auch das es irgendwie damit zusammenhängt, wie ich die Zahl angebe, um die die Buchstaben versetzt werden sollen. Ach schaut euch das einfach mal an, und habt bitte Nachsicht mit einem Anfänger. Die vielen print's sind nur wegen der Fehlersuche da. Danke schonmal für eure Hilfe!
Code: Alles auswählen
#!/usr/bin/python
# -*- coding: cp1252 -*-
"""
__version__ = "$Revision: 1.3 $"
__date__ = "$Date: 2004/04/14 02:38:47 $"
"""
from PythonCard import model
def schluesseln(eingabe, faktor):
x = list(eingabe)
woerter = eingabe.split()
y = list(u'xyzabcdefghijklmnopqrstuvwxyzabc')
z = list(u'XYZABCDEFGHIJKLMNOPQRSTUVWXYZABC')
k = list(u'89012345678901234567890123456789')
print x
print y
wortnummer = 1
for wort in woerter:
stelle = 0
for buchstabe in x:
print buchstabe
wo = 0
#print 'for x gest'
for buchstver in y:
#print 'for y gest'
print 'xstelle: '+str(stelle)+' '+'xst: '+x[stelle]+' '+y[wo]
if 5 < wo < 31:
if x[stelle] == y[wo]:
#print 'if stelle = wo erfolgr'
x[stelle] = y[wo+wortnummer*faktor]
#print 'xstelle: '+str(stelle)+' '+'xst: '+x[stelle]+' '+'buchst: '+buchstabe+' '+y[wo]
print 'out: ' + x[stelle]+ ' Vers: '+str(wortnummer*faktor)
break
if 5 < wo < 32:
if x[stelle] == z[wo]:
#print 'if stelle = wo erfolgr'
x[stelle] = z[wo+wortnummer*faktor]
print 'out: ' + x[stelle]+ ' Vers: '+str(wortnummer*faktor)
break
if 5 < wo < 32:
if x[stelle] == k[wo]:
#print 'if stelle = wo erfolgr'
x[stelle] = k[wo+wortnummer*faktor]
print 'out: ' + x[stelle]+ ' Vers: '+str(wortnummer*faktor)
break
if wo <= 25:
wo = wo+1
else:
wo = 0
stelle = stelle +1
if wortnummer == 1:
wortnummer = 2
elif wortnummer == 2:
wortnummer = 3
elif wortnummer == 3:
wortnummer = 1
xb = str(''.join(x))
return xb
#self.components.txtdisp.text = xb
class MyBackground(model.Background):
def on_initialize(self, event):
# if you have any initialization
# including sizer setup, do it here
pass
def on_btnverschluesseln_mouseClick(self, event):
self.components.txtdisp.text = schluesseln(self.components.txtdisp.text, -1)
def on_btnentschluesseln_mouseClick(self, event):
self.components.txtdisp.text = schluesseln(self.components.txtdisp.text, 1)
if __name__ == '__main__':
app = model.Application(MyBackground)
app.MainLoop()