00001 /***************************************************************************** 00002 * Copyright (C) 2011 by Benjamin Hadorn (b_hadorn@bluewin.ch) 00003 ***************************************************************************** 00004 * Project : Zeus Base Library 00005 * Module : SimpleDES 00006 * Package : Zeus.ZeusBase.Security 00007 * Author : Benjamin Hadorn 00008 * Date : 27.12.2011 00009 * System : Zeus-Framework 00010 ***************************************************************************** 00011 * Licence: * 00012 * This library is free software; you can redistribute it and/or modify * 00013 * it under the terms of the GNU Lesser General Public License as * 00014 * published by the Free Software Foundation; either version * 00015 * 2.1 of the License, or (at your option) any later version. * 00016 * * 00017 * This library is distributed in the hope that it will be useful, * 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00020 * GNU Lesser General Public License for more details. * 00021 * * 00022 * You should have received a copy of the GNU Lesser General Public * 00023 * License along with this library; if not, write to the Free Software * 00024 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA * 00025 *****************************************************************************/ 00026 00027 /***************************************************************************** 00028 * Changes: 00029 * 27.12.2011 bha: created zeus 2.0 00030 *****************************************************************************/ 00031 00032 #ifndef SimpleDESH 00033 #define SimpleDESH 00034 00035 #include <zeusbase/Security/AbstractCrypter.h> 00036 00037 BEGIN_NAMESPACE_Zeus 00038 00039 /***************************************************************************/ 00044 /***************************************************************************/ 00045 class TSimpleDES : public TAbstractCrypter 00046 { 00047 public: 00048 TSimpleDES(); 00049 Int encode(Int iInput); 00050 Int decode(Int iInput); 00051 00052 //abstract methods 00053 virtual Retval encode(const IByteArray& rInput, IByteArray& rOutput); 00054 virtual Retval decode(const IByteArray& rInput, IByteArray& rOutput); 00055 virtual Int getBlockSizeForDecoding() const; 00056 virtual Int getBlockSizeForEncoding() const; 00057 virtual void setKey(Uint64 uldKey); 00058 virtual void setKey(const IByteArray& rKey); 00059 00060 protected: 00061 virtual ~TSimpleDES(); 00062 00063 private: 00065 Int m_iKey1; 00067 Int m_iKey2; 00068 00069 //static methods 00070 static Int F_1(Int r, Int k); 00071 static Int encrypt(Int iValue, Int iKey1, Int iKey2); 00072 }; 00073 00074 /***************************************************************************/ 00077 /***************************************************************************/ 00078 inline Int TSimpleDES::getBlockSizeForDecoding() const 00079 { 00080 return 1; 00081 } 00082 00083 /***************************************************************************/ 00086 /***************************************************************************/ 00087 inline Int TSimpleDES::getBlockSizeForEncoding() const 00088 { 00089 return 1; 00090 } 00091 00092 /***************************************************************************/ 00095 /***************************************************************************/ 00096 inline Int TSimpleDES::encode(Int iInput) 00097 { 00098 return TSimpleDES::encrypt(iInput, m_iKey1, m_iKey2); 00099 } 00100 00101 /***************************************************************************/ 00104 /***************************************************************************/ 00105 inline Int TSimpleDES::decode(Int iInput) 00106 { 00107 return TSimpleDES::encrypt(iInput, m_iKey2, m_iKey1); 00108 } 00109 00110 END_NAMESPACE_Zeus 00111 #endif 00112