|
|
@ -1,5 +1,3 @@
|
|
|
|
import random as r
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def Encrypt(text, key):
|
|
|
|
def Encrypt(text, key):
|
|
|
|
result = ""
|
|
|
|
result = ""
|
|
|
|
for i in range(len(text)):
|
|
|
|
for i in range(len(text)):
|
|
|
@ -12,17 +10,6 @@ def Encrypt(text, key):
|
|
|
|
result += chr((ord(char) + key - 97) % 26 + 97)
|
|
|
|
result += chr((ord(char) + key - 97) % 26 + 97)
|
|
|
|
return result
|
|
|
|
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):
|
|
|
|
def Decrypt(text, key):
|
|
|
@ -37,47 +24,7 @@ def Decrypt(text, key):
|
|
|
|
result += chr((ord(char) - key - 97) % 26 + 97)
|
|
|
|
result += chr((ord(char) - key - 97) % 26 + 97)
|
|
|
|
return result
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
def DecryptVerif(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 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def testDecrypte(x):
|
|
|
|
|
|
|
|
if(Decrypt("Hello world",2)!="Jgnnq yqtnf"):
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
if(Decrypt("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(Decrypt(l,cle)!=DecryptVerif(l,cle)):
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print(Decrypt("Scripted",4))Oynelpaz
|
|
|
|
print(Encrypt("Hello world", 29))
|
|
|
|
|
|
|
|
print(Decrypt("Khoor zruog", 29))
|
|
|
|