Cryptage d'un texte par décalage clavier, python

Maelctn Messages postés 9 Date d'inscription   Statut Membre Dernière intervention   -  
NHenry Messages postés 15219 Date d'inscription   Statut Modérateur Dernière intervention   -
Bonjour, avec un ami on doit crypter un texte avec la méthode du décalage clavier. Voici notre sujet :
Ecrire un programme/script en Python qui ouvre un fichier texte contenant un message secret, lit son contenu, génère un sens de décalage que l'utilisateur choisit, et qui écrit dans un autre fichier texte le message chiffré avec la méthode du chiffre par décalage clavier.
Remarque : on prend AZERTY comme clavier de référence.

Problèmes, nous n'arrivons pas à commencer, pourtant ceci à l'air très simple mais nous ne maîtrisons pas du tout le python et sommes perdus.

On appelle à votre aide, merci.
A voir également:

1 réponse

NHenry Messages postés 15219 Date d'inscription   Statut Modérateur Dernière intervention   365
 
Regardes des sources parlant du chiffrement de César.
0
Maelctn Messages postés 9 Date d'inscription   Statut Membre Dernière intervention  
 
C'est ce que l'on fait depuis tout à l'heure mais nous n'y comprenons pas grand chose !
0
NHenry Messages postés 15219 Date d'inscription   Statut Modérateur Dernière intervention   365
 
Le principe est simple, remplacer un caractère par un autre.
Je ne vois pas ce qui peut bloquer.
0
Maelctn Messages postés 9 Date d'inscription   Statut Membre Dernière intervention  
 
Bonjour,
Le script a beaucoup avancé depuis et il reste un léger problème : le script crypte des espaces seulement. Je cherche le problème mais j'ai quand même du mal, je vous met ci-dessous le script :
D=input ('Entrez 1 pour haut, 2 pour droite, 3 pour bas, 4 pour gauche = ')
dictSpeCharList = {156:69, 192:65, 194:65, 198:69, 199:67, 200:69, 201:69, 202:69, 203:69, 206:73, 207:73, 212:79, 217:86, 219:86, 224:65, 226:65, 230:69, 231:67, 232:69, 233:69, 234:69, 235:69, 238:73, 239:73, 244:79, 249:86, 251:86}
dictMinToMaj = {97:65, 98:66, 99:67, 100:68, 101:69, 102:70, 103:71, 104:72, 105:73, 106:74, 107:75, 108:76, 109:77, 110:78, 111:79, 112:80, 113:81, 114:82, 115:83, 116:84, 117:85, 118:86, 119:87, 120:88, 121:89, 122:90}
dictHaut = {65:87, 66:71, 67:68, 68:69, 69:67, 70:82, 71:84, 72:89, 73:75, 74:85, 75:73, 76:79, 77:80, 78:72, 79:76, 80:77, 81:65, 82:86, 83:90, 84:66, 85:74, 86:70, 87:81, 88:83, 89:78, 90:88}
dictBas = {65:81, 66:84, 67:69, 68:67, 69:68, 70:86, 71:66, 72:78, 73:75, 74:85, 75:73, 76:79, 77:80, 78:89, 79:76, 80:77, 81:87, 82:70, 83:88, 84:71, 85:74, 86:82, 87:65, 88:90, 89:72, 90:83}
dictDroite = {65:90, 66:78, 67:86, 68:70, 69:82, 70:71, 71:72, 72:74, 73:79, 74:75, 75:76, 76:77, 77:81, 78:87, 79:80, 80:65, 81:83, 82:84, 83:68, 84:89, 85:73, 86:66, 87:88, 88:67, 89:85, 90:69}
dictGauche = {65:80, 66:86, 67:88, 68:83, 69:90, 70:68, 71:70, 72:71, 73:85, 74:72, 75:74, 76:75, 77:76, 78:66, 79:73, 80:79, 81:77, 82:69, 83:81, 84:82, 85:89, 86:67, 87:78, 88:87, 89:84, 90:65}

