|
Below is the code
#include <iostream>
#include <fstream>
#include <string>
#include <conio.h>
using namespace std;
string XOR(string value,string key)
{
string retval(value);
short unsigned int klen=key.length();
short unsigned int vlen=value.length();
short unsigned int k=0;
short unsigned int v=0;
for(v;v<vlen;v++)
{
retval[v]=value[v]^key[k];
k=(++k<klen?k );
}
return retval;
}
/******************************************************************************/
/* Here's a Test Program */
/******************************************************************************/
int main()
{
//string value("just for fun");
string key = "TERADATA";
string username;
string password;
string cnfpassword;
ofstream myfile;
cout<<"Enter user name::";
cin>>username;
cout<<"Enter Password\n";
cout<<"NOTE:\n"<<"1) Password can be alphanumeric or numeric or alphabets\n"
<<"2) Blank spaces not allowed\n"<<"::";
cin>>password;
cout<<"Confirm Password::";
cin>>cnfpassword;
if (password.compare(cnfpassword) != 0)
{
cout<<"Sorry Password dose not match....try again"<<"\n";
return 1;
}
else
{
password=XOR(password,key);
}
cout<<"Encrypted Password ::"<<"\n";
cout<<password<<"\n\n";
myfile.open("Test_SSOpw.txt", ios::out);
if( !myfile )
cout<<"Error opening file";
else
{
myfile.write("#USERNAME#", 10);
myfile.write(username.c_str(), username.length());
myfile <<'\n';
myfile <<"#PASSWORD#"<<password;
myfile.close();
cout<<"Functional SSO password encryption success!!"<<'\n';
}
password=XOR(password,"TERADATA");
cout<<"Decrypted Password ::"<<password<<"\n";
getch();
return 0;
}
|
|
|
|
|
Below is the code
#include <iostream>
#include <fstream>
#include <string>
#include <conio.h>
using namespace std;
string XOR(string value,string key)
{
string retval(value);
short unsigned int klen=key.length();
short unsigned int vlen=value.length();
short unsigned int k=0;
short unsigned int v=0;
for(v;v<vlen;v++)
{
retval[v]=value[v]^key[k];
k=(++k<klen?k);
}
return retval;
}
/******************************************************************************/
/* Here's a Test Program */
/******************************************************************************/
int main()
{
//string value("just for fun");
string key = "TERADATA";
string username;
string password;
string cnfpassword;
ofstream myfile;
cout<<"Enter user name::";
cin>>username;
cout<<"Enter Password\n";
cout<<"NOTE:\n"<<"1) Password can be alphanumeric or numeric or alphabets\n"
<<"2) Blank spaces not allowed\n"<<"::";
cin>>password;
cout<<"Confirm Password::";
cin>>cnfpassword;
if (password.compare(cnfpassword) != 0)
{
cout<<"Sorry Password dose not match....try again"<<"\n";
return 1;
}
else
{
password=XOR(password,key);
}
cout<<"Encrypted Password ::"<<"\n";
cout<<password<<"\n\n";
myfile.open("Test_SSOpw.txt", ios::out);
if( !myfile )
cout<<"Error opening file";
else
{
myfile.write("#USERNAME#", 10);
myfile.write(username.c_str(), username.length());
myfile <<'\n';
myfile <<"#PASSWORD#"<<password;
myfile.close();
cout<<"Functional SSO password encryption success!!"<<'\n';
}
password=XOR(password,"TERADATA");
cout<<"Decrypted Password ::"<<password<<"\n";
getch();
return 0;
}
|
|
|
|
|
Nandu_77b wrote: cin>>cnfpassword;
Use getc() in a while loop to get the password characters and display an asterisk with cout for each character.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
I have tried with the below code, but I am getting some junk value in password.
int i = 0;
char ch;
char password[20];
do
{
ch = getch();
cerr<<"*";
password[i++] = ch;
}
while(ch != '\r');
|
|
|
|
|
This works for me:
std::string str;
char c;
cout<<"Please enter password:";
while(true)
{
c = _getch();
if(c == 32 || c == 13 || c == 27)
break;
else
{
str += c;
std::cout<<"*";
}
}
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
|
Hi,
I am writing some character bytes in to File using
fprintf(fp,"%c",data);
if data is 26 then while reading it is read as -1,
if other than 26 it is able to read correctly.
What will be the problem?
Any idea?
Regards,
Sunil Kumar
|
|
|
|
|
how is data populated ?
also, how do you read the file back ?
|
|
|
|
|
Hi,
I read using
int c=getc(fp);
until I read the complete bytes.
Regards,
Sunil Kumar
|
|
|
|
|
sunilkumar.d wrote: Hi,
I read using
int c=getc(fp);
until I read the complete bytes.
thanks. and then i ask back my second question, which was :
how do you read back the file ?
just a guess. wouldn't it work better if you write (with fprintf() using the %d parameter rather than %c (as you're handling an int and not a char) ?
also, doesn't fscanf() work better than getc() ?
|
|
|
|
|
Well, good luck Tox.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
I did nt try that way.
Actually the code is already written.Now I am maintaining it.
So I did nt change it.
Regards,
Sunil Kumar
|
|
|
|
|
please make tries and use your debugger...if you don't make tries, how can you tell what's wrong !
man, if you're on a maintenance team, it your every day job. you should already be able to have such reflex
|
|
|
|
|
Could this be related with ASCII value? 26 corresponds to substitute, so as toxcct says you would be having some problem with the way you read from the file.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Hi , thanks for the answer.
I am reading like
int c;
for(i=0;i<10;i++)
{
c=getc(fp)
char [i]=c;
}
If the charater is 26 then c will contain -1.
Regards,
Sunil Kumar
|
|
|
|
|
sunilkumar.d wrote: int c;
for(i=0;i<10;i++)
{
c=getc(fp)
char [i]=c;
}
Are you sure this is the code? It won't even compile.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
Sorry sir,
I just typed in correctly.
Regards,
Sunil Kumar
|
|
|
|
|
Hi,
How is the File Opened? If you are looking for bytes it should be "rb", "r+b" etc, the 'b' must be there. What was ascii 26 again? I think it was 'Substitute' Anyway, fgets and fputs may try to put an interpretation to ascii 26 when encountered in text mode. In binary mode is should pass straight trough.
Hope this is helpfull,
Regards,
Bram van Kampen
|
|
|
|
|
Hai,
In my XML File ,i am having a tag which value is Date & Time.
Like this,
2008/05/19 00:00:00
in my output XML File i want value Like this,
05/19/2008 00:00:00
using XSL transform,
what is the solution for this ...
please reply me..
Born to win...!
|
|
|
|
|
Does anyone know how to get the vendor id, product id and serial number of a USB device from Windows?
I know that you can get the vendor name and product name using IOCTL_STORAGE_QUERY_PROPERY, but this returns a text description of the vendor and product rather than the hex ID codes.
I have also found that the registry enumerates the USB devices in HKLM\CurrentControlSet\services\USBSTOR\enum, but I don't know how to tie this into the device handle I have on an opened device handle.
|
|
|
|
|
See Win32_DiskDrive[^] class. (Look at the DeviceID field).
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
|
Have you tried this?:
http://www.winsim.com/diskid32/diskid32.html
I found it very good for physical drives, and, it's freeware
regards,
Bram van Kampen
|
|
|
|
|
This code that you suggested is very specific to IDE, issuing ATA commands via a custom driver. What I require are the USB identifiers as transmitted over the USB during enumeration of the device. These IDs identify the specific device. They are held as entries in the registry. What I was hoping for was a system call or technique that would associate a handle of an opened device to the registry entry that specified the Vendor, Product and serial numbers.
|
|
|
|
|
Hi,
Sorry for the Delay.
I Understand what you mean. I am not aware of any system calls in that respect. System calls tend to be generic as far as the filing system is concerned. I guess that this sort of communication takes place at device driver level. This suggests that to get this info, you'll need to write a driver, and insert it into the driverchain. All very technical and Error Prone. Seeing that you know that this info is stored in the registry, any chance of using that information.
Hope this is Helpfull, unfortunately, this is where my knowledge stops.
Regards,
Bram van Kampen
|
|
|
|