-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cchiffr1.py
50 lines (40 loc) · 942 Bytes
/
Cchiffr1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Nov 29 18:32:56 2018
@author: remy
"""
def verifie(L) :
for k in L:
if type(k) != int or k < 0 or k > 25:
return False
return True
def chiffrement_cesar(L,d):
C = []
for k in L:
C.append((k+d) % 26)
return C
def dechiffrement_cesar(L,d):
return(chiffrement_cesar(L,-d))
def frequences(L):
lifreq = 26*[0]
for k in L:
lifreq[k] += 1
return lifreq
def indice_max(T):
imax = 0
for k in range(1,len(T)):
if T[k] > T[imax]:
imax = k
return imax
def dechiffrement_auto(L):
imax = indice_max(frequences(L))
#imax devrait désigner 4 pour 'e'
cle = (imax - 4) % 26
return dechiffrement_cesar(L,cle)
def chiffrement_vigenere(L,C):
c = []
for k in range(len(L)):
cle = k % len(C)
c.append((L[k] + cle) % 26)
return c