Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <map>
- #include <fstream>
- #include <iostream>
- #include <sstream>
- using namespace std;
- //Text file called pwlist.txt
- //Duncan,WANIS
- //James,OOIWDFV
- void main(){
- map<string,string> pws;
- ifstream pf("pwlist.txt");
- for(string pw, user, line; pf.good() && getline(pf,line);pws.insert(pair<string,string>(user,pw)))
- {
- stringstream strm(line);
- getline(strm,user,',');
- getline(strm,pw,',');
- };
- pf.close();
- string username, password;
- cout<<"Please enter username:\n";
- cin>>username;
- cout<<"Please enter password:\n";
- cin>>password;
- for( unsigned int i = 0; i < password.size(); ++i )
- {
- //A little bit encrpyted just to spice things up
- password[i] = 'A'+(password[i]^username[i%username.size()])%26;
- }
- if ( pws.find(username) != pws.end() && pws.find(username)->second == password )
- {
- cout<<"Correct Login Well Done!\n";
- }
- else
- cout<<"Incorrect please do not try again!\n";
- //Now to see if we can create a cracker.
- //The encrypted password is what needs to be modified we want another password that will colide
- //Assume we know the first pw char is W and real pw is R and the username is Duncan
- //R^D = 82^68 = 22
- //22%26 = 22
- //22+'A' = 'W'
- //So we need something else that creates W
- //So we need something so that x%26 = 22
- //x could be 22+26*anything lets try 48
- //So what ^ with 'D' = 48 well 116 does
- //116 = 't' therefore t would work instead of 'R'
- //And sure enough that came out correct so we have a collision.
- //We can work out all possible passwords from the password list as follows.
- //Remember max char is 128 128/26 = ~4.9
- //Assume passwords are in the range 32-126 ie special chars, chars, numerical
- username = "James";
- string encryptedpw = pws.find(username)->second;
- for( unsigned int i = 0; i < encryptedpw.size(); ++i )
- {
- int beforemod = encryptedpw[i]-'A';
- cout<<"Character "<<i<<" is one of: ";
- for( ; beforemod < 128; beforemod+=26 )
- {
- char possible = (char)beforemod^username[i%username.size()];
- if ( possible > 31 && possible < 127 ){
- cout<<possible<<", ";
- }
- }
- cout<<endl;
- }
- //From this response it is clear that it would still take a small amount of work to
- //calculate the original. Although ultimatly it doesn't matter as we have now a list
- //of valid passwords.
- //Pause until we are done
- cin>>username;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement