Advertisement
Guest User

Untitled

a guest
Oct 30th, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <locale>
  5. #include <sstream>
  6. using namespace std;
  7.  
  8. using namespace std;
  9.  
  10. // Global Variables
  11. int originalNumber, key, a, b, c, number, valA, valB, valC, encryptedNumber;
  12.  
  13. // isolateDigits procedure
  14. void isolateDigits()
  15. {
  16. a = originalNumber / 100 % 10;
  17. b = originalNumber / 10 % 10;
  18. c = originalNumber % 10;
  19. }
  20.  
  21. // replaceDigits procedure for Encryption
  22. void replaceDigits()
  23. {
  24. valA = a + key;
  25. valB = b + key;
  26. valC = c + key;
  27. }
  28.  
  29. // swapDigit1WithDigit3 procedure
  30. void swapDigit1WithDigit3()
  31. {
  32. valC = a + key;
  33. valB = b + key;
  34. valA = c + key;
  35. }
  36.  
  37. // recomposeEncryptedNumber procedure
  38. void recomposeEncryptedNumber()
  39. {
  40. if (valA >= 10)
  41. valA = valA - 10;
  42. if (valB >= 10)
  43. valB = valB - 10;
  44. if (valC >= 10)
  45. valC = valC - 10;
  46.  
  47. encryptedNumber = (valC) << (valB) << (valA); // PROBLEM
  48.  
  49. }
  50.  
  51. int main()
  52.  
  53. {
  54. int length;
  55. // Get original Number
  56. cout << ("nEnter the original three-digit number: ");
  57. cin >> originalNumber;
  58.  
  59. // Check for 3 digits
  60. int Number = originalNumber; // number to be converted to a string
  61. string Result; // string which will contain the result
  62. ostringstream convert; // stream used for the conversion
  63. convert << Number; // insert the textual representation of 'Number' in the characters in the stream
  64. Result = convert.str(); // set 'Result' to the contents of the stream
  65. length = Result.length();
  66. if (length != 3)
  67. {
  68. cout << ("nPlease enter a valid three digit number: ");
  69. cin >> originalNumber;
  70. }
  71.  
  72. // Get Key
  73. cout << ("nEnter the key: ");
  74. cin >> key;
  75.  
  76. // Call isolateDigits
  77. isolateDigits();
  78.  
  79. // Call replaceDigits
  80. replaceDigits();
  81.  
  82. // Call swapDigit1WithDigit3
  83. swapDigit1WithDigit3();
  84.  
  85. // Call recomposeEncryptedNumber
  86. recomposeEncryptedNumber();
  87.  
  88. cout << "nThe encrypted number for " << originalNumber << " is " << encryptedNumber << ".n" << "n";
  89.  
  90. //Print out Digits - Test
  91. //cout << "n" << valA;
  92. //cout << "n" << valB;
  93. //cout << "n" << valC << "n" << "n";
  94.  
  95. // Pause at end
  96. system("pause");
  97. return(0);
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement