Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Password Encryption
You are NOT allowed to use string operations Or array declaration in the encryption process. You are asked to declare lists stacks and Queues of type char from the STL to encrypt the password to get full score.
Encryption Algorithm
Step 1: (2 Points)
In this step the password characters will be inserted into list object to be ready for the coming encryption stages.
(objects to use → only list)
Step 2: (2 Points)
In this step, the first and last characters of the password (within (e.g H7l*lo → o7l*lH)
(objects to use → only list)
Step 3: (5 Points)
the list) will be reversed.
In this step, the ASCII value of the characters will be changed and the new characters (after changing the ASCII) will be in original order in the list.
The new ASCII value for each character will be calculated by adding to the current ASCII value the least significant digit from the ASCII of the next character.
(e.g. After step 2, the password is: oellH with ASCII values:
           o: 111,     7: 55,    l: 108,     *:42        l: 108,    H: 72
      The new ASCII values will be:
           t: 111+5,   ?: 55+8,  n: 108+2,   2:42+8      n: 108+2,  H: 72
      The password will be : t?n2nH
Note: The ASCII for the last character will not be changed because there is no character next to the last one.
(objects to use → list and stack OR list and queue OR both) give explanation for your choice.
Step 4: (4 Points)
Finally, in this step, the characters in even positions will be reversed and you keep the characters in the odd positions in their original order.
(e.g. After step 3, the password is : t?n2nH so after applying step 4 the password will be : n?n2tH (objects to use → list and stack OR list and queue OR both) give explanation for your choice


What I have tried:

string UserAccountType::encryptPassword(string ep){
list<char> l;
stack<char> s;
for(int i=0;i<ep.size();i++)
l.push_back(ep[i]);

 char temp=l.front();
 l.pop_front();
 l.push_front(l.back());
 l.pop_back();
 l.push_back(temp);
 
while(!l.empty()){
s.push(l.back());
l.pop_back();
}

queue <char> q;
char x;
temp=s.top();
while(s.size() != 1){
x=s.top();
s.pop();
s.top()+=x%10;
q.push(x);
}
q.push(temp);

}
Posted
Updated 25-Dec-21 7:11am
Comments
k5054 25-Dec-21 9:27am    
And your question is?
Also, have you been introduced to the algorithm library yet? Much of the work for this exercise can be achieved with functions found there.
dalia alzoubi 25-Dec-21 9:43am    
no not yet I want the code for this function I can't solve it
k5054 25-Dec-21 9:51am    
The algorithm library reduces much of this to single lines of code. But since you haven't started on it in class, then its probably best not to delve into it at this point.

If you look at other people's questions here about homework, the standard answer is "We don't do homework for you! You have to do it yourself. But, we will try to help you understand why your code doesn't work".

You've got some code here. That puts you ahead of many who post for homework help. But all we know at this point is that you have some sort of issue with it. You haven't said what that issue is. Does it fail to compile? Does it produce the wrong output? If so what's wrong with the output? Are you having an issue grasping the concept, or in this case a stage of the algorithm provided, and can't quite see how to proceed? What, exactly do you want assistance with?

Read the assignment carefully: it lays out in very precise detail exactly what it espects you to do.
So do it: read step one, and write code to do it - you have user input so create the list and insert the user input to it. Test that step. When you are sure it works, move on to step 2.

This isn't complicated, and you have very little "thinking" to do - just implementation of a spelled-out-for-you algorithm!

So give it a try, step by step. You'll get there.
 
Share this answer
 
Dont write such spaghetti code but use some class design with functions to make your homework easier better understandable. Also use spreaking names and insertion of the code. Like
C++
class PasswordEncryptor {
public:
// creates an instance (step 1)
PasswordEncryptor(String password);
// inserts password into list (step 2)
bool prepareForList();
private:
list<char> password;
}

I guess that you havent used "the least significant digit from the ASCII of the next character." but the current.
Read your instructions carefully and try to get some test data and write it as test to verify your solution.

Good lucke
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900