Update implementation.py
commencé à gérer le décalage des alphabets.. A finir
This commit is contained in:
parent
c8b415e0df
commit
84d1642afe
|
@ -4,27 +4,31 @@ def encode(al, key, msg):
|
||||||
tmp = '';
|
tmp = '';
|
||||||
hash = '';
|
hash = '';
|
||||||
for i in range(0, len(msg)): # parcourt chaque caractere du message
|
for i in range(0, len(msg)): # parcourt chaque caractere du message
|
||||||
tmp = msg[i]
|
tmp = al[1].index( msg[i] );
|
||||||
for j in range(1, len(al)): # parcourt les alphabets du premier au dernier
|
hash += al[len(al)-1][tmp];
|
||||||
tmp = al[j][ al[j-1].index(tmp) ];
|
|
||||||
hash += tmp
|
# decale le premier alphabet d'un cran, le deuxieme si le premier depasse
|
||||||
|
for i in range(1, len(al)):
|
||||||
|
print i;
|
||||||
return hash;
|
return hash;
|
||||||
|
|
||||||
alphabet = [];
|
alphabet = [];
|
||||||
|
alphabet.append( [] )
|
||||||
alphabet.append( ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] )
|
alphabet.append( ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] )
|
||||||
alphabet.append( ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] )
|
alphabet.append( ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] )
|
||||||
alphabet.append( ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] )
|
alphabet.append( ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] )
|
||||||
|
|
||||||
for i in range(0, len(alphabet)):
|
for i in range(1, len(alphabet)):
|
||||||
random.shuffle( alphabet[i] );
|
random.shuffle( alphabet[i] );
|
||||||
|
alphabet[0].append( alphabet[i][0] );
|
||||||
print alphabet[i]
|
print alphabet[i]
|
||||||
print
|
print
|
||||||
|
|
||||||
code = raw_input("Votre message: ")
|
code = raw_input("Votre message: ")
|
||||||
# demande la saisie des cles (positions initiales)
|
# demande la saisie des cles (positions initiales)
|
||||||
key = [0,0,0,0];
|
key = [];
|
||||||
for i in range(0, len(key)):
|
for i in range(0, len(alphabet)):
|
||||||
key[i] = raw_input('Cle n%d : ' % (i+1) )
|
key.append( raw_input('Cle n%d : ' % (i+1) ) )
|
||||||
|
print
|
||||||
|
|
||||||
print encode(alphabet, key, code);
|
print encode(alphabet, key, code);
|
||||||
|
|
Loading…
Reference in New Issue