2015-05-21 10:05:53 +00:00
|
|
|
import random
|
|
|
|
|
|
|
|
def encode(al, key, msg):
|
|
|
|
tmp = '';
|
|
|
|
hash = '';
|
|
|
|
for i in range(0, len(msg)): # parcourt chaque caractere du message
|
2015-05-21 10:18:11 +00:00
|
|
|
tmp = al[1].index( msg[i] );
|
|
|
|
hash += al[len(al)-1][tmp];
|
|
|
|
|
|
|
|
# decale le premier alphabet d'un cran, le deuxieme si le premier depasse
|
|
|
|
for i in range(1, len(al)):
|
|
|
|
print i;
|
2015-05-21 10:05:53 +00:00
|
|
|
return hash;
|
|
|
|
|
|
|
|
alphabet = [];
|
2015-05-21 10:18:11 +00:00
|
|
|
alphabet.append( [] )
|
2015-05-21 10:05:53 +00:00
|
|
|
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'] )
|
|
|
|
|
2015-05-21 10:18:11 +00:00
|
|
|
for i in range(1, len(alphabet)):
|
2015-05-21 10:05:53 +00:00
|
|
|
random.shuffle( alphabet[i] );
|
2015-05-21 10:18:11 +00:00
|
|
|
alphabet[0].append( alphabet[i][0] );
|
2015-05-21 10:05:53 +00:00
|
|
|
print alphabet[i]
|
|
|
|
print
|
|
|
|
|
|
|
|
code = raw_input("Votre message: ")
|
|
|
|
# demande la saisie des cles (positions initiales)
|
2015-05-21 10:18:11 +00:00
|
|
|
key = [];
|
|
|
|
for i in range(0, len(alphabet)):
|
|
|
|
key.append( raw_input('Cle n%d : ' % (i+1) ) )
|
|
|
|
print
|
2015-05-21 10:05:53 +00:00
|
|
|
|
|
|
|
print encode(alphabet, key, code);
|