Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- using namespace std;
- int main()
- {
- int idSchool;
- string binary;
- cout << "First we'll test converting an integer to base 2...";
- cout << "\nPlease input your school ID #: ";
- cin >> idSchool;
- if (idSchool > 0) ///Check if integer inputed is positive
- {
- cout << "Number larger than 0 inputed, continuing..." << endl;
- }
- else
- {
- cout << "Integer smaller than 0, please input a larger integer." << endl;
- return 0;
- }
- while (idSchool!=0)
- {
- binary=char(48+idSchool%2)+binary;
- idSchool/=2;
- }
- cout << "Student ID converted to base 2: " << binary;
- long long unsigned int baseNinety;
- string encryptCode;
- cout << "\nEnter your student ID again: ";
- cin >> baseNinety;
- int baseninetyCompare; ///keep student number in memory for compare against reverse
- baseninetyCompare=baseNinety; ///compare value set to original student number
- baseNinety*=baseNinety; ///square student ID
- while(baseNinety>0)
- {
- encryptCode=char(33+baseNinety%90)+encryptCode;
- baseNinety/=90;
- }
- cout << "Encrypted code: " << encryptCode;
- int reverseEncrypt; ///reverse attempt
- cout << "\nInput the encrypted code to be reversed (copy and paste): ";
- cin >> reverseEncrypt;
- /// I'm stuck here ******************************************************************
- }
- /*
- For example, suppose your student number is 123456. Then the square is
- 15241383936 = 169348710 · 90 + 36
- = (1881652 · 90 + 30) · 90 + 36
- = ((20907 · 90 + 22) · 90 + 30) · 90 + 36
- = (((232 · 90 + 27) · 90 + 22) · 90 + 30) · 90 + 36
- = ((((2 · 90 + 52) · 90 + 27) · 90 + 22) · 90 + 30) · 90 + 36
- = (((((0 · 90 + 2) · 90 + 52) · 90 + 27) · 90 + 22) · 90 + 30) · 90 + 36
- Now the remainders are, in reverse order, 2,52,27,22,30 and 36. These need to be increased by 33, to get our
- ascii values: 35,85,60,55,63,69, which correspond to the string of ascii characters #U<7?E. So that would be
- the encrypted student number.
- Now write code to check your result by reversing it, so we can recover the student number in base 10 from the
- encrypted version of its square. (Not a very secure encryption, is it?)
- Submit your code as <your initials> encryptSID.cpp by 3/1/16.
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement