Changeset a301379c
- Timestamp:
- 2005-12-13T22:43:59Z (19 years ago)
- Branches:
- master
- Children:
- b73ac9c
- Parents:
- ab49fdc
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
crypting.c
rab49fdc ra301379c 29 29 the programs will be built. */ 30 30 31 #ifndef CRYPTING_MAIN32 #define BITLBEE_CORE33 #include "bitlbee.h"34 #include "irc.h"35 31 #include "md5.h" 36 32 #include "crypting.h" … … 38 34 #include <stdio.h> 39 35 #include <stdlib.h> 40 41 #else42 43 typedef struct irc44 {45 char *password;46 } irc_t;47 48 #include "md5.h"49 #include "crypting.h"50 #include <string.h>51 #include <stdio.h>52 #include <stdlib.h>53 54 #endif55 36 56 37 /*\ … … 83 64 84 65 85 char *hashpass (irc_t *irc) { 66 char *hashpass (const char *password) 67 { 86 68 md5_state_t md5state; 87 69 md5_byte_t digest[16]; … … 90 72 char *rv; 91 73 92 if ( irc->password == NULL) return (NULL);74 if (password == NULL) return (NULL); 93 75 94 rv = (char *)g_malloc (33); 95 memset (rv, 0, 33); 76 rv = g_new0 (char, 33); 96 77 97 78 md5_init (&md5state); 98 md5_append (&md5state, ( unsigned char *)irc->password, strlen (irc->password));79 md5_append (&md5state, (const unsigned char *)password, strlen (password)); 99 80 md5_finish (&md5state, digest); 100 81 … … 108 89 } 109 90 110 char *obfucrypt (irc_t *irc, char *line) { 91 char *obfucrypt (char *line, const char *password) 92 { 111 93 int i, j; 112 94 char *rv; 113 95 114 if ( irc->password == NULL) return (NULL);96 if (password == NULL) return (NULL); 115 97 116 rv = (char *)g_malloc (strlen (line) + 1); 117 memset (rv, '\0', strlen (line) + 1); 98 rv = g_new0 (char, strlen (line) + 1); 118 99 119 100 i = j = 0; … … 121 102 /* Encrypt/obfuscate the line, using the password */ 122 103 if (*(signed char*)line < 0) *line = - (*line); 123 if (((signed char*)irc->password)[i] < 0) irc->password[i] = - irc->password[i];124 104 125 rv[j] = *line + irc->password[i]; /* Overflow intended */105 rv[j] = *line + password[i]; /* Overflow intended */ 126 106 127 107 line++; 128 if (! irc->password[++i]) i = 0;108 if (!password[++i]) i = 0; 129 109 j++; 130 110 } … … 133 113 } 134 114 135 char *deobfucrypt (irc_t *irc, char *line) { 115 char *deobfucrypt (char *line, const char *password) 116 { 136 117 int i, j; 137 118 char *rv; 138 119 139 if ( irc->password == NULL) return (NULL);120 if (password == NULL) return (NULL); 140 121 141 rv = (char *)g_malloc (strlen (line) + 1); 142 memset (rv, '\0', strlen (line) + 1); 122 rv = g_new0 (char, strlen (line) + 1); 143 123 144 124 i = j = 0; 145 125 while (*line) { 146 126 /* Decrypt/deobfuscate the line, using the pass */ 147 rv[j] = *line - irc->password[i]; /* Overflow intended */127 rv[j] = *line - password[i]; /* Overflow intended */ 148 128 149 129 line++; 150 if (! irc->password[++i]) i = 0;130 if (!password[++i]) i = 0; 151 131 j++; 152 132 } … … 162 142 int main( int argc, char *argv[] ) 163 143 { 164 irc_t *irc = g_malloc( sizeof( irc_t ) );165 144 char *hash, *action, line[256]; 166 char* (*func)( irc_t *,char * );145 char* (*func)( char *, const char * ); 167 146 168 147 if( argc < 2 ) … … 174 153 } 175 154 176 memset( irc, 0, sizeof( irc_t ) ); 177 irc->password = g_strdup( argv[1] ); 178 179 hash = hashpass( irc ); 155 hash = hashpass( argv[1] ); 180 156 action = argv[0] + strlen( argv[0] ) - strlen( "encode" ); 181 157 … … 209 185 fgetc( stdin ); 210 186 211 out = func( irc, line);187 out = func( line, argv[1] ); 212 188 printf( "%s\n", out ); 213 189 g_free( out ); -
crypting.h
rab49fdc ra301379c 25 25 26 26 int checkpass (const char *password, const char *md5sum); 27 char *hashpass ( irc_t *irc);28 char *obfucrypt ( irc_t *irc, char *line);29 char *deobfucrypt ( irc_t *irc, char *line);27 char *hashpass (const char *password); 28 char *obfucrypt (char *line, const char *password); 29 char *deobfucrypt (char *line, const char *password);
Note: See TracChangeset
for help on using the changeset viewer.