From 84d1642afe40a57bd0d1f707a35da5fba4671f51 Mon Sep 17 00:00:00 2001 From: xdrm Date: Thu, 21 May 2015 12:18:11 +0200 Subject: [PATCH] Update implementation.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit commencé à gérer le décalage des alphabets.. A finir --- implementation.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/implementation.py b/implementation.py index ff6c862..5647f73 100644 --- a/implementation.py +++ b/implementation.py @@ -4,27 +4,31 @@ def encode(al, key, msg): tmp = ''; hash = ''; for i in range(0, len(msg)): # parcourt chaque caractere du message - tmp = msg[i] - for j in range(1, len(al)): # parcourt les alphabets du premier au dernier - tmp = al[j][ al[j-1].index(tmp) ]; - hash += tmp + 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; return hash; 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'] ) -for i in range(0, len(alphabet)): +for i in range(1, len(alphabet)): random.shuffle( alphabet[i] ); + alphabet[0].append( alphabet[i][0] ); print alphabet[i] print code = raw_input("Votre message: ") # demande la saisie des cles (positions initiales) -key = [0,0,0,0]; -for i in range(0, len(key)): - key[i] = raw_input('Cle n%d : ' % (i+1) ) - +key = []; +for i in range(0, len(alphabet)): + key.append( raw_input('Cle n%d : ' % (i+1) ) ) +print print encode(alphabet, key, code);