Bonne journée,
J'ai créé un programme simple de cryptage ASCII et j'ai juste 3 questions à son sujet :
- Comment puis-je vérifier si la clé est mal saisie et dire à mon programme de ne pas essayer de décrypter si elle a été mal saisie.
- Pourquoi le texte crypté est-il plus long que l'original ?
- Si je voulais crypter d'autres choses que du texte ASCII, à quel point cela serait-il difficile ?
Merci, voici mon code et mes résultats ci-dessous :
import time
key = "Thisisôthekey¦b££glkHPAfgbm(*&%$$*(ô"
string = "Encryption the hell out of me, even if I repeatttttttt lettersssss you can't tell"
entext = ""
detext = ""
keycnt=0
print("Displaing Text to be Encrypted")
time.sleep(1)
print(string)
time.sleep(5)
#Loops through the string and the key and adds the ascii values together to create a Encrypted character
for sLetter in string:
entext += chr(ord(sLetter) + ord(key[keycnt]))
keycnt += 1
if keycnt == len(key):
keycnt =0
print("Displaying encrypted Text")
time.sleep(1)
print(entext)
#Resetting key position
keycnt=0
#Loops through the string and the key and subtracts the ascii values together to create a decrypted character
for sLetter in entext:
detext += chr(ord(sLetter) - ord(key[keycnt]))
keycnt += 1
if keycnt == len(key):
keycnt =0
time.sleep(2)
print("Displaying decrypted Text")
time.sleep(1)
print(detext)
time.sleep(1)