IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++ Discussion :

xor encryption inopérante


Sujet :

C++

  1. #1
    Débutant Avatar de Rniamo
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    508
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 508
    Points : 162
    Points
    162
    Par défaut xor encryption inopérante
    bonjour,

    au cvours de mes ballades on line j'ai trouvé un challenge qui m'a intrigué :

    XOR Encryption (which most people will tell you is not really encryption at all) is performed by taking a key and xoring each byte in a file with the each byte in the key. This is generally performed by moving through the key a character at a time, and repeating when the end is reached.

    Take this file and xor it with the string secret (restart at s when you come to t).

    Then exchange the following byte values in the file:

    # 23 with 0
    # 78 with 66
    # 36 with 144

    and the other way round!! i.e. 0 with 23

    Save the result as a file and rename it to .jpg Open it in a picture viewer and the resulting message is your solution.
    j'ai codé ça :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    #include <iostream>
    #include <fstream>
     
    int main() {
    	std::ifstream f("data.bin",std::ios::binary);
    	std::ofstream out("sortie.jpg",std::ios::binary);
    	std::string key("secret");
    				int i=0;
    	if (f.is_open() && out.is_open()) {
    		int y=0;
    		unsigned char c=f.get() ^ key[y];
    		while(f.eof()!=true) {
    			(y == key.size())? y=0 :y++;
    			switch(c) {
    				case 0x0:   c=0x17;  break; // 0 <-> 23
    				case 0x42:  c=0x4e;  break; // 66 <-> 78
    				case 0x90:  c=0x24;  break; // 144 <-> 36
    				case 0x17:  c=0x0;   break;
    				case 0x4e:  c=0x42;  break;
    				case 0x24:  c=0x90;  break;
    				default:break;
    			}
    			out << c;
    			c=f.get() ^ key[y];
    		}
    	}
     
    	return 1;
    }
    Mais ça ne marche pas. où est le problème ?

  2. #2
    Expert confirmé
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Décembre 2003
    Messages
    3 549
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Décembre 2003
    Messages : 3 549
    Points : 4 625
    Points
    4 625
    Par défaut
    remplace
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    (y == key.size())? y=0 :y++;
    par
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    (y == key.size()-1)? y=0 :y++;
    Boost ftw

  3. #3
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 518
    Points
    41 518
    Par défaut
    J'ai du mal à comprendre l'utilité de cette partie-là...
    Then exchange the following byte values in the file:

    # 23 with 0
    # 78 with 66
    # 36 with 144
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  4. #4
    Débutant Avatar de Rniamo
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    508
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 508
    Points : 162
    Points
    162
    Par défaut
    merci, petit problème d'indice

  5. #5
    Rédacteur

    Avatar de ram-0000
    Homme Profil pro
    Consultant en sécurité
    Inscrit en
    Mai 2007
    Messages
    11 517
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Consultant en sécurité
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mai 2007
    Messages : 11 517
    Points : 50 367
    Points
    50 367
    Par défaut
    Citation Envoyé par Rniamo Voir le message
    merci, petit problème d'indice
    Tu peux mettre la solution STP ?
    Raymond
    Vous souhaitez participer à la rubrique Réseaux ? Contactez-moi

    Cafuro Cafuro est un outil SNMP dont le but est d'aider les administrateurs système et réseau à configurer leurs équipements SNMP réseau.
    e-verbe Un logiciel de conjugaison des verbes de la langue française.

    Ma page personnelle sur DVP
    .

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [ZIP/AES] Créer un zip encrypté
    Par denisC dans le forum Entrée/Sortie
    Réponses: 7
    Dernier message: 05/06/2009, 16h54
  2. Réponses: 2
    Dernier message: 28/07/2005, 16h23
  3. Crash de mon dvd encrypté avec xine
    Par Slein dans le forum Applications et environnements graphiques
    Réponses: 3
    Dernier message: 06/06/2004, 17h45
  4. technique du XOR
    Par microseb dans le forum C++Builder
    Réponses: 2
    Dernier message: 10/08/2003, 00h55
  5. cherche algos encryption en RSA et ELGAMAL
    Par Vermin dans le forum Algorithmes et structures de données
    Réponses: 2
    Dernier message: 04/11/2002, 09h58

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo