Advertisement
Guest User

Project3

a guest
Mar 1st, 2016
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int idSchool;
  9.     string binary;
  10.     cout << "First we'll test converting an integer to base 2...";
  11.     cout << "\nPlease input your school ID #: ";
  12.     cin >> idSchool;
  13.     if (idSchool > 0) ///Check if integer inputed is positive
  14.     {
  15.         cout << "Number larger than 0 inputed, continuing..." << endl;
  16.     }
  17.     else
  18.     {
  19.         cout << "Integer smaller than 0, please input a larger integer." << endl;
  20.         return 0;
  21.     }
  22.     while (idSchool!=0)
  23.     {
  24.         binary=char(48+idSchool%2)+binary;
  25.         idSchool/=2;
  26.     }
  27.     cout << "Student ID converted to base 2: " << binary;
  28.     long long unsigned int baseNinety;
  29.     string encryptCode;
  30.     cout << "\nEnter your student ID again: ";
  31.     cin >> baseNinety;
  32.     int baseninetyCompare; ///keep student number in memory for compare against reverse
  33.     baseninetyCompare=baseNinety; ///compare value set to original student number
  34.     baseNinety*=baseNinety; ///square student ID
  35.     while(baseNinety>0)
  36.     {
  37.         encryptCode=char(33+baseNinety%90)+encryptCode;
  38.         baseNinety/=90;
  39.     }
  40.     cout << "Encrypted code: " << encryptCode;
  41.     int reverseEncrypt; ///reverse attempt
  42.     cout << "\nInput the encrypted code to be reversed (copy and paste): ";
  43.     cin >> reverseEncrypt;
  44.     /// I'm stuck here ******************************************************************
  45. }
  46. /*
  47. For example, suppose your student number is 123456. Then the square is
  48. 15241383936 = 169348710 · 90 + 36
  49. = (1881652 · 90 + 30) · 90 + 36
  50. = ((20907 · 90 + 22) · 90 + 30) · 90 + 36
  51. = (((232 · 90 + 27) · 90 + 22) · 90 + 30) · 90 + 36
  52. = ((((2 · 90 + 52) · 90 + 27) · 90 + 22) · 90 + 30) · 90 + 36
  53. = (((((0 · 90 + 2) · 90 + 52) · 90 + 27) · 90 + 22) · 90 + 30) · 90 + 36
  54. Now the remainders are, in reverse order, 2,52,27,22,30 and 36. These need to be increased by 33, to get our
  55. ascii values: 35,85,60,55,63,69, which correspond to the string of ascii characters #U<7?E. So that would be
  56. the encrypted student number.
  57.  
  58. Now write code to check your result by reversing it, so we can recover the student number in base 10 from the
  59. encrypted version of its square. (Not a very secure encryption, is it?)
  60.  
  61. Submit your code as <your initials> encryptSID.cpp by 3/1/16.
  62. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement