Crypt.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // FileZilla - a Windows ftp client
  2. // Copyright (C) 2002-2004 - Tim Kosse <[email protected]>
  3. // This program is free software; you can redistribute it and/or
  4. // modify it under the terms of the GNU General Public License
  5. // as published by the Free Software Foundation; either version 2
  6. // of the License, or (at your option) any later version.
  7. // This program is distributed in the hope that it will be useful,
  8. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. // GNU General Public License for more details.
  11. // You should have received a copy of the GNU General Public License
  12. // along with this program; if not, write to the Free Software
  13. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. // Crypt.cpp: Implementierung der Klasse CCrypt.
  15. //
  16. //////////////////////////////////////////////////////////////////////
  17. #include "stdafx.h"
  18. #include "crypt.h"
  19. #ifdef _DEBUG
  20. #undef THIS_FILE
  21. static char THIS_FILE[]=__FILE__;
  22. #define new DEBUG_NEW
  23. #endif
  24. //////////////////////////////////////////////////////////////////////
  25. // Konstruktion/Destruktion
  26. //////////////////////////////////////////////////////////////////////
  27. char* CCrypt::m_key = "FILEZILLA1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  28. CString CCrypt::encrypt(CString str)
  29. {
  30. USES_CONVERSION;
  31. int pos=str.GetLength()%strlen(m_key);
  32. CString ret;
  33. LPCSTR lpszAscii=T2CA(str);
  34. for (unsigned int i=0;i<strlen(lpszAscii);i++)
  35. {
  36. CString tmp=ret;
  37. ret.Format(_T("%s%03d"),tmp,(unsigned char)lpszAscii[i]^m_key[(i+pos)%strlen(m_key)]);
  38. }
  39. return ret;
  40. }
  41. CString CCrypt::decrypt(CString str)
  42. {
  43. USES_CONVERSION;
  44. LPCSTR lpszAscii=T2CA(str);
  45. int pos=(strlen(lpszAscii)/3)%strlen(m_key);
  46. CString ret;
  47. TCHAR tmp[2];
  48. tmp[1] = 0;
  49. for (unsigned int i=0;i<strlen(lpszAscii)/3;i++)
  50. {
  51. int digit;
  52. int number = 0;
  53. digit = lpszAscii[i * 3];
  54. if (digit < '0' || digit > '9')
  55. return _T("");
  56. number += (digit - '0') * 100;
  57. digit = lpszAscii[i * 3 + 1];
  58. if (digit < '0' || digit > '9')
  59. return _T("");
  60. number += (digit - '0') * 10;
  61. digit = lpszAscii[i * 3 + 2];
  62. if (digit < '0' || digit > '9')
  63. return _T("");
  64. number += digit - '0';
  65. tmp[0] = number^m_key[(i+pos)%strlen(m_key)];
  66. ret += tmp;
  67. }
  68. return ret;
  69. }