we jumped from writing "Hello World" and doing palindrome programs to this... I feel overwhelmed.. |
Yes, that does seem a bit drastic.
Good progress with using find/substr, that is very similar to how I was envisioning it.
One note is that your are doing substr(0,5), so you are essentially hardcoding the username to be 5 characters long. Not a big deal if the flexibility is not required, but the result of value,find(",")
could be used to determine how big the first (username) string is.
Anyway, so yes you need to pass things to functions.
http://www.cplusplus.com/doc/tutorial/functions/
Let's assume you have correctly separated the username from the password.
Your decryptPassword function takes in a string, right?
So, from your authenticateUser function, you need to pass the password to the decryptPassword function.
This is done by something like:
1 2 3 4
|
if (username == USERNAME && passw == decryptPassword(PASSWORD))
{
authPassed = true;
}
|
But now the hard part is actually looking at the encrypted password string, and decrypting it according to your formula.
I actually don't understand right off the bat what it is your decryption ought to it.
You begin with: i0J0u0j0u0J0Zys0r0
I notice the number of 0s in this is equal to the number of lowercase letters in the plaintext password. Now that might just be a coincidence, so don't go too strongly there.
I noticed you've been given a string of vowels to work with. I assume this is related to how the encryption works.
So yeah, what you need to do is explain, step by step, how the decryption process is supposed to work. What do those letters and numbers me? How do they relate to the vowel string?
For example, let's start simpler:
If I have a string "a", what should it encrypt to?
And given that encrypted string, what do I need to do to transform it back into "a"?
_____________________________________________
I also noticed that "J0" maps to A both times, if you break up the encrypted string.
1 2
|
i0 J0 u0 j0 u0 J0
b A n a n A
|
Also, j0 (lowercase J) makes to lower-case a.
"J" is the 10th letter of the alphabet, and "A" is the 1st letter of the alphabet. So the decryption is shifting the J backwards by (10 - 1, = 9) letters.
The "u0" decrypts to n both times.
U = 21, N = 14
U - N = 7.
The the u0 is being decrypted by a shift of 7.
Your cipher seems to be decrypted by alternating shifts of 9 and 7. At least part of it?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
// Example program
#include <iostream>
#include <string>
using std::string;
using std::cout;
void test_decrypt()
{
string password = "i0J0u0j0u0J0Zys0r0{";
string decrypted_password;
for (size_t i = 0; i < password.length(); i+=2)
{
if (i % 4 == 0)
{
decrypted_password += password[i] - 7;
}
else
{
decrypted_password += password[i] - 9;
}
}
cout << decrypted_password << '\n';
}
int main()
{
test_decrypt();
}
|
Output:
Clearly, the remaining part of the password doesn't match this pattern, that's where my pattern breaks down. The 0 (and lack of 0 in the later part of the string) must mean something I; assume it's another type of shift.