مشفر النصوص (لتحويل النصوص إلى شفرة)

    • مشفر النصوص (لتحويل النصوص إلى شفرة)

      السلام عليكم


      برنامج يسمح لك بتشفير النص بكلمة مرور و بنفس كلمة المرور يمكنك فك شفرة النص
      البرنامج تجدونه على المرفقات شفرة لا بأس بجودتها ... في أمان الله




      جميع الحقوق محفوضة ناقوس الخطر
    • وهذه وظائف التشفير لمن يريد الإستفادة منها

      C++6

      MFC


      PHP كود المصدر

      1. CString _StringEncrypt(CString STR,CString Password);
      2. CString _StringDecrypt(CString STR,CString Password);
      3. static unsigned int BitXOR(unsigned int x, unsigned int y, unsigned int z);



      هذه الوظيفة الأولى لتشفير النص

      PHP كود المصدر

      1. CString _StringEncrypt(CString STR ,CString Password)
      2. {
      3. CString StrResult,TXT,OutTxt;
      4. INT L = 0;
      5. UINT N=0;
      6. for (int M = 1; M <= STR.GetLength(); M++)
      7. {
      8. TXT = STR.Left(M).Right(1);
      9. int Modified = BitXOR(TXT.GetAt(0),Password.GetAt(L), 255);
      10. if (L == Password.GetLength() - 1) {L = 0;} else {L++;}
      11. StrResult = "";
      12. StrResult.Format(_T("%d"), Modified);
      13. sscanf(StrResult.GetBuffer(0),"%d",&N);
      14. StrResult.Format("%X",N);
      15. OutTxt.Insert(OutTxt.GetLength(),StrResult.Right(2));
      16. }
      17. return OutTxt;
      18. }
      عرض الكل



      وهذه الوظيفة الثانية لفك التشفير


      PHP كود المصدر

      1. CString _StringDecrypt(CString STR ,CString Password)
      2. {
      3. CString StrResult,OutTxt,iStr;
      4. INT L = 0;
      5. UINT N=0;
      6. for (int M = 2; M <= STR.GetLength(); M += 2)
      7. {
      8. iStr = STR.Left(M).Right(2);
      9. sscanf(iStr.GetBuffer(0),"%x",&N);
      10. iStr.Format("%u",N);
      11. int Modified = BitXOR(_ttoi(iStr),Password.GetAt(L), 255);
      12. if (L == Password.GetLength() - 1) {L = 0;} else {L++;}
      13. OutTxt.Insert(OutTxt.GetLength(),(char) Modified);
      14. }
      15. return OutTxt;
      16. }
      عرض الكل



      وهذه وظيفة لعملية bitwise exclusive OR

      PHP كود المصدر

      1. inline unsigned int BitXOR(unsigned int x, unsigned int y, unsigned int z)
      2. {
      3. return x ^ y ^ z;
      4. }


      في أمان الله

    • طريقة اخرى أفضل من السابقة لتشفير مترجمة من Autoit و إلى C++6

      من المرفقات تجدون المثال جاهز مع التطبيق

      وهذه هي جميع الوظائف

      في أمان الله

      AutoitEncrypt_C++Decrypt

      PHP كود المصدر

      1. FileDelete("Encrypt.txt")
      2. FileDelete("Decrypt.txt")
      3. $sHTML = ""
      4. $sHTML &= "<HTML>" & @CRLF
      5. $sHTML &= "<HEAD>" & @CRLF
      6. $sHTML &= "<TITLE>_IE_Example('frameset')</TITLE>" & @CRLF
      7. $sHTML &= "</HEAD>" & @CRLF
      8. $sHTML &= "<FRAMESET rows='25,200'>" & @CRLF
      9. $sHTML &= " <FRAME NAME=Top SRC=about:blank>" & @CRLF
      10. $sHTML &= " <FRAMESET cols='100,500'>" & @CRLF
      11. $sHTML &= " <FRAME NAME=Menu SRC=about:blank>" & @CRLF
      12. $sHTML &= " <FRAME NAME=Main SRC=about:blank>" & @CRLF
      13. $sHTML &= " </FRAMESET>" & @CRLF
      14. $sHTML &= "</FRAMESET>" & @CRLF
      15. $sHTML &= "</HTML>"
      16. ;Decrypt;COMMAND _StringEncrypt_.exe Space i_Encrypt = 0 Space sFilePath Space Password Space Level
      17. $TXT = _StringEncrypt(1, $sHTML, "Autoit", 5)
      18. $FO = FileOpen("Encrypt.txt",1)
      19. FileWriteLine($FO, $TXT)
      20. FileClose($FO)
      21. $COMMAND = "_StringEncrypt_.exe" & " " & "0" & " " & "Encrypt.txt" & " " & "Autoit" & " " & "5"
      22. Run($COMMAND, "", @SW_HIDE)
      23. Func _StringEncrypt($i_Encrypt, $s_EncryptText, $s_EncryptPassword, $i_EncryptLevel = 1)
      24. If $i_Encrypt <> 0 And $i_Encrypt <> 1 Then
      25. SetError(1)
      26. Return ''
      27. ElseIf $s_EncryptText = '' Or $s_EncryptPassword = '' Then
      28. SetError(1)
      29. Return ''
      30. Else
      31. If Number($i_EncryptLevel) <= 0 Or Int($i_EncryptLevel) <> $i_EncryptLevel Then $i_EncryptLevel = 1
      32. Local $v_EncryptModified
      33. Local $i_EncryptCountH
      34. Local $i_EncryptCountG
      35. Local $v_EncryptSwap
      36. Local $av_EncryptBox[256][2]
      37. Local $i_EncryptCountA
      38. Local $i_EncryptCountB
      39. Local $i_EncryptCountC
      40. Local $i_EncryptCountD
      41. Local $i_EncryptCountE
      42. Local $v_EncryptCipher
      43. Local $v_EncryptCipherBy
      44. If $i_Encrypt = 1 Then
      45. For $i_EncryptCountF = 0 To $i_EncryptLevel Step 1
      46. $i_EncryptCountG = ''
      47. $i_EncryptCountH = ''
      48. $v_EncryptModified = ''
      49. For $i_EncryptCountG = 1 To StringLen($s_EncryptText)
      50. If $i_EncryptCountH = StringLen($s_EncryptPassword) Then
      51. $i_EncryptCountH = 1
      52. Else
      53. $i_EncryptCountH += 1
      54. EndIf
      55. $v_EncryptModified = $v_EncryptModified & Chr(BitXOR(Asc(StringMid($s_EncryptText, $i_EncryptCountG, 1)), Asc(StringMid($s_EncryptPassword, $i_EncryptCountH, 1)), 255))
      56. Next
      57. $s_EncryptText = $v_EncryptModified
      58. $i_EncryptCountA = ''
      59. $i_EncryptCountB = 0
      60. $i_EncryptCountC = ''
      61. $i_EncryptCountD = ''
      62. $i_EncryptCountE = ''
      63. $v_EncryptCipherBy = ''
      64. $v_EncryptCipher = ''
      65. $v_EncryptSwap = ''
      66. $av_EncryptBox = ''
      67. Local $av_EncryptBox[256][2]
      68. For $i_EncryptCountA = 0 To 255
      69. $av_EncryptBox[$i_EncryptCountA][1] = Asc(StringMid($s_EncryptPassword, Mod($i_EncryptCountA, StringLen($s_EncryptPassword)) + 1, 1))
      70. $av_EncryptBox[$i_EncryptCountA][0] = $i_EncryptCountA
      71. Next
      72. For $i_EncryptCountA = 0 To 255
      73. $i_EncryptCountB = Mod(($i_EncryptCountB + $av_EncryptBox[$i_EncryptCountA][0] + $av_EncryptBox[$i_EncryptCountA][1]), 256)
      74. $v_EncryptSwap = $av_EncryptBox[$i_EncryptCountA][0]
      75. $av_EncryptBox[$i_EncryptCountA][0] = $av_EncryptBox[$i_EncryptCountB][0]
      76. $av_EncryptBox[$i_EncryptCountB][0] = $v_EncryptSwap
      77. Next
      78. For $i_EncryptCountA = 1 To StringLen($s_EncryptText)
      79. $i_EncryptCountC = Mod(($i_EncryptCountC + 1), 256)
      80. $i_EncryptCountD = Mod(($i_EncryptCountD + $av_EncryptBox[$i_EncryptCountC][0]), 256)
      81. $i_EncryptCountE = $av_EncryptBox[Mod(($av_EncryptBox[$i_EncryptCountC][0] + $av_EncryptBox[$i_EncryptCountD][0]), 256)][0]
      82. $v_EncryptCipherBy = BitXOR(Asc(StringMid($s_EncryptText, $i_EncryptCountA, 1)), $i_EncryptCountE)
      83. $v_EncryptCipher &= Hex($v_EncryptCipherBy, 2)
      84. Next
      85. $s_EncryptText = $v_EncryptCipher
      86. Next
      87. Else
      88. For $i_EncryptCountF = 0 To $i_EncryptLevel Step 1
      89. $i_EncryptCountB = 0
      90. $i_EncryptCountC = ''
      91. $i_EncryptCountD = ''
      92. $i_EncryptCountE = ''
      93. $v_EncryptCipherBy = ''
      94. $v_EncryptCipher = ''
      95. $v_EncryptSwap = ''
      96. $av_EncryptBox = ''
      97. Local $av_EncryptBox[256][2]
      98. For $i_EncryptCountA = 0 To 255
      99. $av_EncryptBox[$i_EncryptCountA][1] = Asc(StringMid($s_EncryptPassword, Mod($i_EncryptCountA, StringLen($s_EncryptPassword)) + 1, 1))
      100. $av_EncryptBox[$i_EncryptCountA][0] = $i_EncryptCountA
      101. Next
      102. For $i_EncryptCountA = 0 To 255
      103. $i_EncryptCountB = Mod(($i_EncryptCountB + $av_EncryptBox[$i_EncryptCountA][0] + $av_EncryptBox[$i_EncryptCountA][1]), 256)
      104. $v_EncryptSwap = $av_EncryptBox[$i_EncryptCountA][0]
      105. $av_EncryptBox[$i_EncryptCountA][0] = $av_EncryptBox[$i_EncryptCountB][0]
      106. $av_EncryptBox[$i_EncryptCountB][0] = $v_EncryptSwap
      107. Next
      108. For $i_EncryptCountA = 1 To StringLen($s_EncryptText) Step 2
      109. $i_EncryptCountC = Mod(($i_EncryptCountC + 1), 256)
      110. $i_EncryptCountD = Mod(($i_EncryptCountD + $av_EncryptBox[$i_EncryptCountC][0]), 256)
      111. $i_EncryptCountE = $av_EncryptBox[Mod(($av_EncryptBox[$i_EncryptCountC][0] + $av_EncryptBox[$i_EncryptCountD][0]), 256)][0]
      112. $v_EncryptCipherBy = BitXOR(Dec(StringMid($s_EncryptText, $i_EncryptCountA, 2)), $i_EncryptCountE)
      113. $v_EncryptCipher = $v_EncryptCipher & Chr($v_EncryptCipherBy)
      114. Next
      115. $s_EncryptText = $v_EncryptCipher
      116. $i_EncryptCountG = ''
      117. $i_EncryptCountH = ''
      118. $v_EncryptModified = ''
      119. For $i_EncryptCountG = 1 To StringLen($s_EncryptText)
      120. If $i_EncryptCountH = StringLen($s_EncryptPassword) Then
      121. $i_EncryptCountH = 1
      122. Else
      123. $i_EncryptCountH += 1
      124. EndIf
      125. $v_EncryptModified &= Chr(BitXOR(Asc(StringMid($s_EncryptText, $i_EncryptCountG, 1)), Asc(StringMid($s_EncryptPassword, $i_EncryptCountH, 1)), 255))
      126. Next
      127. $s_EncryptText = $v_EncryptModified
      128. Next
      129. EndIf
      130. Return $s_EncryptText
      131. EndIf
      132. EndFunc ;==>_StringEncryptƒo??÷ ?/¾w+E›@??"´7œ¯*mjëh?×6FileDelete("Encrypt.txt")
      133. FileDelete("Decrypt.txt")
      134. $TXT = "" & @CRLF
      135. $TXT &= "Features: " & @CRLF
      136. $TXT &= " " & @CRLF
      137. $TXT &= "Easy to learn BASIC-like syntax " & @CRLF
      138. $TXT &= "Simulate keystrokes and mouse movements " & @CRLF
      139. $TXT &= "Manipulate windows and processes " & @CRLF
      140. $TXT &= "Interact with all standard windows controls " & @CRLF
      141. $TXT &= "Scripts can be compiled into standalone executables " & @CRLF
      142. $TXT &= "Create Graphical User Interfaces (GUIs) " & @CRLF
      143. $TXT &= "COM support " & @CRLF
      144. $TXT &= "Regular expressions " & @CRLF
      145. $TXT &= "Directly call external DLL and Windows API functions " & @CRLF
      146. $TXT &= "Scriptable RunAs functions " & @CRLF
      147. $TXT &= "Detailed helpfile and large community-based support forums " & @CRLF
      148. $TXT &= "Compatible with Windows 95 / 98 / ME / NT4 / 2000 / XP / 2003 / Vista / 2008 " & @CRLF
      149. $TXT &= "Unicode and x64 support " & @CRLF
      150. $TXT &= "Digitally signed for peace of mind " & @CRLF
      151. $TXT &= "Works with Windows Vista's User Account Control (UAC) " & @CRLF
      152. $FO = FileOpen("Decrypt.txt",2)
      153. $FR = FileWriteLine($FO ,$TXT)
      154. FileClose($FO)
      155. ;Encrypt;COMMAND _StringEncrypt_.exe Space i_Encrypt = 1 Space sFilePath Space Password Space Level
      156. $COMMAND = "_StringEncrypt_.exe" & " " & "1" & " " & "Decrypt.txt" & " " & "Autoit" & " " & "5"
      157. RunWait($COMMAND, "", @SW_HIDE)
      158. $FO = FileOpen("Encrypt.txt",0)
      159. $FR = FileReadLine($FO)
      160. FileClose($FO)
      161. $TXT = _StringEncrypt(0, $FR, "Autoit", 5)
      162. FileDelete("Decrypt.txt")
      163. $FO = FileOpen("Decrypt.txt",2)
      164. $FR = FileWriteLine($FO,$TXT)
      165. FileClose($FO)
      166. Func _StringEncrypt($i_Encrypt, $s_EncryptText, $s_EncryptPassword, $i_EncryptLevel = 1)
      167. If $i_Encrypt <> 0 And $i_Encrypt <> 1 Then
      168. SetError(1)
      169. Return ''
      170. ElseIf $s_EncryptText = '' Or $s_EncryptPassword = '' Then
      171. SetError(1)
      172. Return ''
      173. Else
      174. If Number($i_EncryptLevel) <= 0 Or Int($i_EncryptLevel) <> $i_EncryptLevel Then $i_EncryptLevel = 1
      175. Local $v_EncryptModified
      176. Local $i_EncryptCountH
      177. Local $i_EncryptCountG
      178. Local $v_EncryptSwap
      179. Local $av_EncryptBox[256][2]
      180. Local $i_EncryptCountA
      181. Local $i_EncryptCountB
      182. Local $i_EncryptCountC
      183. Local $i_EncryptCountD
      184. Local $i_EncryptCountE
      185. Local $v_EncryptCipher
      186. Local $v_EncryptCipherBy
      187. If $i_Encrypt = 1 Then
      188. For $i_EncryptCountF = 0 To $i_EncryptLevel Step 1
      189. $i_EncryptCountG = ''
      190. $i_EncryptCountH = ''
      191. $v_EncryptModified = ''
      192. For $i_EncryptCountG = 1 To StringLen($s_EncryptText)
      193. If $i_EncryptCountH = StringLen($s_EncryptPassword) Then
      194. $i_EncryptCountH = 1
      195. Else
      196. $i_EncryptCountH += 1
      197. EndIf
      198. $v_EncryptModified = $v_EncryptModified & Chr(BitXOR(Asc(StringMid($s_EncryptText, $i_EncryptCountG, 1)), Asc(StringMid($s_EncryptPassword, $i_EncryptCountH, 1)), 255))
      199. Next
      200. $s_EncryptText = $v_EncryptModified
      201. $i_EncryptCountA = ''
      202. $i_EncryptCountB = 0
      203. $i_EncryptCountC = ''
      204. $i_EncryptCountD = ''
      205. $i_EncryptCountE = ''
      206. $v_EncryptCipherBy = ''
      207. $v_EncryptCipher = ''
      208. $v_EncryptSwap = ''
      209. $av_EncryptBox = ''
      210. Local $av_EncryptBox[256][2]
      211. For $i_EncryptCountA = 0 To 255
      212. $av_EncryptBox[$i_EncryptCountA][1] = Asc(StringMid($s_EncryptPassword, Mod($i_EncryptCountA, StringLen($s_EncryptPassword)) + 1, 1))
      213. $av_EncryptBox[$i_EncryptCountA][0] = $i_EncryptCountA
      214. Next
      215. For $i_EncryptCountA = 0 To 255
      216. $i_EncryptCountB = Mod(($i_EncryptCountB + $av_EncryptBox[$i_EncryptCountA][0] + $av_EncryptBox[$i_EncryptCountA][1]), 256)
      217. $v_EncryptSwap = $av_EncryptBox[$i_EncryptCountA][0]
      218. $av_EncryptBox[$i_EncryptCountA][0] = $av_EncryptBox[$i_EncryptCountB][0]
      219. $av_EncryptBox[$i_EncryptCountB][0] = $v_EncryptSwap
      220. Next
      221. For $i_EncryptCountA = 1 To StringLen($s_EncryptText)
      222. $i_EncryptCountC = Mod(($i_EncryptCountC + 1), 256)
      223. $i_EncryptCountD = Mod(($i_EncryptCountD + $av_EncryptBox[$i_EncryptCountC][0]), 256)
      224. $i_EncryptCountE = $av_EncryptBox[Mod(($av_EncryptBox[$i_EncryptCountC][0] + $av_EncryptBox[$i_EncryptCountD][0]), 256)][0]
      225. $v_EncryptCipherBy = BitXOR(Asc(StringMid($s_EncryptText, $i_EncryptCountA, 1)), $i_EncryptCountE)
      226. $v_EncryptCipher &= Hex($v_EncryptCipherBy, 2)
      227. Next
      228. $s_EncryptText = $v_EncryptCipher
      229. Next
      230. Else
      231. For $i_EncryptCountF = 0 To $i_EncryptLevel Step 1
      232. $i_EncryptCountB = 0
      233. $i_EncryptCountC = ''
      234. $i_EncryptCountD = ''
      235. $i_EncryptCountE = ''
      236. $v_EncryptCipherBy = ''
      237. $v_EncryptCipher = ''
      238. $v_EncryptSwap = ''
      239. $av_EncryptBox = ''
      240. Local $av_EncryptBox[256][2]
      241. For $i_EncryptCountA = 0 To 255
      242. $av_EncryptBox[$i_EncryptCountA][1] = Asc(StringMid($s_EncryptPassword, Mod($i_EncryptCountA, StringLen($s_EncryptPassword)) + 1, 1))
      243. $av_EncryptBox[$i_EncryptCountA][0] = $i_EncryptCountA
      244. Next
      245. For $i_EncryptCountA = 0 To 255
      246. $i_EncryptCountB = Mod(($i_EncryptCountB + $av_EncryptBox[$i_EncryptCountA][0] + $av_EncryptBox[$i_EncryptCountA][1]), 256)
      247. $v_EncryptSwap = $av_EncryptBox[$i_EncryptCountA][0]
      248. $av_EncryptBox[$i_EncryptCountA][0] = $av_EncryptBox[$i_EncryptCountB][0]
      249. $av_EncryptBox[$i_EncryptCountB][0] = $v_EncryptSwap
      250. Next
      251. For $i_EncryptCountA = 1 To StringLen($s_EncryptText) Step 2
      252. $i_EncryptCountC = Mod(($i_EncryptCountC + 1), 256)
      253. $i_EncryptCountD = Mod(($i_EncryptCountD + $av_EncryptBox[$i_EncryptCountC][0]), 256)
      254. $i_EncryptCountE = $av_EncryptBox[Mod(($av_EncryptBox[$i_EncryptCountC][0] + $av_EncryptBox[$i_EncryptCountD][0]), 256)][0]
      255. $v_EncryptCipherBy = BitXOR(Dec(StringMid($s_EncryptText, $i_EncryptCountA, 2)), $i_EncryptCountE)
      256. $v_EncryptCipher = $v_EncryptCipher & Chr($v_EncryptCipherBy)
      257. Next
      258. $s_EncryptText = $v_EncryptCipher
      259. $i_EncryptCountG = ''
      260. $i_EncryptCountH = ''
      261. $v_EncryptModified = ''
      262. For $i_EncryptCountG = 1 To StringLen($s_EncryptText)
      263. If $i_EncryptCountH = StringLen($s_EncryptPassword) Then
      264. $i_EncryptCountH = 1
      265. Else
      266. $i_EncryptCountH += 1
      267. EndIf
      268. $v_EncryptModified &= Chr(BitXOR(Asc(StringMid($s_EncryptText, $i_EncryptCountG, 1)), Asc(StringMid($s_EncryptPassword, $i_EncryptCountH, 1)), 255))
      269. Next
      270. $s_EncryptText = $v_EncryptModified
      271. Next
      272. EndIf
      273. Return $s_EncryptText
      274. EndIf
      275. EndFunc ;==>_StringEncrypt
      عرض الكل




      C++6 functions

      Declaration

      PHP كود المصدر

      1. CString _StringEncrypt(CString STR,CString Password,int Level = 1);
      2. CString _StringDecrypt(CString STR,CString Password,int Level = 1);
      3. int BitXOR(int x,int y,int z);
      4. int Mod(int x , int y);
      5. int Bit_XOR(int x ,int y);


      Definition

      PHP كود المصدر

      1. [code]CString _StringEncrypt(CString STR ,CString Password,int Level)
      2. {
      3. for (int M = 0; M <= Level; M++)
      4. {
      5. CString StrResult,StrL,STR2;
      6. int L = 0;
      7. for (int M = 1; M <= STR.GetLength(); M++)
      8. {
      9. StrL = STR.Left(M).Right(1);
      10. int Modified = BitXOR(StrL.GetAt(0),Password.GetAt(L), 255);
      11. if (L == Password.GetLength() - 1) {L = 0;} else {L++;}
      12. STR2.Insert(STR2.GetLength(),(char) Modified);
      13. }
      14. STR = STR2;
      15. int EncryptBox[256][2];
      16. CString StrM;
      17. for (M = 0; M <= 255; M++)
      18. {
      19. StrM = Password.Left(Mod(M,Password.GetLength()) + 1).Right(1);
      20. EncryptBox[M][1] = StrM.GetAt(0);
      21. EncryptBox[M][0] = M;
      22. }
      23. int B = 0 , Swap = 0;
      24. for (M = 0; M <= 255; M++)
      25. {
      26. B = Mod((B + EncryptBox[M][0] + EncryptBox[M][1]), 256);
      27. Swap = EncryptBox[M][0];
      28. EncryptBox[M][0] = EncryptBox[B][0];
      29. EncryptBox[B][0] = Swap;
      30. }
      31. int C = 0 , D = 0 , E = 0 , By = 0 , N = 0;
      32. CString StrN,StrFormat,Cipher;
      33. for (M = 1; M <= STR.GetLength(); M++)
      34. {
      35. C = Mod((C + 1), 256);
      36. D = Mod((D + EncryptBox[C][0]), 256);
      37. E = EncryptBox[Mod((EncryptBox[C][0] + EncryptBox[D][0]), 256)][0];
      38. StrN = STR.Left(M).Right(1);
      39. By = Bit_XOR(StrN.GetAt(0),E);
      40. StrFormat = "";
      41. StrFormat.Format(_T("%d"), By);
      42. sscanf(StrFormat.GetBuffer(0),"%d",&N);
      43. StrFormat.Format("%X",N);
      44. Cipher.Insert(Cipher.GetLength(),StrFormat.Right(2));
      45. }
      46. STR = Cipher;
      47. }
      48. return STR;
      49. }
      50. CString _StringDecrypt(CString STR ,CString Password,int Level)
      51. {
      52. for (int M = 0; M <= Level; M++)
      53. {
      54. CString StrResult,StrL,STR2;
      55. int L = 0;
      56. int EncryptBox[256][2];
      57. CString StrM;
      58. for (int M = 0; M <= 255; M++)
      59. {
      60. StrM = Password.Left(Mod(M,Password.GetLength()) + 1).Right(1);
      61. EncryptBox[M][1] = StrM.GetAt(0);
      62. EncryptBox[M][0] = M;
      63. }
      64. int B = 0 , Swap = 0;
      65. for (M = 0; M <= 255; M++)
      66. {
      67. B = Mod((B + EncryptBox[M][0] + EncryptBox[M][1]), 256);
      68. Swap = EncryptBox[M][0];
      69. EncryptBox[M][0] = EncryptBox[B][0];
      70. EncryptBox[B][0] = Swap;
      71. }
      72. int C = 0 , D = 0 , E = 0 , By = 0 , N = 0;
      73. CString StrN,StrFormat,Cipher;
      74. for (M = 2; M <= STR.GetLength(); M+= 2)
      75. {
      76. C = Mod((C + 1), 256);
      77. D = Mod((D + EncryptBox[C][0]), 256);
      78. E = EncryptBox[Mod((EncryptBox[C][0] + EncryptBox[D][0]), 256)][0];
      79. StrFormat = STR.Left(M).Right(2);
      80. sscanf(StrFormat.GetBuffer(0),"%x",&N);
      81. StrFormat.Format("%u",N);
      82. By = Bit_XOR(_ttoi(StrFormat),E);
      83. Cipher.Insert(Cipher.GetLength(),(char) By);
      84. }
      85. STR = Cipher;
      86. for (M = 1; M <= STR.GetLength(); M++)
      87. {
      88. StrL = STR.Left(M).Right(1);
      89. int Modified = BitXOR(StrL.GetAt(0),Password.GetAt(L), 255);
      90. if (L == Password.GetLength() - 1) {L = 0;} else {L++;}
      91. STR2.Insert(STR2.GetLength(),(char) Modified);
      92. }
      93. STR = STR2;
      94. }
      95. return STR;
      96. }
      97. int Bit_XOR(int x,int y)
      98. {
      99. return x ^ y;
      100. }
      101. int BitXOR(int x,int y,int z)
      102. {
      103. return x ^ y ^ z;
      104. }
      105. int Mod(int x , int y)
      106. {
      107. return x % y;
      108. }
      عرض الكل






      C ++ 6

      Win32 Console Application

      An application that supports MFC

      PHP كود المصدر

      1. // _StringEncrypt_.cpp : Defines the entry point for the console application.
      2. //
      3. #include "stdafx.h"
      4. #include "_StringEncrypt_.h"
      5. #ifdef _DEBUG
      6. #define new DEBUG_NEW
      7. #undef THIS_FILE
      8. static char THIS_FILE[] = __FILE__;
      9. #endif
      10. CString _StringEncrypt(CString STR,CString Password,int Level = 1);
      11. CString _StringDecrypt(CString STR,CString Password,int Level = 1);
      12. int BitXOR(int x,int y,int z);
      13. int Mod(int x , int y);
      14. int Bit_XOR(int x ,int y);
      15. void File_Write(CString EncryptFile,CString Str);
      16. CString File_Read(CString EncryptFile);
      17. /////////////////////////////////////////////////////////////////////////////
      18. // The one and only application object
      19. CWinApp theApp;
      20. using namespace std;
      21. int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
      22. {
      23. int nRetCode = 0;
      24. // initialize MFC and print and error on failure
      25. if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
      26. {
      27. // TODO: change error code to suit your needs
      28. cerr << _T("Fatal Error: MFC initialization failed") << endl;
      29. nRetCode = 1;
      30. }
      31. else
      32. {
      33. CString Str;
      34. if ((CString) argv[1] == (CString) "1")
      35. {
      36. Str = File_Read(argv[2]);
      37. Str = _StringEncrypt(Str ,argv[3],_ttoi(argv[4]));
      38. File_Write("Encrypt.txt",Str);
      39. cout << (LPCTSTR)"Ok"<< endl;
      40. }
      41. if ((CString) argv[1] == (CString) "0")
      42. {
      43. Str = File_Read(argv[2]);
      44. Str = _StringDecrypt(Str ,argv[3],_ttoi(argv[4]));
      45. File_Write("Decrypt.txt",Str);
      46. cout << (LPCTSTR)"Ok"<< endl;
      47. }
      48. }
      49. return nRetCode;
      50. }
      51. CString _StringEncrypt(CString STR ,CString Password,int Level)
      52. {
      53. for (int M = 0; M <= Level; M++)
      54. {
      55. CString StrResult,StrL,STR2;
      56. int L = 0;
      57. for (int M = 1; M <= STR.GetLength(); M++)
      58. {
      59. StrL = STR.Left(M).Right(1);
      60. int Modified = BitXOR(StrL.GetAt(0),Password.GetAt(L), 255);
      61. if (L == Password.GetLength() - 1) {L = 0;} else {L++;}
      62. STR2.Insert(STR2.GetLength(),(char) Modified);
      63. }
      64. STR = STR2;
      65. int EncryptBox[256][2];
      66. CString StrM;
      67. for (M = 0; M <= 255; M++)
      68. {
      69. StrM = Password.Left(Mod(M,Password.GetLength()) + 1).Right(1);
      70. EncryptBox[M][1] = StrM.GetAt(0);
      71. EncryptBox[M][0] = M;
      72. }
      73. int B = 0 , Swap = 0;
      74. for (M = 0; M <= 255; M++)
      75. {
      76. B = Mod((B + EncryptBox[M][0] + EncryptBox[M][1]), 256);
      77. Swap = EncryptBox[M][0];
      78. EncryptBox[M][0] = EncryptBox[B][0];
      79. EncryptBox[B][0] = Swap;
      80. }
      81. int C = 0 , D = 0 , E = 0 , By = 0 , N = 0;
      82. CString StrN,StrFormat,Cipher;
      83. for (M = 1; M <= STR.GetLength(); M++)
      84. {
      85. C = Mod((C + 1), 256);
      86. D = Mod((D + EncryptBox[C][0]), 256);
      87. E = EncryptBox[Mod((EncryptBox[C][0] + EncryptBox[D][0]), 256)][0];
      88. StrN = STR.Left(M).Right(1);
      89. By = Bit_XOR(StrN.GetAt(0),E);
      90. StrFormat = "";
      91. StrFormat.Format(_T("%d"), By);
      92. sscanf(StrFormat.GetBuffer(0),"%d",&N);
      93. StrFormat.Format("%X",N);
      94. Cipher.Insert(Cipher.GetLength(),StrFormat.Right(2));
      95. }
      96. STR = Cipher;
      97. }
      98. return STR;
      99. }
      100. CString _StringDecrypt(CString STR ,CString Password,int Level)
      101. {
      102. for (int M = 0; M <= Level; M++)
      103. {
      104. CString StrResult,StrL,STR2;
      105. int L = 0;
      106. int EncryptBox[256][2];
      107. CString StrM;
      108. for (int M = 0; M <= 255; M++)
      109. {
      110. StrM = Password.Left(Mod(M,Password.GetLength()) + 1).Right(1);
      111. EncryptBox[M][1] = StrM.GetAt(0);
      112. EncryptBox[M][0] = M;
      113. }
      114. int B = 0 , Swap = 0;
      115. for (M = 0; M <= 255; M++)
      116. {
      117. B = Mod((B + EncryptBox[M][0] + EncryptBox[M][1]), 256);
      118. Swap = EncryptBox[M][0];
      119. EncryptBox[M][0] = EncryptBox[B][0];
      120. EncryptBox[B][0] = Swap;
      121. }
      122. int C = 0 , D = 0 , E = 0 , By = 0 , N = 0;
      123. CString StrN,StrFormat,Cipher;
      124. for (M = 2; M <= STR.GetLength(); M+= 2)
      125. {
      126. C = Mod((C + 1), 256);
      127. D = Mod((D + EncryptBox[C][0]), 256);
      128. E = EncryptBox[Mod((EncryptBox[C][0] + EncryptBox[D][0]), 256)][0];
      129. StrFormat = STR.Left(M).Right(2);
      130. sscanf(StrFormat.GetBuffer(0),"%x",&N);
      131. StrFormat.Format("%u",N);
      132. By = Bit_XOR(_ttoi(StrFormat),E);
      133. Cipher.Insert(Cipher.GetLength(),(char) By);
      134. }
      135. STR = Cipher;
      136. for (M = 1; M <= STR.GetLength(); M++)
      137. {
      138. StrL = STR.Left(M).Right(1);
      139. int Modified = BitXOR(StrL.GetAt(0),Password.GetAt(L), 255);
      140. if (L == Password.GetLength() - 1) {L = 0;} else {L++;}
      141. STR2.Insert(STR2.GetLength(),(char) Modified);
      142. }
      143. STR = STR2;
      144. }
      145. return STR;
      146. }
      147. int Bit_XOR(int x,int y)
      148. {
      149. return x ^ y;
      150. }
      151. int BitXOR(int x,int y,int z)
      152. {
      153. return x ^ y ^ z;
      154. }
      155. int Mod(int x , int y)
      156. {
      157. return x % y;
      158. }
      159. void File_Write(CString EncryptFile,CString Str)
      160. {
      161. CFile file;
      162. if (file.Open(EncryptFile, CFile::modeCreate|CFile::modeWrite))
      163. {
      164. CFileStatus status;
      165. if(CFile::GetStatus( EncryptFile, status ))
      166. {
      167. file.Write(Str.GetBuffer(0),Str.GetLength());
      168. }}
      169. }
      170. CString File_Read(CString EncryptFile)
      171. {
      172. CFile file;
      173. const int MAX_BUFFER_SIZE = 65536;
      174. int nSize = 0;
      175. char szBuffer[MAX_BUFFER_SIZE+1];
      176. CString TXTR;
      177. CFileStatus status;
      178. if (file.Open(EncryptFile, CFile::modeRead | CFile::typeBinary | CFile::shareDenyNone))
      179. {
      180. if(CFile::GetStatus( EncryptFile, status ))
      181. {
      182. while(true)
      183. {
      184. nSize = file.Read(szBuffer,MAX_BUFFER_SIZE);
      185. if(nSize <= 0)
      186. break;
      187. szBuffer[nSize] = '\0';
      188. TXTR += szBuffer;
      189. }
      190. }}
      191. return TXTR;
      192. }
      عرض الكل




    • تم إضافة خيار جديد لفتح ملف لأن لصق النص على نظام الويندوس الإنجليزي لنصوص العربية تحدث
      معه بعض المشاكل في حال عدم تثبيت اللغة بصورة كاملة الفتح المباشر للملف يتفادى حدوث هذه
      المشكلة البرنامج المعدل من المرفقات