我想異或一些已經加密的文件。
我知道XOR鍵是0x14或dec(20)。C++異或字符串鍵十六進制
我的代碼除了一件作品。所有'4'都沒有了。
這裏是我的XOR功能:
void xor(string &nString) // Time to undo what we did from above :D
{
const int KEY = 0x14;
int strLen = (nString.length());
char *cString = (char*)(nString.c_str());
for (int i = 0; i < strLen; i++)
{
*(cString+i) = (*(cString+i)^KEY);
}
}
這裏是我的主要的部分:
ifstream inFile;
inFile.open("ExpTable.bin");
if (!inFile) {
cout << "Unable to open file";
}
string data;
while (inFile >> data) {
xor(data);
cout << data << endl;
}
inFile.close();
這裏是encypted文件的一部分:
$y{bq //0 move
%c|{ //1 who
&c|qfq //2 where
'saufp //3 guard
x{wu`}{z //4 location
但x{wu
} {z`正在返回//位置。它不顯示4.
請注意X. thats應該被解碼爲4的空間盈虧。
我錯過了什麼?爲什麼不顯示所有4? <space> = 4 // 4 = <space>
UPDATE
這是所有具體的轉換列表:
HEX(enc) ASCII(dec)
20 4
21 5
22 6
23 7
24 0
25 1
26 2
27 3
28 <
29 =
2a >
2b ?
2c 8
2d 9
2e :
2f ;
30 $
31 %
32 &
33 '
34
35 !
36 "
37 #
38 ,
39 -
3a .
3b /
3c (
3d )
3e *
3f +
40 T
41 U
42 V
43 W
44 P
45 Q
46 R
47 S
48 \
49 ]
4a ^
4b _
4c X
4d Y
4e Z
4f [
50 D
51 E
52 F
53 G
54 @
55 A
56 B
57 C
58 L
59 M
5a N
5b O
5c H
5d I
5e J
5f K
60 t
61 u
62 v
63 w
64 p
65 q
66 r
67 s
68 |
69 }
6a
6b
6c x
6d y
6e z
6f {
70 d
71 e
72 f
73 g
75 a
76 b
77 c
78 l
79 m
7a n
7b o
7c h
7d i
7e j
7f k
1d /tab
1e /newline
+1 - 關鍵是'inFile >> data'跳過空格。 –
in |二進制,都是不明的。 XD – madziikoy
你需要'#include'正確的頭文件和'使用'正確的命名空間。 – melpomene