syncmlfw/ds/settings/src/NSmlDSCrypt.cpp
changeset 0 b497e44ab2fc
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     1 /*
       
     2 * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  DS-settings 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "nsmldssettings.h"
       
    22 
       
    23 
       
    24 //=============================================
       
    25 //
       
    26 //		CNSmlDSCrypt
       
    27 //
       
    28 //=============================================
       
    29 
       
    30 //=============================================
       
    31 //		CNSmlDSCrypt::CNSmlDSCrypt()
       
    32 //		Constructor.
       
    33 //=============================================
       
    34 EXPORT_C CNSmlDSCrypt::CNSmlDSCrypt()
       
    35 	{
       
    36 	}
       
    37 
       
    38 //=============================================
       
    39 //		CNSmlDSCrypt::~CNSmlDSCrypt()
       
    40 //		Destructor.
       
    41 //=============================================
       
    42 EXPORT_C CNSmlDSCrypt::~CNSmlDSCrypt()
       
    43 	{
       
    44 	delete iOutput;
       
    45 	}
       
    46 
       
    47 //=============================================
       
    48 //		CNSmlDSCrypt::EncryptedL()
       
    49 //		Destructor.
       
    50 //=============================================
       
    51 EXPORT_C TDesC& CNSmlDSCrypt::EncryptedL( const TDesC& aInput )
       
    52 	{
       
    53 	delete iOutput;
       
    54 	iOutput = 0;
       
    55 
       
    56 	iOutput = aInput.AllocL();
       
    57 
       
    58 	TPtr ptrOutput( iOutput->Des() );
       
    59 	
       
    60 	// Keys to be used in encryption / decryption.
       
    61 	TUint16 key1 = 0xa576;
       
    62 	TUint16 key2 = 0x02f9;
       
    63 
       
    64 	for (TInt i = 0; i < iOutput->Length(); i++ )
       
    65 		{
       
    66 		key1 %= key2;
       
    67 		key1 <<= 7;
       
    68 		key1 ^= key2;
       
    69 		key2 %= key1;
       
    70 		key2 <<= 3;
       
    71 		key2 ^= key1;
       
    72 		ptrOutput[i] ^= key1;
       
    73 		}
       
    74 
       
    75 	return *iOutput;
       
    76 	}
       
    77 
       
    78 //=============================================
       
    79 //		CNSmlDSCrypt::DecryptedL()
       
    80 //		Destructor.
       
    81 //=============================================
       
    82 EXPORT_C TDesC& CNSmlDSCrypt::DecryptedL( const TDesC& aInput )
       
    83 	{
       
    84 	return EncryptedL( aInput );
       
    85 	}
       
    86 
       
    87 //  End of File