So i did tons of research for bout 2 hours on google and finally figured out how bit-level works when using XOR, but most of the time, the vars were already declared I wanted to know how to declare them but by user input. This is just an example i managed to get it to work with pass, but as for key I am stuck. But see when I want to XOR pass ^ key I want the key to know the pass length and generate random symbols mixed with alpha-numeric either from a generator or specified array, instead of my already declared var "!@#$%^&". Here is my code:

// XORO.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <string.h>
#include <conio.h>
#include <cstring>

using namespace std;

char pass[32]; //pass will not always be 32 char in length
char key[32] = "!@#$%^&"; //length needs to match strlen of pass
int chLen;
int count = NULL;

int main()
{
  cout << "Input your password: ";
  cin  >> pass;      cout << endl;

  cout << "      You typed: " << pass << endl;
  cout << "Sizeof password: " << strlen(pass) << endl;
  
  chLen = strlen(pass);

  //Count strlen for XOR encryption

  cout << "  # of Integers: " << chLen << endl;
  //To make sure that the size of pass is stored in chLen.

  cout << "X-OR Encryption: ";
  for ( count = NULL; count < chLen; count++)
  {
	  pass[count] = pass[count] ^ key[count];
		cout << pass[count];
  } cout << endl << endl;

  cout << " X-OR Reveresed: ";
  for ( count = NULL; count < chLen; count++)
  {
	  pass[count] = key[count] ^ pass[count];
		cout << pass[count];
  } cout << endl << endl;

  _getch();
  return 0;
}

Any insight will help. Much appreciated.

Ok for this i would recomend making a key making function something like the following

void makeKey(char *keyBuff, int keyLen)
{

   unsigned char randomKeyByte;//var to hold random key
   if(strlen(keyBuff)<keyLen)//if key buffer is to small we have a problem
   {
     cout<<"Key buffer is to small"<<endl;
     cout<<"Requested key of size "<<keyLen;
     cout<<" into buffer of size "<<strlen(keyBuff)<<endl;
     return;
   }

   //if the previous if statment passes (buffer is suitable for key) then proceed

   for(int x = 0; x<keyLen; x++) //loops through the number of bytes required for the key
   {
      randomKeyByte = rand();
      randomKeyByte%=256; //scale key byte betweeon 0-255

      keyBuff[x] = randomKeyByte;//assign random byte to key buffer
   }

}

this function checks the length of the buffer you have provided (bear in mind you will require the headder's for random <cstdlib> time <time.h> and strlen <cstring> ) and generates a key of the length required in the character array passed to this fucntion.

now to use this code would look something like below

//at some point in the code around init you will need to seed random number

srand( (unsigned int) time(NULL) );//seed random number generator 

//later when you need a key you may have something like this

chLen = strlen(pass);
//using key now as char *key;
key = new char[chLen+1];//create array big enough for key the same length as pass + NULL char

makeKey(key,chLen);

//now key holds your random key

//proceed with exor'ing bytes as before

Hope this helps you if you have any questions or problems please post here or pm me

thanks :)

im still working on it give me a moment of time and I will have my code posted before the end of the night.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.