def intCodeCharModify (intCodeASCII, dictSpeCharList, dictMintoMaj):
     
    if (65 <= intCodeASCII <= 90) or intCodeASCII == 10:
        intChangedCode = intCodeASCII
    else: 
        if  intCodeASCII in dictSpeCharList:
            intChangedCode =  dictSpeCharList[intCodeASCII]
        else:
            if intCodeASCII in dictMinToMaj:
                intChangedCode = dictMintoMaj[intCodeASCII]   
            else:
                intChangedCode = 32
    return intChangedCode        
 

#Epuration du texte
strPathLu = 'E:\Dossier ISN\MP3 python\chatnoir.txt'               #Fichier de base avec le texte non-épuré
strPathEcrit = 'E:\Dossier ISN\MP3 python\epure.txt'              #Fichier avec le texte épuré
fileFichierLu = open(strPathLu, 'r')
fileFichierEcrit = open(strPathEcrit, 'w')
fileFichierEcrit.closed
fileFichierEcrit = open(strPathEcrit, 'a')
boolTest = True                                               
while boolTest == True:
        strChar = fileFichierLu.read(1)
        if not strChar:
            boolTest = False
        else:
            intNewCode = intCodeCharModify (ord(strChar), dictSpeCharList, dictMinToMaj)
            fileFichierEcrit.write(chr(intNewCode))
print('Opération de préparation du texte terminée')            
fileFichierLu.close()
fileFichierEcrit.close()
#Cryptage du texte
strPathLu='E:\Dossier ISN\MP3 python\epure.txt'                    #Fichier avec le texte épuré
strPathEcrit='E:\Dossier ISN\MP3 python\crypte.txt'                #Fichier avec le texte crypé
fileFichierLu=open(strPathLu,'r')
fileFichierEcrit=open(strPathEcrit,'w')
fileFichierEcrit.close()
fileFichierEcrit=open(strPathEcrit,'a')
boolTest=True
while boolTest==True :
    strChar=fileFichierLu.read(1)
    if not strChar :
        boolTest = False
    else:
        IntCodeASCII = ord(strChar)
        if IntCodeASCII==10 :                       
            IntK=IntCodeASCII
            fileFichierEcrit.write(chr(IntK))
        else:
            if IntCodeASCII==32 :         
                IntK=IntCodeASCII
                fileFichierEcrit.write(chr(IntK))
            else:
                if D == 1 :
                    IntK=IntCodeASCII =  dictHaut[IntCodeASCII]     #Utilisation du dictionnaire              <------ Mettre une condition
                    fileFichierEcrit.write(chr(IntK=IntCodeASCII))
                else:    
                    if D == 2 :
                            IntK=IntCodeASCII =  dictDroite[IntCodeASCII]     #Utilisation du dictionnaire              <------ Mettre une condition
                            fileFichierEcrit.write(chr(IntK=IntCodeASCII))
                    else:
                        if D == 3 :
                                IntK=IntCodeASCII =  dictBas[IntCodeASCII]     #Utilisation du dictionnaire              <------ Mettre une condition   
                                fileFichierEcrit.write(chr(IntK=IntCodeASCII))
                        else:
                            if D == 4 :
                                IntK=IntCodeASCII =  dictGauche[IntCodeASCII]     #Utilisation du dictionnaire              <------ Mettre une condition
                                fileFichierEcrit.write(chr(IntK=IntCodeASCII))
            
print('Le cryptage est terminé.')
fileFichierLu.close()
fileFichierEcrit.close()


EDIT : Ajout des balises de code (la coloration syntaxique).
Explications disponibles ici : ICI

Merci d'y penser dans tes prochains messages.
0
NHenry Messages postés 15219 Date d'inscription   Statut Modérateur Dernière intervention   365
 
Ne manipulant pas Python, j'ai un peu de mal à comprendre tout le code, surtout à une heure aussi tardive.
Essayes de voir en pas à pas et regardant les valeur des variables.
0