Pages : 1
#1 Le 22/09/2008, à 15:40
- rniamo
xor encryption challenge [Résolu]
j'essaye de faireun challenge :
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 144and 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.
Mais je n'y arrive pas, voici le code :
#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()-1)? 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;
}
Dernière modification par rniamo (Le 23/09/2008, à 09:16)
< Quelques un des mes programmes | Cuisine Facile (pour les gourmands) | Fast MVC for PHP >
\ ^__^
\ (o o)\_______
(___)\ )\
Hors ligne
#2 Le 22/09/2008, à 21:53
- rniamo
Re : xor encryption challenge [Résolu]
personne n'a d'idée ? Dans l'absolu le challenge n'a pas d'importance mais ça m'énerve de ne pas réussir.
< Quelques un des mes programmes | Cuisine Facile (pour les gourmands) | Fast MVC for PHP >
\ ^__^
\ (o o)\_______
(___)\ )\
Hors ligne