.
This commit is contained in:
1
bac1/q1/24nov/analyse.txt
Normal file
1
bac1/q1/24nov/analyse.txt
Normal file
File diff suppressed because one or more lines are too long
1
bac1/q1/24nov/decalage.txt
Normal file
1
bac1/q1/24nov/decalage.txt
Normal file
@ -0,0 +1 @@
|
||||
xzujwrtsnruqjrjsyfyntsjxyhtwwjhyjojujzcrfnsyjsfsyufxxjwfqjcjwhnhjxznafsy
|
26
bac1/q1/24nov/dico.txt
Normal file
26
bac1/q1/24nov/dico.txt
Normal file
@ -0,0 +1,26 @@
|
||||
a d
|
||||
b c
|
||||
c q
|
||||
d r
|
||||
e k
|
||||
f n
|
||||
g g
|
||||
h v
|
||||
i u
|
||||
j t
|
||||
k x
|
||||
l o
|
||||
m i
|
||||
n l
|
||||
o a
|
||||
p j
|
||||
q y
|
||||
r b
|
||||
s s
|
||||
t z
|
||||
u m
|
||||
v p
|
||||
w h
|
||||
x w
|
||||
y f
|
||||
z e
|
105
bac1/q1/24nov/encryption.py
Normal file
105
bac1/q1/24nov/encryption.py
Normal file
@ -0,0 +1,105 @@
|
||||
def lecture(nom : str) -> str:
|
||||
"""get all character of a file
|
||||
|
||||
:nom: file name
|
||||
:returns: string of the file's content
|
||||
|
||||
"""
|
||||
with open(nom, 'r') as file:
|
||||
return file.read()
|
||||
|
||||
|
||||
def nettoyage(texte : str) -> str:
|
||||
"""clean the text from it's space and uppsercase
|
||||
|
||||
:texte: Sentence to cclean
|
||||
:returns: the string cleaned
|
||||
|
||||
"""
|
||||
texte = texte.lower()
|
||||
alphabet = 'abcdefghijklmnopqrstuvwxyz'
|
||||
ret = ''
|
||||
for char in texte:
|
||||
if char in alphabet:
|
||||
ret += char
|
||||
return ret
|
||||
|
||||
|
||||
def chiffrement_decalage(texte : str, u : int) -> str:
|
||||
"""Encrypt a string with cesar
|
||||
|
||||
:texte: String to encrypt
|
||||
:u: Key for ceasar encryption
|
||||
:returns: encrypted text
|
||||
|
||||
"""
|
||||
alphabet = 'abcdefghijklmnopqrstuvwxyz'
|
||||
decalage = dict()
|
||||
for k, l in enumerate(alphabet):
|
||||
decalage[l] = alphabet[(k+u) % len(alphabet)]
|
||||
ret = ''
|
||||
for l in texte:
|
||||
ret += decalage[l]
|
||||
return ret
|
||||
|
||||
|
||||
def dechiffrement_decalage(texte, u):
|
||||
"""decrypt text encoded with cesar
|
||||
|
||||
:texte: the string to decode
|
||||
:u: ceasar key to decode
|
||||
:returns: the string decoded with the key
|
||||
|
||||
"""
|
||||
return chiffrement_decalage(texte, -u)
|
||||
|
||||
|
||||
def chiffrement_substitution(texte, dico):
|
||||
ret = ''
|
||||
for l in texte:
|
||||
if l in dico:
|
||||
ret += dico[l]
|
||||
else:
|
||||
ret += l
|
||||
return ret
|
||||
|
||||
|
||||
def dechiffrement_substitution(texte, dico):
|
||||
invert = dict()
|
||||
for k, v in dico.items():
|
||||
invert[v] = k
|
||||
return chiffrement_substitution(texte, invert)
|
||||
|
||||
|
||||
|
||||
def file_to_dict(filename):
|
||||
ret = dict()
|
||||
with open(filename) as f:
|
||||
for l in f:
|
||||
ret[l.split()[0]] = l.split()[1]
|
||||
return ret
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
if(len(sys.argv) == 5):
|
||||
if sys.argv[1] == 'd':
|
||||
if sys.argv[2] == 'c':
|
||||
text = nettoyage(lecture(sys.argv[3]))
|
||||
print(chiffrement_decalage(text, int(sys.argv[4])))
|
||||
if sys.argv[2] == 'd':
|
||||
text = nettoyage(lecture(sys.argv[3]))
|
||||
print(dechiffrement_decalage(text, sys.argv[4]))
|
||||
|
||||
if sys.argv[1] == 's':
|
||||
if sys.argv[2] == 'c':
|
||||
text = nettoyage(lecture(sys.argv[3]))
|
||||
dico = file_to_dict(sys.argv[4])
|
||||
print(chiffrement_substitution(text, dico))
|
||||
if sys.argv[2] == 'd':
|
||||
text = nettoyage(lecture(sys.argv[3]))
|
||||
dico = file_to_dict(sys.argv[4])
|
||||
print(dechiffrement_substitution(text, dico))
|
||||
|
||||
|
BIN
bac1/q1/24nov/serie9.pdf
Normal file
BIN
bac1/q1/24nov/serie9.pdf
Normal file
Binary file not shown.
1
bac1/q1/24nov/substitution.txt
Normal file
1
bac1/q1/24nov/substitution.txt
Normal file
@ -0,0 +1 @@
|
||||
zbdpduookbrmbldtdiduszmkjkbsallkidusjambymaujbklrbkokbusymk
|
24
bac1/q1/24nov/test.py
Normal file
24
bac1/q1/24nov/test.py
Normal file
@ -0,0 +1,24 @@
|
||||
from encryption import (
|
||||
lecture,
|
||||
nettoyage,
|
||||
chiffrement_decalage,
|
||||
chiffrement_substitution
|
||||
)
|
||||
|
||||
def test1():
|
||||
print(lecture("test.txt"))
|
||||
|
||||
def test2():
|
||||
print(nettoyage(" this is a TestsS "))
|
||||
|
||||
def test3():
|
||||
print(chiffrement_decalage("blablabla", -42))
|
||||
|
||||
def test4():
|
||||
print(chiffrement_substitution("blablabla", {'a': 'b', 'b': 'd'}))
|
||||
|
||||
if __name__ == "__main__":
|
||||
# test1()
|
||||
# test2()
|
||||
# test3()
|
||||
test4()
|
1
bac1/q1/24nov/vigenere.txt
Normal file
1
bac1/q1/24nov/vigenere.txt
Normal file
@ -0,0 +1 @@
|
||||
yzadgqxqmmtpxazvblxitapsgmnedinexsikallqotgvrp
|
Reference in New Issue
Block a user