From c8b415e0dfb88b63189785c93ee880c5edb93e63 Mon Sep 17 00:00:00 2001 From: xdrm Date: Thu, 21 May 2015 12:05:53 +0200 Subject: [PATCH] Create implementation.py --- implementation.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 implementation.py diff --git a/implementation.py b/implementation.py new file mode 100644 index 0000000..ff6c862 --- /dev/null +++ b/implementation.py @@ -0,0 +1,30 @@ +import random + +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 + return hash; + +alphabet = []; +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)): + random.shuffle( alphabet[i] ); + 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) ) + + +print encode(alphabet, key, code);