test Encrypte

ServeurDeTest
Pierre BALLANDRAS 3 years ago
parent 40d91f3691
commit 03195369a8

@ -1,3 +1,5 @@
import random as r
def Encrypt(text, key):
result = ""
for i in range(len(text)):
@ -10,6 +12,17 @@ def Encrypt(text, key):
result += chr((ord(char) + key - 97) % 26 + 97)
return result
def EncryptVerif(text, key):
result = ""
for i in range(len(text)):
char = text[i]
if(char==" "):
result+=" "
elif (char.isupper()):
result += chr((ord(char) + key-65) % 26 + 65)
else:
result += chr((ord(char) + key - 97) % 26 + 97)
return result
def Decrypt(text, key):
@ -25,6 +38,18 @@ def Decrypt(text, key):
return result
def testEncrypte(x):
if(Encrypt("Hello world",2)!="Jgnnq yqtnf"):
return False
if(Encrypt("Scripted",9)!="Blarycnm"):
return False
for i in range(x):
l=""
cle=r.randint(1,26)
for i in range(r.randint(1,10)):
l+=chr(r.randint(97,122))
if(Encrypt(l,cle)!=EncryptVerif(l,cle)):
return False
return True
print(Encrypt("Hello world", 29))
print(Decrypt("Khoor zruog", 29))
print(testEncrypte(10))

@ -1,6 +1,10 @@
def triangle(n):
if(n==0):
return []
if(n==1):
return [[1]]
triangle=[[1],[1, 1]]
columns=n
for line in range(2,n):
@ -10,6 +14,6 @@ def triangle(n):
triangle[line].append(1)
return triangle
print(triangle(2))
print(triangle(4))
print(triangle(0))
print(triangle(1))
print(triangle(8))

Loading…
Cancel
Save