70 lines
1.7 KiB
Python
70 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: iso-8859-15 -*-
|
|
|
|
#Klartext: Beispielklartext
|
|
#Schlüssel: Apfelstrudel
|
|
#Chiffrat: 31 14 35 21 12 35 14 15 41 15 11 23 22 14 53 22
|
|
|
|
text="Be1ispie3lklartext was ist das?"
|
|
PW="A9pfelstr2udel"
|
|
QZ5=[11,12,13,14,15,21,22,23,24,25,31,32,33,34,35,41,42,43,44,45,51,52,53,54,55]
|
|
alpha5ij="ABCDEFGHIKLMNOPQRSTUVWXYZ" #j wird durch i ersetzt
|
|
alpha5uv="ABCDEFGHIJKLMNOPQRSTUWXYZ" #v wird durch u ersetzt
|
|
QZ6=[11,12,13,14,15,16,21,22,23,24,25,26,31,32,33,34,35,36,41,42,43,44,45,46,51,52,53,54,55,56,61,62,63,64,65,66]
|
|
alpha6="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
|
text=text.upper()
|
|
textij=text.replace("J","I")
|
|
textuv=text.replace("V","U")
|
|
PW=PW.upper()
|
|
PWi=PW.replace("J","I")
|
|
PWu=PW.replace("V","U")
|
|
passw5ij=""
|
|
for i in PWi:
|
|
if i in alpha5ij:passw5ij+=i
|
|
passw5uv=""
|
|
for i in PWu:
|
|
if i in alpha5uv:passw5uv+=i
|
|
passw6=""
|
|
for i in PWi:
|
|
if i in alpha6:passw6+=i
|
|
text5ij=""
|
|
for i in textij:
|
|
if i in alpha5ij:text5ij+=i
|
|
text5uv=""
|
|
for i in textuv:
|
|
if i in alpha5uv:text5uv+=i
|
|
text6=""
|
|
for i in text:
|
|
if i in alpha6:text6+=i
|
|
PW5ij=""
|
|
for b in PWi+alpha5ij:
|
|
if b in alpha5ij and b not in PW5ij:PW5ij+=b
|
|
PW5uv=""
|
|
for b in PWu+alpha5uv:
|
|
if b in alpha5uv and b not in PW5uv:PW5uv+=b
|
|
PW6=""
|
|
for b in PW+alpha6:
|
|
if b in alpha6 and b not in PW6:PW6+=b
|
|
WB5ij={}
|
|
for i in range(25):
|
|
WB5ij[PW5ij[i]]=str(QZ5[i])
|
|
WB5uv={}
|
|
for i in range(25):
|
|
WB5uv[PW5uv[i]]=str(QZ5[i])
|
|
WB6={}
|
|
for i in range(36):
|
|
WB6[PW6[i]]=str(QZ6[i])
|
|
ctext5ij=""
|
|
for b in text5ij:ctext5ij+=WB5ij[b]+" "
|
|
ctext5uv=""
|
|
for b in text5uv:ctext5uv+=WB5uv[b]+" "
|
|
ctext6=""
|
|
for b in text6:ctext6+=WB6[b]+" "
|
|
|
|
print("5x5(j=i)",text5ij,passw5ij)
|
|
print(ctext5ij)
|
|
print("5x5(v=u)",text5uv,passw5uv)
|
|
print(ctext5uv)
|
|
print("6x6",text6,passw6)
|
|
print(ctext6)
|