xor encryption inopérante
	
	
		bonjour,
au cvours de mes ballades on line j'ai trouvé un challenge qui m'a intrigué :
	Citation:
	
		
		
			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:
	
| 12
 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 ?