Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.5 KiB

  1. //#pragma title( "Cipher.cpp - Very simple cipher for encryption" )
  2. /*
  3. Copyright (c) 1995-1998, Mission Critical Software, Inc. All rights reserved.
  4. ===============================================================================
  5. Module - Cipher.cpp
  6. System - Common
  7. Author - Tom Bernhardt
  8. Created - 1996-01-21
  9. Description - Very simple Cipher routine for network packet password
  10. encryption. This is a symmetrical cipher where applying
  11. it twice will revert it to its orignial form. One of its
  12. functions is a one's complement so it assumes that no char
  13. will have the value of '\xff' to erroneously pre-terminate
  14. the resultant string.
  15. NOTE: This is obviously so simple that it can be easily
  16. cracked by either single stepping the code or comparing sequences
  17. of known values and their encrypted result. Its only use
  18. is to keep out the casual observer/hacker. It should be replaced
  19. by heavy public key encryption when possible.
  20. Updates -
  21. ===============================================================================
  22. */
  23. #include <windows.h>
  24. #include "Cipher.hpp"
  25. void
  26. SimpleCipher(
  27. WCHAR * str // i/o-string to encrypt
  28. )
  29. {
  30. WCHAR * c;
  31. // exchange nibbles and NOT result or each char
  32. for ( c = str; *c; c++ )
  33. *c = ~( *c >> 4 | *c << 4 );
  34. // exchange chars around middle
  35. for ( --c; c > str; c--, str++ )
  36. {
  37. *c ^= *str;
  38. *str ^= *c;
  39. *c ^= *str;
  40. }
  41. }
  42. void
  43. SimpleCipher(
  44. char unsigned * str // i/o-string to encrypt
  45. )
  46. {
  47. char unsigned * c;
  48. // exchange nibbles and NOT result or each char
  49. for ( c = str; *c; c++ )
  50. *c = ~( *c >> 4 | *c << 4 );
  51. // exchange chars around middle
  52. for ( --c; c > str; c--, str++ )
  53. {
  54. *c ^= *str;
  55. *str ^= *c;
  56. *c ^= *str;
  57. }
  58. }
  59. void
  60. SimpleCipher(
  61. char unsigned * str ,// i/o-string to encrypt
  62. int len // in -length of string
  63. )
  64. {
  65. char unsigned * c;
  66. // exchange nibbles and NOT result or each char
  67. for ( c = str; len--; c++ )
  68. *c = ~( *c >> 4 | *c << 4 );
  69. // exchange chars around middle
  70. for ( --c; c > str; c--, str++ )
  71. {
  72. *c ^= *str;
  73. *str ^= *c;
  74. *c ^= *str;
  75. }
  76. }
  77. // Cipher.cpp - end of file