Here is an XOR filter if you wish to use xor in a transformation chain.

const size_t kPadSize(YOURPADSIZEHERE);

class XORFilter : public CryptoPP::Bufferless<CryptoPP::Filter> {
 public:
  XORFilter(CryptoPP::BufferedTransformation *attachment,
            byte *pad,
            const size_t &pad_size = kPadSize)
      : pad_(pad), count_(0), kPadSize_(pad_size) {
    CryptoPP::Filter::Detach(attachment);
  }
  size_t Put2(const byte* in_string,
              size_t length,
              int message_end,
              bool blocking) {
    if (length == 0) {
      return AttachedTransformation()->Put2(in_string, length, message_end,
                                            blocking);
    }
    boost::scoped_array<byte> buffer(new byte[length]);

    size_t i(0);
    for (; i != length; ++i) {
      buffer[i] = in_string[i] ^ pad_[count_ % kPadSize_];
      ++count_;
    }

    return AttachedTransformation()->Put2(buffer.get(), length, message_end,
                                          blocking);
  }
  bool IsolatedFlush(bool, bool) { return false; }

 private:
  XORFilter &operator = (const XORFilter&);
  XORFilter(const XORFilter&);
  byte *pad_;
  size_t count_;
  const size_t kPadSize_;
};

Best Regards
David Irvine


<http://maidsafe.net>maidsafe.net Limited is a limited liability company
incorporated in Scotland with number SC297540. VAT Registered 889 0608 77.
Registered Office: 72 Templehill, Troon, KA10 6BE.
Telephone Scotland: +44 1292 750020.




On Sun, Sep 16, 2012 at 11:30 AM, degski <[email protected]> wrote:

> Hi Shahram,
>
> This might not be what you mean, but the xor function is C/C++ is like:
>
> int x = 6544654, y = 9684296;
>
> x ^= y;
>
>
> x now contains the xored value of x with y. For your strings, just do it
> byte by byte.
>
> Cheers,
>
>
> degski
>
>
> On 16 September 2012 12:21, Shahram <[email protected]> wrote:
>
>> "Dear Jay Jay
>>
>> Thanks for your quick reply. But What I want is close to what you
>> suggest. That's part of an SIP protocol with a "SHA256" hash function. I
>> couldn't find XOR function in Crypto++ with the specification that I've
>> mentioned before. Is it possible for you to help me in this way? Thanks
>> again.
>>
>> On Sunday, September 16, 2012 12:00:02 AM UTC-7, Jay Jay wrote:
>>>
>>> I take it you want to encrypt a username with a password. Why roll your
>>> own? DefaultEncryptorWithMAC will do this for you:
>>>
>>> Use like:
>>>
>>> template < typename F >
>>> const string EncryptString ( const string& instr, const string&
>>> passPhrase ) {
>>>
>>>     string outstr;
>>>
>>>     try {
>>>
>>>         DefaultEncryptorWithMAC Encryptor ( passPhrase.c_str ( ), new F
>>> ( new StringSink ( outstr ), false ) );
>>>         Encryptor.Put ( ( byte* ) instr.c_str ( ), instr.size ( ) );
>>>         Encryptor.MessageEnd ( );
>>>     }
>>>
>>>     catch ( std::exception& e ) {
>>>
>>>         cout << e.what ( ) << endl;
>>>
>>>         exit ( 0 );
>>>     }
>>>
>>>     return outstr;
>>> }
>>>
>>> Where F is either HexEncoder or Base64Encoder.
>>>
>>> So call
>>>
>>> const string encrypted_username (  EncryptString<Base64Encoder> (
>>> username, password ) );
>>>
>>> Cheers,
>>>
>>>
>>> degski
>>>
>>> On 16 September 2012 09:21, Shahram <[email protected]> wrote:
>>>
>>>> Dear All
>>>>
>>>> Would you please help me to know how can I have a function with the
>>>> following specification:
>>>>
>>>> Inputs: string  username, password;
>>>> output string   F(username, password) = username XOR hash (password)
>>>>  where hash= SHA256 or anything else.
>>>>
>>>> And I need also to have and write the output down in hex . Thanks in
>>>> advance.
>>>>
>>>> Regards
>>>> Shahram
>>>>
>>>> --
>>>> You received this message because you are subscribed to the "Crypto++
>>>> Users" Google Group.
>>>> To unsubscribe, send an email to cryptopp-user...@**googlegroups.com.
>>>> More information about Crypto++ and this group is available at
>>>> http://www.cryptopp.com.
>>>
>>>
>>>
>>>
>>> --
>>> "When I see a bird that walks like a duck and swims like a duck and
>>> quacks like a duck, I call that bird a duck."
>>>
>>> - *James Whitcomb Riley*
>>>
>>>  --
>> You received this message because you are subscribed to the "Crypto++
>> Users" Google Group.
>> To unsubscribe, send an email to
>> [email protected].
>> More information about Crypto++ and this group is available at
>> http://www.cryptopp.com.
>
>
>
>
> --
> "When I see a bird that walks like a duck and swims like a duck and quacks
> like a duck, I call that bird a duck."
>
> - *James Whitcomb Riley*
>
>  --
> You received this message because you are subscribed to the "Crypto++
> Users" Google Group.
> To unsubscribe, send an email to
> [email protected].
> More information about Crypto++ and this group is available at
> http://www.cryptopp.com.
>

-- 
You received this message because you are subscribed to the "Crypto++ Users" 
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at 
http://www.cryptopp.com.

Reply via email to