Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iostream>
- #include <iomanip>
- #include <locale>
- #include <sstream>
- using namespace std;
- using namespace std;
- // Global Variables
- int originalNumber, key, a, b, c, number, valA, valB, valC, encryptedNumber;
- // isolateDigits procedure
- void isolateDigits()
- {
- a = originalNumber / 100 % 10;
- b = originalNumber / 10 % 10;
- c = originalNumber % 10;
- }
- // replaceDigits procedure for Encryption
- void replaceDigits()
- {
- valA = a + key;
- valB = b + key;
- valC = c + key;
- }
- // swapDigit1WithDigit3 procedure
- void swapDigit1WithDigit3()
- {
- valC = a + key;
- valB = b + key;
- valA = c + key;
- }
- // recomposeEncryptedNumber procedure
- void recomposeEncryptedNumber()
- {
- if (valA >= 10)
- valA = valA - 10;
- if (valB >= 10)
- valB = valB - 10;
- if (valC >= 10)
- valC = valC - 10;
- encryptedNumber = (valC) << (valB) << (valA); // PROBLEM
- }
- int main()
- {
- int length;
- // Get original Number
- cout << ("nEnter the original three-digit number: ");
- cin >> originalNumber;
- // Check for 3 digits
- int Number = originalNumber; // number to be converted to a string
- string Result; // string which will contain the result
- ostringstream convert; // stream used for the conversion
- convert << Number; // insert the textual representation of 'Number' in the characters in the stream
- Result = convert.str(); // set 'Result' to the contents of the stream
- length = Result.length();
- if (length != 3)
- {
- cout << ("nPlease enter a valid three digit number: ");
- cin >> originalNumber;
- }
- // Get Key
- cout << ("nEnter the key: ");
- cin >> key;
- // Call isolateDigits
- isolateDigits();
- // Call replaceDigits
- replaceDigits();
- // Call swapDigit1WithDigit3
- swapDigit1WithDigit3();
- // Call recomposeEncryptedNumber
- recomposeEncryptedNumber();
- cout << "nThe encrypted number for " << originalNumber << " is " << encryptedNumber << ".n" << "n";
- //Print out Digits - Test
- //cout << "n" << valA;
- //cout << "n" << valB;
- //cout << "n" << valC << "n" << "n";
- // Pause at end
- system("pause");
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement