00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "encryption.h"
00019
00020
00021 static const char scramble1 [50] = "C6FDC7A1EDFBB6FEE3DBF5BEBAEFDDF7ABC6FDC7A1EDFBB6";
00022 static const char hexstr [17] = "0123456789ABCDEF";
00023
00024 int Encryption::hexbyt( const char c )
00025 {
00026 if( c >= '0' && c <= '9' )
00027 return c - '0';
00028 else
00029 return c - 'A' + 10;
00030 }
00031
00032 const QString Encryption::crypt( const KUrl& url )
00033 {
00034 char result[50];
00035 char scramble2[50];
00036 QString hexresult;
00037
00038 memset (result, 0, 50);
00039 memset (scramble2, 0, 50);
00040 int pos = url.pass().length () + 1;
00041 int free = 50 - pos;
00042
00043 if( url.user().length() <= free )
00044 {
00045 strcpy( &scramble2[pos], url.user().toLatin1() );
00046 pos += url.user().length();
00047 free -= url.user().length();
00048 }
00049 else
00050 {
00051 memcpy( &scramble2[pos], url.user().toLatin1(), free );
00052 free = 0;
00053 }
00054
00055 if( url.host().length() <= free )
00056 {
00057 strcpy( &scramble2[pos], url.host().toLatin1() );
00058 pos += url.host().length();
00059 free -= url.host().length();
00060 }
00061 else
00062 {
00063 memcpy( &scramble2[pos], url.host().toLatin1(), free );
00064 free = 0;
00065 }
00066
00067 memcpy( result, url.pass().toLatin1(), url.pass().length() );
00068 for (int i = 0; i <= 31; i++)
00069 {
00070 result[i] = (char)( result[i] ^ ( scramble1[i] ^ scramble2[i] ) );
00071 hexresult += hexstr[ result[i] / 16 ];
00072 hexresult += hexstr[ result[i] % 16 ];
00073 }
00074
00075 return hexresult;
00076 }
00077
00078 const QString Encryption::decrypt( const QString& pass )
00079 {
00080 char result[50];
00081
00082 memset( result, 0, 50 );
00083 int i;
00084 for( i = 0; i <= 31; i++ )
00085 {
00086 result[i] = (char)hexbyt( pass[ i * 2 ].toLatin1() ) * 16 + hexbyt( pass[ i * 2 + 1 ].toLatin1() );
00087 result[i] = (char)( result[i] ^ scramble1[i] );
00088 }
00089
00090 return result;
00091 }